Brute forcing possible sequences

This commit is contained in:
Matúš Púll 2024-11-07 18:41:57 +01:00
parent d405a2db95
commit adcc4961a6

View file

@ -11,14 +11,22 @@ public:
// Guessing // Guessing
vector<int> guess() { vector<int> guess() {
// TODO auto possibilities = known.list_all_possibilities();
return {}; auto chosen = vector<int>(0);
return brute_force(&possibilities, &chosen, 0);
} }
// Utility functions // Utility functions
// Prints what the solver deduced // Prints what the solver deduced
void print() { void print() {
known.print(); known.print();
auto possibilities = known.list_all_possibilities();
auto chosen = vector<int>(0);
auto v = brute_force(&possibilities, &chosen, 0);
cout << "Bruteforce chosen ";
for(int col : v)
cout << col << " ";
cout << std::endl;
} }
// Clean guess and response from info we know // Clean guess and response from info we know
Historic_guess clean(Historic_guess hist) { Historic_guess clean(Historic_guess hist) {
@ -60,6 +68,12 @@ public:
return response[0] == hist.response[0] && return response[0] == hist.response[0] &&
response[1] == hist.response[1]; response[1] == hist.response[1];
} }
bool all_are_consistent(vector<int> supposed_sequence) {
for(auto hist : history)
if(!is_consistent(supposed_sequence, hist))
return false;
return true;
}
// Specific reactions // Specific reactions
void if_not_here_then_nowhere(vector<int> guess) { void if_not_here_then_nowhere(vector<int> guess) {
@ -99,6 +113,23 @@ public:
} }
} }
// Try all remaining sequences
vector<int> brute_force(vector<vector<int>> *possibilities, vector<int> *chosen, int index) {
vector<int> r = vector<int>(N, -1);
if(index == N) {
if(all_are_consistent(*chosen))
r = *chosen;
return r;
}
for(int col : (*possibilities)[index]) {
chosen->push_back(col);
r = brute_force(possibilities, chosen, index+1);
if(r[0] != -1)
return r;
chosen->pop_back();
}
return r;
}
bool extract_info(Historic_guess hist) { bool extract_info(Historic_guess hist) {
bool something_to_learn = true; bool something_to_learn = true;