From 6a75cd777b2015e53260791483ef3cb5fe8d8a82 Mon Sep 17 00:00:00 2001 From: ashastral Date: Wed, 2 Mar 2022 19:19:32 -0800 Subject: [PATCH] be even a little more adversarial --- wordlelike/src/evaluator.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wordlelike/src/evaluator.rs b/wordlelike/src/evaluator.rs index d632aa6..66979e3 100644 --- a/wordlelike/src/evaluator.rs +++ b/wordlelike/src/evaluator.rs @@ -87,7 +87,17 @@ impl AdversarialEvaluator { impl Evaluator for AdversarialEvaluator { fn evaluate(&self, word: Word) -> Matches { let best_secrets = self.best_secrets(word); - return guess(&word, best_secrets.first().unwrap()); + let mut secret_with_most_nowheres: Option> = None; + let mut most_nowheres = None; + for secret in best_secrets { + let matches = guess(&word, &secret); + let nowheres = matches.iter().filter(|&m| m == &LetterMatch::NOWHERE).count(); + if most_nowheres.is_none() || nowheres > most_nowheres.unwrap() { + most_nowheres = Some(nowheres); + secret_with_most_nowheres = Some(secret); + } + } + return guess(&word, &secret_with_most_nowheres.unwrap()); } fn push(&mut self, result: GuessResult) {