diff --git a/solver.cpp b/solver.cpp index c4a184c..56e709d 100644 --- a/solver.cpp +++ b/solver.cpp @@ -15,7 +15,7 @@ bool Solver::all_are_consistent(vector supposed_sequence) { // Try all remaining sequences vector Solver::brute_force(vector> *possibilities, vector *chosen, int index) { - vector r = vector(N, -1); + vector r(N, -1); if(index == N) { if(all_are_consistent(*chosen)) r = *chosen; @@ -38,6 +38,7 @@ int Solver::get_weight(vector guess) { // Get weight for(auto hist : history) { // TODO get worst-case weight + // Possibly get how many sequences it eliminates } return 1; @@ -47,11 +48,13 @@ Weighed_guess Solver::minimax(vector> *possibilities, vector *c // If complete guess, get weight and return if(index == N) return {get_weight(*chosen), *chosen}; - // Get max-weighted child + + // Get max-weighted children Weighed_guess r = {-2, {}}; for(int col : (*possibilities)[index]) { chosen->push_back(col); - Weighed_guess r2 = minimax(possibilities, chosen, index+1); + auto r2 = minimax(possibilities, chosen, index+1); + if(r2.weight > r.weight || r.weight == -2) r = r2; chosen->pop_back(); @@ -61,9 +64,10 @@ Weighed_guess Solver::minimax(vector> *possibilities, vector *c // Guessing vector Solver::guess() { - // TODO make it smart auto possibilities = known.list_all_possibilities(); auto chosen = vector(0); + + // TODO make it smart return brute_force(&possibilities, &chosen, 0); } @@ -121,14 +125,6 @@ vector Solver::extract_info(Historic_guess hist) { auto guess = cleaned.guess; auto response = cleaned.response; - bool something = false; - for(int n = 0; n < N; n++) - if(guess[n] > -1) - something = true; - - if(!something) - return {false, false}; - // Get number of colors, that can be on their positions int possible_count = 0; for(int n = 0; n < N; n++) @@ -195,6 +191,7 @@ void Solver::learn(vector guess, Response response) { // Learn from previous guesses for(int i = 0; i < history.size(); i++) { auto info = extract_info(history[i]); + if(!info[0]) { // If there is nothing left to learn from the guess history.erase(history.begin()+i);