If response only contains right positions, the colors still can be somewhere else
This commit is contained in:
parent
61125a7e64
commit
24a4d45640
1 changed files with 22 additions and 5 deletions
27
solver.hpp
27
solver.hpp
|
@ -53,21 +53,35 @@ public:
|
||||||
// TODO
|
// TODO
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
void learn_back(vector<int> guess) {
|
void learn_back(vector<int> historic_guess) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
void learn(vector<int> guess, vector<int> response) {
|
void learn(vector<int> guess, vector<int> response) {
|
||||||
// Reduce color positions
|
// 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)
|
for(int col : guess)
|
||||||
known.empty_color(col);
|
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++)
|
for(int n = 0; n < known.N; n++)
|
||||||
known.cannot_be(n, guess[n]);
|
known.cannot_be(n, guess[n]);
|
||||||
}
|
}
|
||||||
else if(response[0] == 0) {
|
else if(response[0] == 0) { // At least only on the right spot
|
||||||
// TODO if somewhere, then at least here
|
// 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 {
|
else {
|
||||||
// TODO nonzero / nonzero
|
// TODO nonzero / nonzero
|
||||||
|
@ -77,6 +91,9 @@ public:
|
||||||
for(vector<int> past_guess : history)
|
for(vector<int> past_guess : history)
|
||||||
learn_back(past_guess);
|
learn_back(past_guess);
|
||||||
|
|
||||||
|
// Write to history
|
||||||
|
for(int r : response)
|
||||||
|
guess.push_back(r);
|
||||||
history.push_back(guess);
|
history.push_back(guess);
|
||||||
}
|
}
|
||||||
void print() {
|
void print() {
|
||||||
|
|
Loading…
Reference in a new issue