#pragma once #include #include using std::vector; using std::cout; class Game { // Table of NxM saying which position can hold which color vector> possible; public: int N, M; Game(int p_N, int p_M) : N(p_N), M(p_M) { possible = vector>(N, vector(M, 1)); } // 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[col].push_back(n); 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; } };