Compare commits

...

3 commits

Author SHA1 Message Date
530f51c9cc Merge branch 'devel' into feat/naive
Some checks failed
cargo devel CI / cargo CI (push) Failing after 1m54s
2024-08-07 14:29:18 +02:00
c140264a0c chore: bump to first alpha version
Some checks failed
cargo devel CI / cargo CI (push) Failing after 1m23s
2024-08-07 14:27:52 +02:00
38ae033798 WIP: try fix naive solver 2024-08-07 14:20:53 +02:00
3 changed files with 33 additions and 5 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "wordle-analyzer"
version = "0.1.0"
version = "0.1.0-alpha.0"
edition = "2021"
publish = false
authors = ["Christoph J. Scherr <software@cscherr.de>"]
@ -60,4 +60,7 @@ path = "src/bin/bench/cli.rs"
required-features = ["solve", "cli", "bench", "builtin"]
[dev-dependencies]
test-log = { version = "0.2.16", default-features = false, features = ["color", "trace"] }
test-log = { version = "0.2.16", default-features = false, features = [
"color",
"trace",
] }

View file

@ -67,6 +67,7 @@ impl<'wl, WL: WordList> Solver<'wl, WL> for NaiveSolver<'wl, WL> {
.entry(p.0)
.or_insert(CharInfo::new(game.length()));
cinfo.tried_but_failed(idx);
abs_freq.entry(p.0).or_default();
}
}
trace!("absolute frequencies: {abs_freq:?}");
@ -91,6 +92,9 @@ impl<'wl, WL: WordList> Solver<'wl, WL> for NaiveSolver<'wl, WL> {
.filter(|solution_candidate| {
if !game.responses().is_empty()
&& !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());
return false;

View file

@ -34,10 +34,17 @@ impl SolverState {
&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)> {
self.char_map
.iter()
.filter(|(_key, value)| value.part_of_solution())
.filter(|(_key, value)| value.known_part_of_solution())
.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 {
@ -100,7 +116,12 @@ impl CharInfo {
}
#[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
}
@ -152,7 +173,7 @@ impl CharInfo {
impl Debug for CharInfo {
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")
.field("correct_idxs", &self.confirmed_indexes)
.field("amnt_occ", &self.occurences_amount)