WIP: try fix naive solver

This commit is contained in:
Christoph J. Scherr 2024-08-07 14:20:53 +02:00
parent 38d484fb5e
commit 38ae033798
2 changed files with 28 additions and 3 deletions

View File

@ -67,6 +67,7 @@ impl<'wl, WL: WordList> Solver<'wl, WL> for NaiveSolver<'wl, WL> {
.entry(p.0) .entry(p.0)
.or_insert(CharInfo::new(game.length())); .or_insert(CharInfo::new(game.length()));
cinfo.tried_but_failed(idx); cinfo.tried_but_failed(idx);
abs_freq.entry(p.0).or_default();
} }
} }
trace!("absolute frequencies: {abs_freq:?}"); trace!("absolute frequencies: {abs_freq:?}");
@ -91,6 +92,9 @@ impl<'wl, WL: WordList> Solver<'wl, WL> for NaiveSolver<'wl, WL> {
.filter(|solution_candidate| { .filter(|solution_candidate| {
if !game.responses().is_empty() if !game.responses().is_empty()
&& !state.has_all_known_contained(&solution_candidate.0) && !state.has_all_known_contained(&solution_candidate.0)
// we need these sometimes,
// because we can't just input gibberish
//&& !state.has_wrong_chars(&solution_candidate.0)
{ {
trace!("known cont:{:#?}", state.get_all_known_contained()); trace!("known cont:{:#?}", state.get_all_known_contained());
return false; return false;

View File

@ -34,10 +34,17 @@ impl SolverState {
&mut self.char_map &mut self.char_map
} }
pub(crate) fn get_all_known_bad(&self) -> Vec<(&char, &CharInfo)> {
self.char_map
.iter()
.filter(|(_key, value)| value.not_in_solution())
.collect()
}
pub(crate) fn get_all_known_contained(&self) -> Vec<(&char, &CharInfo)> { pub(crate) fn get_all_known_contained(&self) -> Vec<(&char, &CharInfo)> {
self.char_map self.char_map
.iter() .iter()
.filter(|(_key, value)| value.part_of_solution()) .filter(|(_key, value)| value.known_part_of_solution())
.collect() .collect()
} }
@ -71,6 +78,15 @@ impl SolverState {
} }
} }
} }
pub(crate) fn has_wrong_chars(&self, guess: &Word) -> bool {
for needed_char in self.get_all_known_bad() {
if guess.contains(*needed_char.0) {
return false;
}
}
true
}
} }
impl CharInfo { impl CharInfo {
@ -100,7 +116,12 @@ impl CharInfo {
} }
#[must_use] #[must_use]
pub fn part_of_solution(&self) -> bool { pub fn not_in_solution(&self) -> bool {
self.occurences_amount.end == 0
}
#[must_use]
pub fn known_part_of_solution(&self) -> bool {
self.occurences_amount.start > 0 && self.occurences_amount.end > 0 self.occurences_amount.start > 0 && self.occurences_amount.end > 0
} }
@ -152,7 +173,7 @@ impl CharInfo {
impl Debug for CharInfo { impl Debug for CharInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.part_of_solution() { if !self.not_in_solution() {
f.debug_struct("CharInfo") f.debug_struct("CharInfo")
.field("correct_idxs", &self.confirmed_indexes) .field("correct_idxs", &self.confirmed_indexes)
.field("amnt_occ", &self.occurences_amount) .field("amnt_occ", &self.occurences_amount)