diff --git a/solver.hpp b/solver.hpp index c4eceee..4bbfc52 100644 --- a/solver.hpp +++ b/solver.hpp @@ -11,14 +11,22 @@ public: // Guessing vector guess() { - // TODO - return {}; + auto possibilities = known.list_all_possibilities(); + auto chosen = vector(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(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 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 guess) { @@ -99,6 +113,23 @@ public: } } + // Try all remaining sequences + vector brute_force(vector> *possibilities, vector *chosen, int index) { + vector r = vector(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;