If the numbers in the response add to N, colors not featured in the guess are not present in the guessed sequence
This commit is contained in:
parent
fed923923b
commit
9bc8a326c1
1 changed files with 21 additions and 6 deletions
27
solver.hpp
27
solver.hpp
|
@ -16,7 +16,7 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear what we already know
|
// Utility functions
|
||||||
Historic_guess clean(Historic_guess hist) {
|
Historic_guess clean(Historic_guess hist) {
|
||||||
// The correct colors we know
|
// The correct colors we know
|
||||||
for(int n = 0; n < known.N; n++) {
|
for(int n = 0; n < known.N; n++) {
|
||||||
|
@ -42,14 +42,17 @@ public:
|
||||||
|
|
||||||
return hist;
|
return hist;
|
||||||
}
|
}
|
||||||
|
vector<vector<int>> get_positions_of_colors(vector<int> guess) {
|
||||||
// Specific reactions
|
|
||||||
void if_not_here_then_nowhere(vector<int> guess) {
|
|
||||||
// Get all positions of these colors
|
|
||||||
auto positions_of_colors = vector<vector<int>>(known.M, vector<int>(0));
|
auto positions_of_colors = vector<vector<int>>(known.M, vector<int>(0));
|
||||||
for(int n = 0; n < known.N; n++)
|
for(int n = 0; n < known.N; n++)
|
||||||
if(guess[n] > -1)
|
if(guess[n] > -1)
|
||||||
positions_of_colors[guess[n]].push_back(n);
|
positions_of_colors[guess[n]].push_back(n);
|
||||||
|
return positions_of_colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Specific reactions
|
||||||
|
void if_not_here_then_nowhere(vector<int> guess) {
|
||||||
|
auto positions_of_colors = get_positions_of_colors(guess);
|
||||||
|
|
||||||
// If color isn't here, it can't be in the sequence
|
// If color isn't here, it can't be in the sequence
|
||||||
for(int col = 0; col < known.M; col++) {
|
for(int col = 0; col < known.M; col++) {
|
||||||
|
@ -63,7 +66,7 @@ public:
|
||||||
}
|
}
|
||||||
void here(vector<int> guess) {
|
void here(vector<int> guess) {
|
||||||
for(int n = 0; n < known.N; n++)
|
for(int n = 0; n < known.N; n++)
|
||||||
if(guess[n] > -1)
|
if(guess[n] > -1 && known.possible[n][guess[n]])
|
||||||
for(int col = 0; col < known.M; col++) {
|
for(int col = 0; col < known.M; col++) {
|
||||||
if(col != guess[n])
|
if(col != guess[n])
|
||||||
known.possible[n][col] = 0;
|
known.possible[n][col] = 0;
|
||||||
|
@ -79,6 +82,14 @@ public:
|
||||||
if(col > -1)
|
if(col > -1)
|
||||||
known.empty_color(col);
|
known.empty_color(col);
|
||||||
}
|
}
|
||||||
|
void all_are_here(vector<int> guess) {
|
||||||
|
auto positions_of_colors = get_positions_of_colors(guess);
|
||||||
|
|
||||||
|
for(int col = 0; col < known.M; col++) {
|
||||||
|
if(!positions_of_colors[col].size())
|
||||||
|
known.empty_color(col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool extract_info(Historic_guess hist) {
|
bool extract_info(Historic_guess hist) {
|
||||||
bool something_to_learn = true;
|
bool something_to_learn = true;
|
||||||
|
@ -122,6 +133,10 @@ public:
|
||||||
here(guess);
|
here(guess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All guessed colors are in the sequence
|
||||||
|
if(response[0] + response[1] == known.N)
|
||||||
|
all_are_here(guess);
|
||||||
|
|
||||||
return something_to_learn;
|
return something_to_learn;
|
||||||
}
|
}
|
||||||
void learn(vector<int> p_guess, vector<int> p_response) {
|
void learn(vector<int> p_guess, vector<int> p_response) {
|
||||||
|
|
Loading…
Reference in a new issue