diff --git a/solver.hpp b/solver.hpp index 96d68dc..3db14f1 100644 --- a/solver.hpp +++ b/solver.hpp @@ -104,32 +104,48 @@ public: known.empty_color(col); } - void learn_back(Historic_guess hist) { + bool learn_back(Historic_guess hist) { + bool something_to_learn = true; // TODO + return something_to_learn; } void learn(vector guess, vector response) { + bool something_to_learn; // None of these colors are there - if(response[0] == 0 && response[1] == 0) + if(response[0] == 0 && response[1] == 0) { empty(guess); + something_to_learn = false; + } // None at the right spot - else if(response[1] == 0) + else if(response[1] == 0) { not_here(guess); + something_to_learn = false; + } // At least only on the right spot - else if(response[0] == 0) + else if(response[0] == 0) { if_not_here_then_nowhere(guess); + something_to_learn = true; + } // TODO nonzero / nonzero - else - {} + else { + something_to_learn = true; + } // Learn from previous guesses - for(auto hist : history) - learn_back(hist); + for(int i = 0; i < history.size(); i++) + if(!learn_back(history[i])) { + // If there is nothing left to learn from the guess + history.erase(history.begin()+i); + i--; + } + // Write to history - history.push_back({guess, response}); + if(something_to_learn) + history.push_back({guess, response}); } void print() { known.print();