From ea63c58ce7e9dbc0e1c0e1cb679a89c038e2edd3 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 31 Aug 2023 14:58:40 +0300 Subject: fix: consider promotion a tactical move --- src/board/move_generation.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/board') diff --git a/src/board/move_generation.rs b/src/board/move_generation.rs index 7669b85..abc603a 100644 --- a/src/board/move_generation.rs +++ b/src/board/move_generation.rs @@ -55,9 +55,15 @@ impl Board { // Generalized attack/move pattern for all pieces for target in (move_targets & targets).serialize() { moves.push(Move { source, target, kind }); + } + + // Promotions + if piece_type == Piece::Pawn && tactical_only { + // All promotions are tactical, but target square can be empty + let iter_captures = (move_targets & targets).serialize(); + let iter_pushes = (self.attacks.pawn_pushes[color as usize][source as usize] & empty).serialize(); - // Promotions - if piece_type == Piece::Pawn { + for target in iter_pushes.chain(iter_captures) { if target.rank() == 7 { for promo_type in [Piece::Bishop, Piece::Knight, Piece::Rook, Piece::Queen] { moves.push(Move { source, target, kind: MoveKind::Promotion(promo_type)}) @@ -152,6 +158,7 @@ impl Board { } } } + moves } } @@ -164,7 +171,7 @@ mod tests { #[test] fn generate_pseudolegal_moves_starting_position() { - let mut board = Board::new(); + let board = Board::new(); let moves = board.generate_pseudolegal_moves(); let black_moves = board.generate_pseudolegal_moves(); @@ -212,6 +219,7 @@ mod tests { // Make sure tactical_only and true_tactical are identical sets for mov in tactical_only.iter() { assert!(true_tactical.iter().any(|m| *m == *mov)); + assert!(mov.is_tactical()); } for mov in true_tactical { assert!(tactical_only.iter().any(|m| *m == mov)); @@ -219,6 +227,7 @@ mod tests { // Make sure quiet_only and true_quiet are identical sets for mov in quiet_only.iter() { + assert!(!mov.is_tactical()); assert!(true_quiet.iter().any(|m| *m == *mov)); } for mov in true_quiet { -- cgit v1.2.3