generated from PlexSheep/rs-base
fix(game): evaluation was not generated correctly in an edge case #18
cargo devel CI / cargo CI (push) Failing after 1m52s
Details
cargo devel CI / cargo CI (push) Failing after 1m52s
Details
This commit is contained in:
parent
3c44760a2c
commit
d5cf04d89b
|
@ -129,17 +129,18 @@ impl<'wl, WL: WordList> Game<'wl, WL> {
|
||||||
pub(crate) fn evaluate(mut solution: WordData, guess: &Word) -> Evaluation {
|
pub(crate) fn evaluate(mut solution: WordData, guess: &Word) -> Evaluation {
|
||||||
let mut evaluation = Vec::new();
|
let mut evaluation = Vec::new();
|
||||||
let mut status: Status;
|
let mut status: Status;
|
||||||
for (idx, c) in guess.chars().enumerate() {
|
let mut buf = solution.0.clone();
|
||||||
if solution.0.chars().nth(idx) == Some(c) {
|
for ((idx, c_guess), c_sol) in guess.chars().enumerate().zip(solution.0.chars()) {
|
||||||
|
if c_guess == c_sol {
|
||||||
status = Status::Matched;
|
status = Status::Matched;
|
||||||
solution.0.replace_range(idx..idx + 1, "_");
|
buf.replace_range(idx..idx + 1, "_");
|
||||||
} else if solution.0.contains(c) {
|
} else if buf.contains(c_guess) {
|
||||||
status = Status::Exists;
|
status = Status::Exists;
|
||||||
solution.0 = solution.0.replacen(c, "_", 1);
|
buf = buf.replacen(c_guess, "_", 1);
|
||||||
} else {
|
} else {
|
||||||
status = Status::None
|
status = Status::None
|
||||||
}
|
}
|
||||||
evaluation.push((c, status));
|
evaluation.push((c_guess, status));
|
||||||
}
|
}
|
||||||
evaluation.into()
|
evaluation.into()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue