From 245324d9c3797e50a9a81ac8801adae795fc539f Mon Sep 17 00:00:00 2001 From: Matuush Date: Mon, 4 Nov 2024 18:43:43 +0100 Subject: [PATCH] Game-state should be asked properly and not interact with its contents --- gamestate.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gamestate.hpp b/gamestate.hpp index a8cf3d7..842075a 100644 --- a/gamestate.hpp +++ b/gamestate.hpp @@ -5,10 +5,11 @@ using std::vector; using std::cout; -struct Game { - int N, M; +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)); } @@ -17,9 +18,9 @@ struct Game { 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) + 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) { @@ -28,6 +29,9 @@ struct Game { } // 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++)