Brute forcing possible sequences
This commit is contained in:
parent
d405a2db95
commit
adcc4961a6
1 changed files with 33 additions and 2 deletions
35
solver.hpp
35
solver.hpp
|
@ -11,14 +11,22 @@ public:
|
|||
|
||||
// Guessing
|
||||
vector<int> guess() {
|
||||
// TODO
|
||||
return {};
|
||||
auto possibilities = known.list_all_possibilities();
|
||||
auto chosen = vector<int>(0);
|
||||
return brute_force(&possibilities, &chosen, 0);
|
||||
}
|
||||
|
||||
// Utility functions
|
||||
// Prints what the solver deduced
|
||||
void print() {
|
||||
known.print();
|
||||
auto possibilities = known.list_all_possibilities();
|
||||
auto chosen = vector<int>(0);
|
||||
auto v = brute_force(&possibilities, &chosen, 0);
|
||||
cout << "Bruteforce chosen ";
|
||||
for(int col : v)
|
||||
cout << col << " ";
|
||||
cout << std::endl;
|
||||
}
|
||||
// Clean guess and response from info we know
|
||||
Historic_guess clean(Historic_guess hist) {
|
||||
|
@ -60,6 +68,12 @@ public:
|
|||
return response[0] == hist.response[0] &&
|
||||
response[1] == hist.response[1];
|
||||
}
|
||||
bool all_are_consistent(vector<int> supposed_sequence) {
|
||||
for(auto hist : history)
|
||||
if(!is_consistent(supposed_sequence, hist))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Specific reactions
|
||||
void if_not_here_then_nowhere(vector<int> guess) {
|
||||
|
@ -99,6 +113,23 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
// Try all remaining sequences
|
||||
vector<int> brute_force(vector<vector<int>> *possibilities, vector<int> *chosen, int index) {
|
||||
vector<int> r = vector<int>(N, -1);
|
||||
if(index == N) {
|
||||
if(all_are_consistent(*chosen))
|
||||
r = *chosen;
|
||||
return r;
|
||||
}
|
||||
for(int col : (*possibilities)[index]) {
|
||||
chosen->push_back(col);
|
||||
r = brute_force(possibilities, chosen, index+1);
|
||||
if(r[0] != -1)
|
||||
return r;
|
||||
chosen->pop_back();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
bool extract_info(Historic_guess hist) {
|
||||
bool something_to_learn = true;
|
||||
|
||||
|
|
Loading…
Reference in a new issue