aboutsummaryrefslogtreecommitdiff
path: root/src/board/move_generation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/board/move_generation.rs')
-rw-r--r--src/board/move_generation.rs15
1 files changed, 12 insertions, 3 deletions
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 {