-
Notifications
You must be signed in to change notification settings - Fork 0
/
solver_cpu_reference.hpp
61 lines (48 loc) · 1.93 KB
/
solver_cpu_reference.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Michael M. Magruder (https://github.com/mikemag)
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
#pragma once
#include <cassert>
#include <vector>
#include "solver.hpp"
// CPU Reference Implementation
//
// This is a simple impl to serve as a reference for all the others. It's not optimized for speed. Hopefully it's clear.
// More details w/ the impl.
template <typename SolverConfig_>
class SolverReferenceImpl : public Solver {
using CodewordT = typename SolverConfig_::CodewordT;
using RegionIDT = RegionID<unsigned __int128, SolverConfig_::CodewordT::WINNING_SCORE.result>;
public:
using SolverConfig = SolverConfig_;
constexpr static const char* name = "CPU Reference Impl";
SolverReferenceImpl() : counters(counterDescs.descs.size()) {}
std::chrono::nanoseconds playAllGames(uint32_t packedInitialGuess) override;
void dump() override;
vector<uint32_t> getGuessesForGame(uint32_t packedCodeword) override;
void printStats() override {
for (auto& c : counterDescs.descs) {
cout << c.desc << ": " << commaString(counters[c.index]) << endl;
}
}
void recordStats(StatsRecorder& sr) override {
sr.add("Use Sym Opt", false);
for (auto& c : counterDescs.descs) {
sr.add(c.name, counters[c.index]);
}
}
constexpr static CounterDescriptors<1> counterDescs{{
{"Scores", "Codeword comparisons"},
}};
private:
vector<vector<CodewordT>> nextMovesList;
vector<RegionIDT> regionIDs;
vector<unsigned long long int> counters;
CodewordT nextGuess(const vector<CodewordT>& possibleSolutions, const vector<CodewordT>& usedCodewords);
uint32_t getPackedCodewordForRegion(int level, uint32_t regionIndex) const override {
return nextMovesList[level][regionIndex].packedCodeword();
}
uint8_t getStandardScore(uint8_t score) override { return score; }
};
#include "solver_cpu_reference.inl"