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
22
solver.hpp
22
solver.hpp
|
@ -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,6 +146,12 @@ public:
|
|||
// Learn something new
|
||||
bool something_to_learn = extract_info({p_guess, p_response});
|
||||
|
||||
// Write to history
|
||||
if(something_to_learn)
|
||||
history.push_back({p_guess, p_response});
|
||||
|
||||
// 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])) {
|
||||
|
@ -150,12 +159,5 @@ public:
|
|||
history.erase(history.begin()+i);
|
||||
i--;
|
||||
}
|
||||
|
||||
// Write to history
|
||||
if(something_to_learn)
|
||||
history.push_back({p_guess, p_response});
|
||||
}
|
||||
void print() {
|
||||
known.print();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue