diff --git a/solver.hpp b/solver.hpp index c1bcf6f..e4cdc20 100644 --- a/solver.hpp +++ b/solver.hpp @@ -3,11 +3,12 @@ class Solver { Game known; + int N, M; vector history = {}; vector sequence; public: - Solver(int p_N, int p_M) : known({p_N, p_M}) { - sequence = vector(p_N, -1); + Solver(int p_N, int p_M) : N(p_N), M(p_M), known({p_N, p_M}) { + sequence = vector(N, -1); } // Guessing @@ -22,7 +23,7 @@ public: } Historic_guess clean(Historic_guess hist) { // The in-place colors we know - for(int n = 0; n < known.N; n++) { + for(int n = 0; n < N; n++) { if(known.final_color(n) == hist.guess[n]) { hist.guess[n] = -1; hist.response[1] -= 1; @@ -30,10 +31,10 @@ public: } // The out-of-place colors we know - for(int n = 0; n < known.N; n++) { + for(int n = 0; n < N; n++) { if(hist.guess[n] == -1) continue; - for(int i = 0; i < known.N; i++) { + for(int i = 0; i < N; i++) { if(i == n) continue; if(known.final_color(i) == hist.guess[n]) { @@ -46,8 +47,8 @@ public: return hist; } vector> get_positions_of_colors(vector guess) { - auto positions_of_colors = vector>(known.M, vector(0)); - for(int n = 0; n < known.N; n++) + auto positions_of_colors = vector>(M, vector(0)); + for(int n = 0; n < N; n++) if(guess[n] > -1) positions_of_colors[guess[n]].push_back(n); return positions_of_colors; @@ -58,7 +59,7 @@ public: 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++) { + for(int col = 0; col < M; col++) { int possible_count = 0; for(int n : positions_of_colors[col]) if(known.can(n, col)) @@ -68,12 +69,12 @@ public: } } void here(vector guess) { - for(int n = 0; n < known.N; n++) + for(int n = 0; n < N; n++) if(guess[n] > -1 && known.can(n, guess[n])) known.must_be(n, guess[n]); } void not_here(vector guess) { - for(int n = 0; n < known.N; n++) + for(int n = 0; n < N; n++) if(guess[n] > -1) known.cannot_be(n, guess[n]); } @@ -85,7 +86,7 @@ public: void all_are_here(vector guess) { auto positions_of_colors = get_positions_of_colors(guess); - for(int col = 0; col < known.M; col++) { + for(int col = 0; col < M; col++) { if(!positions_of_colors[col].size()) known.empty_color(col); } @@ -101,7 +102,7 @@ public: // Get number of colors, that can be on their positions int possible_count = 0; - for(int n = 0; n < known.N; n++) + for(int n = 0; n < N; n++) if(guess[n] > -1 && known.can(n, guess[n])) possible_count++; @@ -134,7 +135,7 @@ public: } // All guessed colors are in the sequence - if(response[0] + response[1] == known.N) + if(response[0] + response[1] == N) all_are_here(guess); return something_to_learn;