diff --git a/gamestate.cpp b/gamestate.cpp deleted file mode 100644 index fc48847..0000000 --- a/gamestate.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "global.hpp" - -#include -#include -#include - - -class Game { - // Table of NxM saying which position can hold which color - vector> possible; - std::default_random_engine random_engine; -public: - int N, M; - Game(int p_N, int p_M) : N(p_N), M(p_M) { - possible = vector>(N, vector(M, 1)); - - unsigned int seed = std::chrono::system_clock::now().time_since_epoch().count(); - random_engine = std::default_random_engine(seed); - } - - // Learning functions - void cannot_be(int n, int col) { - possible[n][col] = false; - } - void must_be(int n, int must_col) { - for(int col = 0; col < M; col++) - if(col != must_col) - possible[n][col] = 0; - } - void empty_color(int col) { - for(int n = 0; n < N; n++) - possible[n][col] = 0; - } - - // Checking - bool can(int n, int col) { - return possible[n][col]; - } - int final_color(int n) { - int final_col, count = 0; - for(int col = 0; col < M; col++) - if(possible[n][col]) { - final_col = col; - count++; - } - - if(count == 1) - return final_col; - return -1; - } - - // Get known information - void print() { - cout << " "; - for(int col = 0; col < M; col++) - cout << col; - cout << std::endl; - for(int i = 0; i < N; i++) { - cout << i; - for(auto col : possible[i]) - cout << col; - cout << std::endl;; - } - } - // Get all possible colors for all positions - vector> list_all_possibilities() { - auto r = vector>(N, vector(0)); - for(int col = 0; col < M; col++) - for(int n = 0; n < N; n++) - if(possible[n][col]) - r[n].push_back(col); - - for(int n = 0; n < N; n++) - std::shuffle(r[n].begin(), r[n].end(), random_engine); - return r; - } -}; - -// For remembering guesses with their responses -struct Historic_guess { - vector guess, response; - Historic_guess(vector p_guess, vector p_response) { - guess = p_guess; - response = p_response; - } -}; diff --git a/solver.cpp b/solver.cpp index e967857..ddb90d2 100644 --- a/solver.cpp +++ b/solver.cpp @@ -169,6 +169,8 @@ void Solver::print() { Historic_guess Solver::clean(Historic_guess hist) { // The in-place colors we know for(int n = 0; n < N; n++) { + if(hist.guess[n] == -1) + continue; if(known.final_color(n) == hist.guess[n]) { hist.guess[n] = -1; hist.response[1] -= 1; @@ -180,11 +182,12 @@ Historic_guess Solver::clean(Historic_guess hist) { if(hist.guess[n] == -1) continue; for(int i = 0; i < N; i++) { - if(i == n) + if(i == n || hist.guess[i] == -1) continue; if(known.final_color(i) == hist.guess[n]) { hist.guess[n] = -1; hist.response[0] -= 1; + break; } } } diff --git a/solver.hpp b/solver.hpp index 7fd4b12..51c98d0 100644 --- a/solver.hpp +++ b/solver.hpp @@ -31,7 +31,6 @@ public: void not_here(vector guess); void empty(vector guess); void all_are_here(vector guess); - }; // For remembering guesses with their responses @@ -40,6 +39,7 @@ struct Historic_guess { Historic_guess(vector p_guess, vector p_response); }; +// Solving the game class Solver { Game known; int N, M;