Fix bug in AI handling of blank letters
This commit is contained in:
parent
4b86c031ed
commit
0887cb29aa
2 changed files with 21 additions and 5 deletions
|
@ -100,6 +100,10 @@ impl Letter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn partial_match(&self, other: &Letter) -> bool {
|
||||||
|
self == other || (self.is_blank == other.is_blank && self.points == other.points)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Serialize)]
|
#[derive(Debug, Copy, Clone, Serialize)]
|
||||||
|
|
|
@ -376,8 +376,6 @@ impl AI {
|
||||||
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
assert!(!letter.is_blank); // we should have handled blanks in evaluate_letter_at_spot
|
|
||||||
|
|
||||||
// let's now assign the letter to this spot
|
// let's now assign the letter to this spot
|
||||||
let mut line_letters = line_letters.clone();
|
let mut line_letters = line_letters.clone();
|
||||||
*line_letters.get_mut(line_index as usize).unwrap() = Some(letter);
|
*line_letters.get_mut(line_index as usize).unwrap() = Some(letter);
|
||||||
|
@ -476,13 +474,15 @@ impl AI {
|
||||||
|
|
||||||
available_letters.iter()
|
available_letters.iter()
|
||||||
.for_each(|in_tray| {
|
.for_each(|in_tray| {
|
||||||
if skipped_one || *in_tray != letter {
|
if skipped_one || !in_tray.partial_match(&letter) {
|
||||||
new_available_letters.push(*in_tray);
|
new_available_letters.push(*in_tray);
|
||||||
} else {
|
} else {
|
||||||
skipped_one = true;
|
skipped_one = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
assert!(skipped_one); // at least one should have been removed
|
||||||
|
|
||||||
self.evaluate_spot_heading_right(
|
self.evaluate_spot_heading_right(
|
||||||
&line_letters,
|
&line_letters,
|
||||||
line_cross_letters,
|
line_cross_letters,
|
||||||
|
@ -771,15 +771,27 @@ mod tests {
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut ai = AI::new(difficulty, &dictionary);
|
let mut ai = AI::new(difficulty, &dictionary);
|
||||||
|
let moves = ai.find_all_moves(&tray, &board);
|
||||||
//let rng = SmallRng::seed_from_u64(123);
|
//let rng = SmallRng::seed_from_u64(123);
|
||||||
|
|
||||||
|
println!("Moves are {:?}", moves);
|
||||||
|
|
||||||
|
assert_eq!(moves.len(), 10);
|
||||||
|
|
||||||
|
tray.letters[4] = Some(
|
||||||
|
Letter {
|
||||||
|
text: ' ',
|
||||||
|
points: 0,
|
||||||
|
ephemeral: false,
|
||||||
|
is_blank: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
let moves = ai.find_all_moves(&tray, &board);
|
let moves = ai.find_all_moves(&tray, &board);
|
||||||
|
|
||||||
println!("Moves are {:?}", moves);
|
println!("Moves are {:?}", moves);
|
||||||
|
|
||||||
assert_eq!(moves.len(), 10);
|
assert_eq!(moves.len(), 10);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue