diff --git a/src/game/mod.rs b/src/game/mod.rs index f8ebcaa..9e96fcd 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -1,5 +1,5 @@ use crate::error::*; -use crate::wlist::word::{Word, WordData}; +use crate::wlist::word::{ManyWordDatas, ManyWordsRef, Word, WordData}; use crate::wlist::WordList; use libpt::log::debug; @@ -139,6 +139,10 @@ impl<'wl, WL: WordList> Game<'wl, WL> { pub fn wordlist(&self) -> &WL { self.wordlist } + + pub(crate) fn made_guesses(&self) -> ManyWordsRef { + self.responses.iter().map(|r| r.guess()).collect() + } } /// Build and Configure a [`Game`] diff --git a/src/game/response.rs b/src/game/response.rs index 6966b87..2830e22 100644 --- a/src/game/response.rs +++ b/src/game/response.rs @@ -67,7 +67,7 @@ impl GuessResponse { &self.evaluation } - pub fn guess(&self) -> &str { + pub fn guess(&self) -> &Word { &self.guess } } diff --git a/src/solve/naive/mod.rs b/src/solve/naive/mod.rs index bc2f9e3..13503cc 100644 --- a/src/solve/naive/mod.rs +++ b/src/solve/naive/mod.rs @@ -1,6 +1,6 @@ use libpt::log::info; -use crate::wlist::word::Word; +use crate::wlist::word::{ManyWordDatas, Word}; use crate::wlist::WordList; use super::{AnyBuiltinSolver, Solver, Status}; @@ -26,11 +26,15 @@ impl<'wl, WL: WordList> Solver<'wl, WL> for NaiveSolver<'wl, WL> { } } } - game.wordlist() + let matches: ManyWordDatas = game + .wordlist() .get_words_matching(buf) - .expect("the solution does not exist in the wordlist")[0] - .0 - .clone() + .expect("the solution does not exist in the wordlist") + .iter() + .filter(|m| !game.made_guesses().contains(&&m.0)) + .map(|v| v.to_owned()) + .collect(); + matches[0].0.to_owned() } } diff --git a/src/wlist/word.rs b/src/wlist/word.rs index 91128d4..abb848e 100644 --- a/src/wlist/word.rs +++ b/src/wlist/word.rs @@ -11,7 +11,7 @@ pub type Frequency = f64; // PERF: Hash for String is probably a bottleneck pub type Word = String; pub type WordData = (Word, Frequency); -pub type ManyWords<'a> = Vec<&'a Word>; +pub type ManyWordsRef<'a> = Vec<&'a Word>; pub type ManyWordDatas = Vec<(Word, Frequency)>; #[derive(Clone)]