Skip to content

Commit 80824f5

Browse files
authored
Simplify pawn captures (#1040)
Just removes some duplicated code. STC Elo | 3.03 +- 2.63 (95%) SPRT | 8.0+0.08s Threads=1 Hash=16MB LLR | 3.02 (-2.25, 2.89) [-2.75, 0.25] Games | N: 16506 W: 4269 L: 4125 D: 8112 Penta | [54, 1750, 4496, 1904, 49] https://recklesschess.space/test/14929/ No functional change. Bench: 3466720
1 parent c117317 commit 80824f5

1 file changed

Lines changed: 19 additions & 24 deletions

File tree

src/board/movegen.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ impl super::Board {
107107
}
108108
}
109109

110+
fn collect_pawn_captures(&self, list: &mut MoveList, pawns: Bitboard, dir: i8, target: Bitboard, seventh_rank: Bitboard) {
111+
let promos = (pawns & seventh_rank).shift(dir);
112+
list.push_promotion_capture_setwise(dir, promos & target);
113+
let captures = (pawns & !seventh_rank).shift(dir);
114+
list.push_pawns_setwise(dir, captures & target, MoveKind::Capture);
115+
116+
let ep = self.en_passant();
117+
if ep != Square::None && pawns.contains(ep.shift(-dir)) {
118+
list.push(ep.shift(-dir), self.en_passant(), MoveKind::EnPassant);
119+
}
120+
}
121+
110122
fn collect_pawn_moves(&self, list: &mut MoveList, target: Bitboard, pinned: Bitboard, mgkind: MovegenKind) {
111123
let stm = self.side_to_move();
112124
let up = Square::UP[stm];
@@ -134,34 +146,17 @@ impl super::Board {
134146
if mgkind == MovegenKind::Noisy {
135147
list.push_pawns_setwise(up, promotions & target, MoveKind::PromotionQ);
136148

149+
let target = target & self.colors(!stm);
150+
137151
let up_right = up + Square::RIGHT;
138-
let up_left = up + Square::LEFT;
139152
let right_pin_mask = relative_diagonal(stm, king_sq);
140-
let left_pin_mask = relative_diagonal(!stm, king_sq);
141153
let right_pawns = pawns & (!pinned | right_pin_mask) & !Bitboard::file(File::H);
142-
let left_pawns = pawns & (!pinned | left_pin_mask) & !Bitboard::file(File::A);
143-
let target = target & self.colors(!stm);
144-
145-
let right = (right_pawns & seventh_rank).shift(up_right);
146-
let left = (left_pawns & seventh_rank).shift(up_left);
147-
148-
list.push_promotion_capture_setwise(up_right, right & target);
149-
list.push_promotion_capture_setwise(up_left, left & target);
150-
151-
let right_captures = (right_pawns & !seventh_rank).shift(up_right);
152-
let left_captures = (left_pawns & !seventh_rank).shift(up_left);
154+
self.collect_pawn_captures(list, right_pawns, up_right, target, seventh_rank);
153155

154-
list.push_pawns_setwise(up_right, right_captures & target, MoveKind::Capture);
155-
list.push_pawns_setwise(up_left, left_captures & target, MoveKind::Capture);
156-
157-
if self.en_passant() != Square::None {
158-
let ep = self.en_passant().to_bb();
159-
let right_attacker = right_pawns & ep.shift(-up_right);
160-
let left_attacker = left_pawns & ep.shift(-up_left);
161-
for pawn in right_attacker | left_attacker {
162-
list.push(pawn, self.en_passant(), MoveKind::EnPassant);
163-
}
164-
}
156+
let up_left = up + Square::LEFT;
157+
let left_pin_mask = relative_diagonal(!stm, king_sq);
158+
let left_pawns = pawns & (!pinned | left_pin_mask) & !Bitboard::file(File::A);
159+
self.collect_pawn_captures(list, left_pawns, up_left, target, seventh_rank);
165160
}
166161
}
167162
}

0 commit comments

Comments
 (0)