diff --git a/main.cpp b/main.cpp index 43e2173..cb95a75 100644 --- a/main.cpp +++ b/main.cpp @@ -86,7 +86,7 @@ int main(void) { // Terminal clearing cout << std::endl; - // Print game statistics + // Print game history cout << "History\n"; for(auto guess : history) cout << format_guess_history(sequence, guess) << std::endl; diff --git a/solver.hpp b/solver.hpp index 08a3710..28cd697 100644 --- a/solver.hpp +++ b/solver.hpp @@ -5,17 +5,64 @@ using std::vector; struct Game { int N, M; - Game(int p_N, int p_M) : N(p_N), M(p_M) {} + // Table of NxM saying which position can hold which color + vector> possible; + // Searched sequence + vector sequence; + Game(int p_N, int p_M) : N(p_N), M(p_M) { + possible = vector>(N, vector(M, 1)); + sequence = vector(N, -1); + } + + // Learning functions + void cannot_be(int n, int col) { + possible[n][col] = false; + } + void must_be(int must_n, int col) { + for(int n = 0; n < N; n++) + if(n != must_n) + possible[n][col] = 0; + } + void empty_color(int col) { + for(int n = 0; n < N; n++) + possible[n][col] = 0; + } }; class Solver { Game known; + vector> history = {}; public: Solver(int p_N, int p_M) : known({p_N, p_M}) {} vector guess() { + // TODO return {}; } + void learn_back(vector guess) { + // TODO + } void learn(vector guess, vector response) { - + // Reduce color positions + if(response[0] == 0 && response[1] == 0) { + for(int col : guess) + known.empty_color(col); + } + else if(response[1] == 0) {; + for(int n = 0; n < known.N; n++) + known.cannot_be(n, guess[n]); + } + else if(response[0] == 0) { + for(int n = 0; n < known.N; n++) + known.must_be(n, guess[n]); + } + else { + // TODO nenula / nenula + } + + // Learn from previous guesses + for(vector past_guess : history) + learn_back(past_guess); + + history.push_back(guess); } };