Start of learning from responses
This commit is contained in:
parent
6c2f10b6c0
commit
929e722622
2 changed files with 50 additions and 3 deletions
2
main.cpp
2
main.cpp
|
@ -86,7 +86,7 @@ int main(void) {
|
|||
// Terminal clearing
|
||||
cout << std::endl;
|
||||
|
||||
// Print game statistics
|
||||
// Print game history
|
||||
cout << "History\n";
|
||||
for(auto guess : history)
|
||||
cout << format_guess_history(sequence, guess) << std::endl;
|
||||
|
|
49
solver.hpp
49
solver.hpp
|
@ -5,17 +5,64 @@ using std::vector;
|
|||
|
||||
struct Game {
|
||||
int N, M;
|
||||
Game(int p_N, int p_M) : N(p_N), M(p_M) {}
|
||||
// Table of NxM saying which position can hold which color
|
||||
vector<vector<bool>> possible;
|
||||
// Searched sequence
|
||||
vector<int> sequence;
|
||||
Game(int p_N, int p_M) : N(p_N), M(p_M) {
|
||||
possible = vector<vector<bool>>(N, vector<bool>(M, 1));
|
||||
sequence = vector<int>(N, -1);
|
||||
}
|
||||
|
||||
// Learning functions
|
||||
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)
|
||||
possible[n][col] = 0;
|
||||
}
|
||||
void empty_color(int col) {
|
||||
for(int n = 0; n < N; n++)
|
||||
possible[n][col] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class Solver {
|
||||
Game known;
|
||||
vector<vector<int>> history = {};
|
||||
public:
|
||||
Solver(int p_N, int p_M) : known({p_N, p_M}) {}
|
||||
vector<int> guess() {
|
||||
// TODO
|
||||
return {};
|
||||
}
|
||||
void learn_back(vector<int> guess) {
|
||||
// TODO
|
||||
}
|
||||
void learn(vector<int> guess, vector<int> response) {
|
||||
// Reduce color positions
|
||||
if(response[0] == 0 && response[1] == 0) {
|
||||
for(int col : guess)
|
||||
known.empty_color(col);
|
||||
}
|
||||
else if(response[1] == 0) {;
|
||||
for(int n = 0; n < known.N; n++)
|
||||
known.cannot_be(n, guess[n]);
|
||||
}
|
||||
else if(response[0] == 0) {
|
||||
for(int n = 0; n < known.N; n++)
|
||||
known.must_be(n, guess[n]);
|
||||
}
|
||||
else {
|
||||
// TODO nenula / nenula
|
||||
}
|
||||
|
||||
// Learn from previous guesses
|
||||
for(vector<int> past_guess : history)
|
||||
learn_back(past_guess);
|
||||
|
||||
history.push_back(guess);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue