Game-state should be asked properly and not interact with its contents
This commit is contained in:
parent
1d416deed8
commit
245324d9c3
1 changed files with 9 additions and 5 deletions
|
@ -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<vector<bool>> possible;
|
||||
public:
|
||||
int N, M;
|
||||
Game(int p_N, int p_M) : N(p_N), M(p_M) {
|
||||
possible = vector<vector<bool>>(N, vector<bool>(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++)
|
||||
|
|
Loading…
Reference in a new issue