If response only contains right positions, the colors still can be somewhere else

This commit is contained in:
Matúš Púll 2024-11-03 11:24:17 +01:00
parent 61125a7e64
commit 24a4d45640

View file

@ -53,21 +53,35 @@ public:
// TODO
return {};
}
void learn_back(vector<int> guess) {
void learn_back(vector<int> historic_guess) {
// TODO
}
void learn(vector<int> guess, vector<int> response) {
// Reduce color positions
if(response[0] == 0 && response[1] == 0) {
if(response[0] == 0 && response[1] == 0) { // None of these colors are there
for(int col : guess)
known.empty_color(col);
}
else if(response[1] == 0) {;
else if(response[1] == 0) { // None at the right spot
// Not here
for(int n = 0; n < known.N; n++)
known.cannot_be(n, guess[n]);
}
else if(response[0] == 0) {
// TODO if somewhere, then at least here
else if(response[0] == 0) { // At least only on the right spot
// Get all positions of these colors
auto positions_of_colors = vector<vector<int>>(known.M, vector<int>(0));
for(int n = 0; n < known.N; n++)
positions_of_colors[guess[n]].push_back(n);
// If color can't be anywhere here, it can't be in the sequence
for(int col = 0; col < known.M; col++) {
int possible_count = 0;
for(int n : positions_of_colors[col])
if(known.possible[n][col])
possible_count++;
if(possible_count == 0 && positions_of_colors[col].size() > 0)
known.empty_color(col);
}
}
else {
// TODO nonzero / nonzero
@ -77,6 +91,9 @@ public:
for(vector<int> past_guess : history)
learn_back(past_guess);
// Write to history
for(int r : response)
guess.push_back(r);
history.push_back(guess);
}
void print() {