Minor readability changes + repeating learning from history
This commit is contained in:
parent
9bc8a326c1
commit
53195b5c8b
1 changed files with 16 additions and 14 deletions
30
solver.hpp
30
solver.hpp
|
@ -17,6 +17,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
|
void print() {
|
||||||
|
known.print();
|
||||||
|
}
|
||||||
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++) {
|
||||||
|
@ -96,13 +99,13 @@ public:
|
||||||
|
|
||||||
// A bit of cleaning
|
// A bit of cleaning
|
||||||
auto cleaned = clean(hist);
|
auto cleaned = clean(hist);
|
||||||
vector<int> guess = cleaned.guess;
|
auto guess = cleaned.guess;
|
||||||
vector<int> response = cleaned.response;
|
auto response = cleaned.response;
|
||||||
|
|
||||||
// Get number of colors, that can be on their positions
|
// Get number of colors, that can be on their positions
|
||||||
int possible_count = 0;
|
int possible_count = 0;
|
||||||
for(int n = 0; n < known.N; n++)
|
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++;
|
possible_count++;
|
||||||
|
|
||||||
// None of these colors are there
|
// None of these colors are there
|
||||||
|
@ -143,19 +146,18 @@ public:
|
||||||
// Learn something new
|
// Learn something new
|
||||||
bool something_to_learn = extract_info({p_guess, p_response});
|
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
|
// Write to history
|
||||||
if(something_to_learn)
|
if(something_to_learn)
|
||||||
history.push_back({p_guess, p_response});
|
history.push_back({p_guess, p_response});
|
||||||
}
|
|
||||||
void print() {
|
// Repeat multiple times, if new information turned out
|
||||||
known.print();
|
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--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue