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:
Matúš Púll 2024-11-04 16:29:26 +01:00
parent fed923923b
commit 9bc8a326c1

View file

@ -16,7 +16,7 @@ public:
return {};
}
// Clear what we already know
// Utility functions
Historic_guess clean(Historic_guess hist) {
// The correct colors we know
for(int n = 0; n < known.N; n++) {
@ -42,14 +42,17 @@ public:
return hist;
}
// Specific reactions
void if_not_here_then_nowhere(vector<int> guess) {
// Get all positions of these colors
vector<vector<int>> get_positions_of_colors(vector<int> guess) {
auto positions_of_colors = vector<vector<int>>(known.M, vector<int>(0));
for(int n = 0; n < known.N; n++)
if(guess[n] > -1)
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
for(int col = 0; col < known.M; col++) {
@ -63,7 +66,7 @@ public:
}
void here(vector<int> guess) {
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++) {
if(col != guess[n])
known.possible[n][col] = 0;
@ -79,6 +82,14 @@ public:
if(col > -1)
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 something_to_learn = true;
@ -122,6 +133,10 @@ public:
here(guess);
}
// All guessed colors are in the sequence
if(response[0] + response[1] == known.N)
all_are_here(guess);
return something_to_learn;
}
void learn(vector<int> p_guess, vector<int> p_response) {