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::word::{ManyWordDatas, Word};
|
||||||
use crate::wlist::WordList;
|
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 {
|
fn guess_for(&self, game: &crate::game::Game<WL>) -> Word {
|
||||||
// HACK: hardcoded length
|
// 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();
|
let response = game.last_response();
|
||||||
if response.is_some() {
|
if response.is_some() {
|
||||||
for (idx, p) in response.unwrap().evaluation().iter().enumerate() {
|
for (idx, p) in response.unwrap().evaluation().iter().enumerate() {
|
||||||
if p.1 == Status::Matched {
|
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
|
let matches: ManyWordDatas = game
|
||||||
.wordlist()
|
.wordlist()
|
||||||
.get_words_matching(buf)
|
.get_words_matching(pattern)
|
||||||
.expect("the solution does not exist in the wordlist")
|
.expect("the solution does not exist in the wordlist")
|
||||||
.iter()
|
.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())
|
.map(|v| v.to_owned())
|
||||||
.collect();
|
.collect();
|
||||||
matches[0].0.to_owned()
|
matches[0].0.to_owned()
|
||||||
|
|
|
@ -82,7 +82,6 @@ pub trait WordList: Clone + std::fmt::Debug + Default {
|
||||||
let keys = pattern.captures_iter(&hay);
|
let keys = pattern.captures_iter(&hay);
|
||||||
let mut buf = ManyWordDatas::new();
|
let mut buf = ManyWordDatas::new();
|
||||||
for k in keys {
|
for k in keys {
|
||||||
debug!("match: {k:?}");
|
|
||||||
let w: WordData = self.wordmap().get(&k[0]).unwrap();
|
let w: WordData = self.wordmap().get(&k[0]).unwrap();
|
||||||
buf.push(w)
|
buf.push(w)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue