generated from PlexSheep/rs-base
Compare commits
3 commits
38d484fb5e
...
530f51c9cc
Author | SHA1 | Date | |
---|---|---|---|
530f51c9cc | |||
c140264a0c | |||
38ae033798 |
3 changed files with 33 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "wordle-analyzer"
|
name = "wordle-analyzer"
|
||||||
version = "0.1.0"
|
version = "0.1.0-alpha.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
||||||
|
@ -60,4 +60,7 @@ path = "src/bin/bench/cli.rs"
|
||||||
required-features = ["solve", "cli", "bench", "builtin"]
|
required-features = ["solve", "cli", "bench", "builtin"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[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",
|
||||||
|
] }
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue