diff --git a/solver.hpp b/solver.hpp index 94303bf..8e3c894 100644 --- a/solver.hpp +++ b/solver.hpp @@ -61,6 +61,14 @@ public: known.empty_color(col); } } + void here(vector guess) { + for(int n = 0; n < known.N; n++) + if(guess[n] > -1) + for(int col = 0; col < known.M; col++) { + if(col != guess[n]) + known.possible[n][col] = 0; + } + } void not_here(vector guess) { for(int n = 0; n < known.N; n++) if(guess[n] > -1) @@ -80,6 +88,12 @@ public: vector guess = cleaned.guess; vector response = cleaned.response; + // Get number of colors, that can be on their positions + int possible_count = 0; + for(int n = 0; n < known.N; n++) + if(known.possible[n][guess[n]]) + possible_count++; + // None of these colors are there if(response[0] == 0 && response[1] == 0) { empty(guess); @@ -91,11 +105,22 @@ public: not_here(guess); // At least only on the right spot - else if(response[0] == 0) - if_not_here_then_nowhere(guess); + else if(response[0] == 0) { + // Only colors that can be on these positions are left + if(response[1] == possible_count) { + here(guess); + something_to_learn = false; + } + else + if_not_here_then_nowhere(guess); + } // Nonzero / nonzero - else {} + else { + // Only colors that can be on these positions are left + if(response[1] == possible_count) + here(guess); + } return something_to_learn; }