aboutsummaryrefslogtreecommitdiff
path: root/src/board.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/board.rs')
-rw-r--r--src/board.rs21
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 });
};
}
}