generated from PlexSheep/rs-base
naive solver use other chars
cargo devel CI / cargo CI (push) Successful in 42s
Details
cargo devel CI / cargo CI (push) Successful in 42s
Details
This commit is contained in:
parent
41676e9a23
commit
b33038cc50
|
@ -1,4 +1,4 @@
|
|||
use libpt::log::info;
|
||||
use libpt::log::{debug, info};
|
||||
|
||||
use crate::wlist::word::{ManyWordDatas, Word};
|
||||
use crate::wlist::WordList;
|
||||
|
@ -17,21 +17,32 @@ impl<'wl, WL: WordList> Solver<'wl, WL> for NaiveSolver<'wl, WL> {
|
|||
}
|
||||
fn guess_for(&self, game: &crate::game::Game<WL>) -> Word {
|
||||
// HACK: hardcoded length
|
||||
let mut buf: Word = Word::from(".....");
|
||||
let mut pattern: String = String::from(".....");
|
||||
let mut other_chars: Vec<char> = Vec::new();
|
||||
let response = game.last_response();
|
||||
if response.is_some() {
|
||||
for (idx, p) in response.unwrap().evaluation().iter().enumerate() {
|
||||
if p.1 == Status::Matched {
|
||||
buf.replace_range(idx..idx + 1, &p.0.to_string());
|
||||
pattern.replace_range(idx..idx + 1, &p.0.to_string());
|
||||
} else if p.1 == Status::Exists {
|
||||
other_chars.push(p.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
debug!("other chars: {:?}", other_chars);
|
||||
let matches: ManyWordDatas = game
|
||||
.wordlist()
|
||||
.get_words_matching(buf)
|
||||
.get_words_matching(pattern)
|
||||
.expect("the solution does not exist in the wordlist")
|
||||
.iter()
|
||||
.filter(|m| !game.made_guesses().contains(&&m.0))
|
||||
.filter(|p| !game.made_guesses().contains(&&p.0))
|
||||
.filter(|p| {
|
||||
let mut fits = true;
|
||||
for c in other_chars.iter() {
|
||||
fits &= p.0.contains(*c);
|
||||
}
|
||||
fits
|
||||
})
|
||||
.map(|v| v.to_owned())
|
||||
.collect();
|
||||
matches[0].0.to_owned()
|
||||
|
|
|
@ -82,7 +82,6 @@ pub trait WordList: Clone + std::fmt::Debug + Default {
|
|||
let keys = pattern.captures_iter(&hay);
|
||||
let mut buf = ManyWordDatas::new();
|
||||
for k in keys {
|
||||
debug!("match: {k:?}");
|
||||
let w: WordData = self.wordmap().get(&k[0]).unwrap();
|
||||
buf.push(w)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue