From 9bc8a326c1a885925bef557ae2fc8f46e3476195 Mon Sep 17 00:00:00 2001 From: Matuush Date: Mon, 4 Nov 2024 16:29:26 +0100 Subject: [PATCH] If the numbers in the response add to N, colors not featured in the guess are not present in the guessed sequence --- solver.hpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/solver.hpp b/solver.hpp index 8e3c894..c15ca94 100644 --- a/solver.hpp +++ b/solver.hpp @@ -16,7 +16,7 @@ public: return {}; } - // Clear what we already know + // Utility functions Historic_guess clean(Historic_guess hist) { // The correct colors we know for(int n = 0; n < known.N; n++) { @@ -42,14 +42,17 @@ public: return hist; } - - // Specific reactions - void if_not_here_then_nowhere(vector guess) { - // Get all positions of these colors + vector> get_positions_of_colors(vector guess) { auto positions_of_colors = vector>(known.M, vector(0)); for(int n = 0; n < known.N; n++) if(guess[n] > -1) positions_of_colors[guess[n]].push_back(n); + return positions_of_colors; + } + + // Specific reactions + void if_not_here_then_nowhere(vector guess) { + auto positions_of_colors = get_positions_of_colors(guess); // If color isn't here, it can't be in the sequence for(int col = 0; col < known.M; col++) { @@ -63,7 +66,7 @@ public: } void here(vector guess) { for(int n = 0; n < known.N; n++) - if(guess[n] > -1) + if(guess[n] > -1 && known.possible[n][guess[n]]) for(int col = 0; col < known.M; col++) { if(col != guess[n]) known.possible[n][col] = 0; @@ -79,6 +82,14 @@ public: if(col > -1) known.empty_color(col); } + void all_are_here(vector guess) { + auto positions_of_colors = get_positions_of_colors(guess); + + for(int col = 0; col < known.M; col++) { + if(!positions_of_colors[col].size()) + known.empty_color(col); + } + } bool extract_info(Historic_guess hist) { bool something_to_learn = true; @@ -122,6 +133,10 @@ public: here(guess); } + // All guessed colors are in the sequence + if(response[0] + response[1] == known.N) + all_are_here(guess); + return something_to_learn; } void learn(vector p_guess, vector p_response) {