logik/gamestate.hpp

70 lines
1.3 KiB
C++

#pragma once
#include <vector>
#include <iostream>
using std::vector;
using std::cout;
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));
}
// 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;
}
// Print 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;;
}
}
};
// For remembering guesses with their responses
struct Historic_guess {
vector<int> guess, response;
Historic_guess(vector<int> p_guess, vector<int> p_response) {
guess = p_guess;
response = p_response;
}
};