Game-state should be asked properly and not interact with its contents

This commit is contained in:
Matúš Púll 2024-11-04 18:43:43 +01:00
parent 1d416deed8
commit 245324d9c3

View file

@ -5,10 +5,11 @@
using std::vector; using std::vector;
using std::cout; using std::cout;
struct Game { class Game {
int N, M;
// Table of NxM saying which position can hold which color // Table of NxM saying which position can hold which color
vector<vector<bool>> possible; vector<vector<bool>> possible;
public:
int N, M;
Game(int p_N, int p_M) : N(p_N), M(p_M) { Game(int p_N, int p_M) : N(p_N), M(p_M) {
possible = vector<vector<bool>>(N, vector<bool>(M, 1)); possible = vector<vector<bool>>(N, vector<bool>(M, 1));
} }
@ -17,9 +18,9 @@ struct Game {
void cannot_be(int n, int col) { void cannot_be(int n, int col) {
possible[n][col] = false; possible[n][col] = false;
} }
void must_be(int must_n, int col) { void must_be(int n, int must_col) {
for(int n = 0; n < N; n++) for(int col = 0; col < M; col++)
if(n != must_n) if(col != must_col)
possible[n][col] = 0; possible[n][col] = 0;
} }
void empty_color(int col) { void empty_color(int col) {
@ -28,6 +29,9 @@ struct Game {
} }
// Checking // Checking
bool can(int n, int col) {
return possible[n][col];
}
int final_color(int n) { int final_color(int n) {
int final_col, count = 0; int final_col, count = 0;
for(int col = 0; col < M; col++) for(int col = 0; col < M; col++)