match fix false negative in game
cargo devel CI / cargo CI (push) Successful in 42s Details

This commit is contained in:
Christoph J. Scherr 2024-03-22 23:21:08 +01:00
parent d101d7ddf9
commit da9a7cd036
Signed by: PlexSheep
GPG Key ID: 7CDD0B14851A08EF
2 changed files with 3 additions and 1 deletions

View File

@ -94,7 +94,7 @@ impl<'wl, WL: WordList> Game<'wl, WL> {
for (idx, c) in guess.chars().enumerate() {
if compare_solution.chars().nth(idx) == Some(c) {
status = Status::Matched;
compare_solution = compare_solution.replace(c, "_");
compare_solution.replace_range(idx..idx+1, "_");
} else if compare_solution.contains(c) {
status = Status::Exists;
compare_solution = compare_solution.replacen(c, "_", 1);

View File

@ -35,7 +35,9 @@ impl<'wl, WL: WordList> Solver<'wl, WL> for NaiveSolver<'wl, WL> {
.get_words_matching(pattern)
.expect("the solution does not exist in the wordlist")
.iter()
// only words that have not been guessed yet
.filter(|p| !game.made_guesses().contains(&&p.0))
// only words that contain the letters we found earlier (that were not matched)
.filter(|p| {
// TODO: don't repeat unmatched contained chars on the same position twice #2
let mut fits = true;