Minor readability changes + repeating learning from history

This commit is contained in:
Matúš Púll 2024-11-04 18:26:17 +01:00
parent 9bc8a326c1
commit 53195b5c8b

View file

@ -17,6 +17,9 @@ public:
}
// Utility functions
void print() {
known.print();
}
Historic_guess clean(Historic_guess hist) {
// The correct colors we know
for(int n = 0; n < known.N; n++) {
@ -96,13 +99,13 @@ public:
// A bit of cleaning
auto cleaned = clean(hist);
vector<int> guess = cleaned.guess;
vector<int> response = cleaned.response;
auto guess = cleaned.guess;
auto 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]])
if(guess[n] > -1 && known.possible[n][guess[n]])
possible_count++;
// None of these colors are there
@ -143,19 +146,18 @@ public:
// Learn something new
bool something_to_learn = extract_info({p_guess, p_response});
// Learn from previous guesses
for(int i = 0; i < history.size(); i++)
if(!extract_info(history[i])) {
// If there is nothing left to learn from the guess
history.erase(history.begin()+i);
i--;
}
// Write to history
if(something_to_learn)
history.push_back({p_guess, p_response});
}
void print() {
known.print();
// Repeat multiple times, if new information turned out
for(auto _ : history)
// Learn from previous guesses
for(int i = 0; i < history.size(); i++)
if(!extract_info(history[i])) {
// If there is nothing left to learn from the guess
history.erase(history.begin()+i);
i--;
}
}
};