naive filters matches
cargo devel CI / cargo CI (push) Successful in 42s Details

we can actually win some games in 6 steps with this
This commit is contained in:
Christoph J. Scherr 2024-03-22 22:10:10 +01:00
parent 2c8b9d903c
commit 41676e9a23
Signed by: PlexSheep
GPG Key ID: 7CDD0B14851A08EF
4 changed files with 16 additions and 8 deletions

View File

@ -1,5 +1,5 @@
use crate::error::*; use crate::error::*;
use crate::wlist::word::{Word, WordData}; use crate::wlist::word::{ManyWordDatas, ManyWordsRef, Word, WordData};
use crate::wlist::WordList; use crate::wlist::WordList;
use libpt::log::debug; use libpt::log::debug;
@ -139,6 +139,10 @@ impl<'wl, WL: WordList> Game<'wl, WL> {
pub fn wordlist(&self) -> &WL { pub fn wordlist(&self) -> &WL {
self.wordlist self.wordlist
} }
pub(crate) fn made_guesses(&self) -> ManyWordsRef {
self.responses.iter().map(|r| r.guess()).collect()
}
} }
/// Build and Configure a [`Game`] /// Build and Configure a [`Game`]

View File

@ -67,7 +67,7 @@ impl GuessResponse {
&self.evaluation &self.evaluation
} }
pub fn guess(&self) -> &str { pub fn guess(&self) -> &Word {
&self.guess &self.guess
} }
} }

View File

@ -1,6 +1,6 @@
use libpt::log::info; use libpt::log::info;
use crate::wlist::word::Word; use crate::wlist::word::{ManyWordDatas, Word};
use crate::wlist::WordList; use crate::wlist::WordList;
use super::{AnyBuiltinSolver, Solver, Status}; 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) .get_words_matching(buf)
.expect("the solution does not exist in the wordlist")[0] .expect("the solution does not exist in the wordlist")
.0 .iter()
.clone() .filter(|m| !game.made_guesses().contains(&&m.0))
.map(|v| v.to_owned())
.collect();
matches[0].0.to_owned()
} }
} }

View File

@ -11,7 +11,7 @@ pub type Frequency = f64;
// PERF: Hash for String is probably a bottleneck // PERF: Hash for String is probably a bottleneck
pub type Word = String; pub type Word = String;
pub type WordData = (Word, Frequency); 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)>; pub type ManyWordDatas = Vec<(Word, Frequency)>;
#[derive(Clone)] #[derive(Clone)]