diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-23 08:47:23 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-23 08:55:01 +0300 |
commit | 6719e247a3e0c75261665eca166fc5c8c8fdaf27 (patch) | |
tree | 29e286f0c7b7886a97737cddf0a2d303bfa1bbf9 /src/board.rs | |
parent | 208b35121f9dab4c60c82813b051eeabc9d502cd (diff) | |
download | chessnost-6719e247a3e0c75261665eca166fc5c8c8fdaf27.tar.gz |
refactor: separately store pawn double pushes
Diffstat (limited to 'src/board.rs')
-rw-r--r-- | src/board.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/board.rs b/src/board.rs index 625711e..24bdefa 100644 --- a/src/board.rs +++ b/src/board.rs @@ -144,7 +144,8 @@ impl Board { pub fn generate_moves(&self, color: Color) -> Vec<Move> { let mut moves = Vec::with_capacity(1024); let opponent_occupancy = self.color_occupancy(Color::from(1 - color as u8)); - let available_targets = opponent_occupancy | self.empty(); + let empty = self.empty(); + let available_targets = opponent_occupancy | empty; for (piece_type, piece) in self.pieces_by_color(color).iter().enumerate() { match PieceType::from(piece_type) { PieceType::Pawn => { @@ -152,14 +153,18 @@ impl Board { for target in serialize_bitboard(self.attacks.pawn[color as usize][source as usize] & opponent_occupancy) { moves.push(Move { source, target }); }; - } - for source in serialize_bitboard(*piece) { for target in serialize_bitboard(self.attacks.pawn_pushes[color as usize][source as usize] & available_targets) { - // Exclude double pushes in a monkey way - // TODO: properly rewrite this storing a separate bitboard for double pushes - if !((source as u8 / 8 == 1) && (target as u8 / 8 == 3) && (self.occupancy & (1 << (source as u8 + 8)) > 0)) { - moves.push(Move { source, target }); - } + moves.push(Move { source, target }); + }; + } + + let able_to_double_push_mask = match color { + Color::White => empty >> 8, + Color::Black => empty << 8, + }; + for source in serialize_bitboard(*piece & able_to_double_push_mask) { + for target in serialize_bitboard(self.attacks.pawn_double_pushes[color as usize][source as usize] & available_targets) { + moves.push(Move { source, target }); }; } } |