On an only-inplace-colors response, we can deduce which colors are in place
This commit is contained in:
parent
f0fda2b9c9
commit
fed923923b
1 changed files with 28 additions and 3 deletions
31
solver.hpp
31
solver.hpp
|
@ -61,6 +61,14 @@ public:
|
|||
known.empty_color(col);
|
||||
}
|
||||
}
|
||||
void here(vector<int> guess) {
|
||||
for(int n = 0; n < known.N; n++)
|
||||
if(guess[n] > -1)
|
||||
for(int col = 0; col < known.M; col++) {
|
||||
if(col != guess[n])
|
||||
known.possible[n][col] = 0;
|
||||
}
|
||||
}
|
||||
void not_here(vector<int> guess) {
|
||||
for(int n = 0; n < known.N; n++)
|
||||
if(guess[n] > -1)
|
||||
|
@ -80,6 +88,12 @@ public:
|
|||
vector<int> guess = cleaned.guess;
|
||||
vector<int> response = cleaned.response;
|
||||
|
||||
// Get number of colors, that can be on their positions
|
||||
int possible_count = 0;
|
||||
for(int n = 0; n < known.N; n++)
|
||||
if(known.possible[n][guess[n]])
|
||||
possible_count++;
|
||||
|
||||
// None of these colors are there
|
||||
if(response[0] == 0 && response[1] == 0) {
|
||||
empty(guess);
|
||||
|
@ -91,11 +105,22 @@ public:
|
|||
not_here(guess);
|
||||
|
||||
// At least only on the right spot
|
||||
else if(response[0] == 0)
|
||||
if_not_here_then_nowhere(guess);
|
||||
else if(response[0] == 0) {
|
||||
// Only colors that can be on these positions are left
|
||||
if(response[1] == possible_count) {
|
||||
here(guess);
|
||||
something_to_learn = false;
|
||||
}
|
||||
else
|
||||
if_not_here_then_nowhere(guess);
|
||||
}
|
||||
|
||||
// Nonzero / nonzero
|
||||
else {}
|
||||
else {
|
||||
// Only colors that can be on these positions are left
|
||||
if(response[1] == possible_count)
|
||||
here(guess);
|
||||
}
|
||||
|
||||
return something_to_learn;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue