diff --git a/src/board.rs b/src/board.rs index 1413328..2d12dd9 100644 --- a/src/board.rs +++ b/src/board.rs @@ -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)] diff --git a/src/player_interaction/ai.rs b/src/player_interaction/ai.rs index fcd9b22..ab34fd9 100644 --- a/src/player_interaction/ai.rs +++ b/src/player_interaction/ai.rs @@ -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 mut line_letters = line_letters.clone(); *line_letters.get_mut(line_index as usize).unwrap() = Some(letter); @@ -476,13 +474,15 @@ impl AI { available_letters.iter() .for_each(|in_tray| { - if skipped_one || *in_tray != letter { + if skipped_one || !in_tray.partial_match(&letter) { new_available_letters.push(*in_tray); } else { skipped_one = true; } }); + assert!(skipped_one); // at least one should have been removed + self.evaluate_spot_heading_right( &line_letters, line_cross_letters, @@ -771,15 +771,27 @@ mod tests { }); let mut ai = AI::new(difficulty, &dictionary); - + let moves = ai.find_all_moves(&tray, &board); //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); println!("Moves are {:?}", moves); assert_eq!(moves.len(), 10); - } #[test]