From 53195b5c8b3e9b85abd1cc614184fc4f9f249fb3 Mon Sep 17 00:00:00 2001 From: Matuush Date: Mon, 4 Nov 2024 18:26:17 +0100 Subject: [PATCH] Minor readability changes + repeating learning from history --- solver.hpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/solver.hpp b/solver.hpp index c15ca94..bc270d5 100644 --- a/solver.hpp +++ b/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 guess = cleaned.guess; - vector 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--; + } } };