[0/0] response after cleaning and better comments
This commit is contained in:
parent
264881428e
commit
a31c5d05e0
1 changed files with 23 additions and 14 deletions
37
solver.cpp
37
solver.cpp
|
@ -37,7 +37,7 @@ Weighed_guess Solver::minimax(vector<vector<int>> *possibilities, vector<int> *c
|
|||
chosen->push_back(col);
|
||||
auto r2 = minimax(possibilities, chosen, index+1);
|
||||
|
||||
if(r2.weight > r.weight || r.weight == -2)
|
||||
if((r2.weight > r.weight || r.weight == -2) && r2.weight > -1)
|
||||
r = r2;
|
||||
chosen->pop_back();
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ void Solver::print() {
|
|||
|
||||
// Clean guess and response from info we know
|
||||
Historic_guess Solver::clean(Historic_guess hist) {
|
||||
vector<bool> already_used_in_cleaning(N, 0);
|
||||
vector<bool> already_used_in_cleaning(N, false);
|
||||
|
||||
// Clean empty colors
|
||||
for(int n = 0; n < N; n++)
|
||||
|
@ -73,7 +73,7 @@ Historic_guess Solver::clean(Historic_guess hist) {
|
|||
if(known.final_color(n) == hist.guess[n]) {
|
||||
hist.guess[n] = -1;
|
||||
hist.response.correct -= 1;
|
||||
already_used_in_cleaning[n] = 1;
|
||||
already_used_in_cleaning[n] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ Historic_guess Solver::clean(Historic_guess hist) {
|
|||
if(known.final_color(i) == hist.guess[n]) {
|
||||
hist.guess[n] = -1;
|
||||
hist.response.somewhere -= 1;
|
||||
already_used_in_cleaning[i] = 1;
|
||||
already_used_in_cleaning[i] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -112,14 +112,26 @@ vector<bool> Solver::extract_info(Historic_guess hist) {
|
|||
if(guess[n] > -1 && known.can(n, guess[n]))
|
||||
possible_count++;
|
||||
|
||||
// None of these colors are there
|
||||
if(hist.response.somewhere == 0 && hist.response.correct == 0) {
|
||||
known.empty(hist.guess);
|
||||
// The color isn't in the sequence, except for known info [0/0]
|
||||
if(response.somewhere == 0 && response.correct == 0) {
|
||||
|
||||
// Deduce what was cleaned
|
||||
vector<bool> col_was_cleaned(M, false);
|
||||
for(int n = 0; n < N; n++)
|
||||
if(guess[n] != hist.guess[n])
|
||||
col_was_cleaned[hist.guess[n]] = true;
|
||||
|
||||
for(int n = 0; n < N; n++)
|
||||
if(guess[n] > -1 && col_was_cleaned[guess[n]])
|
||||
for(int n2 = 0; n2 < N; n2++)
|
||||
if(known.final_color(n2) != guess[n])
|
||||
known.cannot_be(n2, guess[n]);
|
||||
|
||||
something_to_learn = false;
|
||||
learned_something = true;
|
||||
}
|
||||
|
||||
// None at the right spot
|
||||
// None at the right spot [X/0]
|
||||
else if(response.correct == 0) {
|
||||
if(possible_count > 0) {
|
||||
known.not_here(guess);
|
||||
|
@ -127,7 +139,7 @@ vector<bool> Solver::extract_info(Historic_guess hist) {
|
|||
}
|
||||
}
|
||||
|
||||
// At least only on the right spot
|
||||
// At least only on the right spot [0/X]
|
||||
else if(response.somewhere == 0) {
|
||||
// Only colors that can be on these positions are left
|
||||
if(response.correct == possible_count) {
|
||||
|
@ -135,14 +147,14 @@ vector<bool> Solver::extract_info(Historic_guess hist) {
|
|||
something_to_learn = false;
|
||||
learned_something = true;
|
||||
}
|
||||
else if(hist.response.somewhere == 0){
|
||||
else if(hist.response.somewhere == 0) {
|
||||
if(known.if_not_here_then_nowhere(hist.guess)) {
|
||||
learned_something = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Nonzero / nonzero
|
||||
// The rest [X/X]
|
||||
else {
|
||||
// Only colors that can be on these positions are left
|
||||
if(response.correct == possible_count) {
|
||||
|
@ -158,9 +170,6 @@ void Solver::learn(vector<int> guess, Response response) {
|
|||
if(response.somewhere + response.correct == N)
|
||||
known.all_are_here(guess);
|
||||
|
||||
if(guess[0] == -1)
|
||||
return;
|
||||
|
||||
// Write to history
|
||||
history.push_back({guess, response});
|
||||
|
||||
|
|
Loading…
Reference in a new issue