diff --git a/engine/src/bitboard/board.rs b/engine/src/bitboard/board.rs index 75ac76b..ff80f61 100644 --- a/engine/src/bitboard/board.rs +++ b/engine/src/bitboard/board.rs @@ -14,6 +14,7 @@ pub struct Board { } impl Board { + pub const EMPTY_SQUARE: u8 = 12; pub fn new_clear() -> Self { let mut bit_board: Self = Self { diff --git a/engine/src/bitboard/makemove.rs b/engine/src/bitboard/makemove.rs index 1968e0f..115d034 100644 --- a/engine/src/bitboard/makemove.rs +++ b/engine/src/bitboard/makemove.rs @@ -12,7 +12,7 @@ impl Board { match move_type { BitMoveType::Quiet => { - + self.make_quiet(played_move); } BitMoveType::Capture => { diff --git a/engine/src/bitboard/makemove/quiets.rs b/engine/src/bitboard/makemove/quiets.rs index e69de29..0def6b7 100644 --- a/engine/src/bitboard/makemove/quiets.rs +++ b/engine/src/bitboard/makemove/quiets.rs @@ -0,0 +1,62 @@ + +use super::*; + +impl Board { + pub fn make_quiet(&mut self, played_move: &BitMove) { + let main_from: usize = played_move.from_square() as usize; + let main_to: usize = played_move.to_square() as usize; + let main_piece: usize = self.piece_board(main_from as u8) as usize; + let friendly_occupancy = main_piece/6; + + let color_offset = self.side_to_move * 6; + let castling_offset = 2 - 2 * self.side_to_move as usize; + let castling_rights = self.castling_rights >> castling_offset; + + self.bitboards[main_piece] &= !(1 << main_from); + self.occupancy[friendly_occupancy] &= !(1 << main_from); + self.piece_board[main_from] = Self::EMPTY_SQUARE; + + if let Some(promotion_piece) = played_move.promotion_piece() { + let promotion_piece = (color_offset + promotion_piece) as usize; + self.bitboards[promotion_piece] |= 1 << main_to; + self.occupancy[friendly_occupancy] |= 1 << main_to; + self.piece_board[main_to] = promotion_piece as u8; + } + else { + self.bitboards[main_piece] |= 1 << main_to; + self.occupancy[friendly_occupancy] |= 1 << main_to; + self.piece_board[main_to] = main_piece as u8; + + if main_piece == 0 && (main_to - main_from) == 16 { + let new_en_passant = main_to - 8; + self.en_passant_square = 1 << new_en_passant; + } + else if main_piece == 6 && (main_from - main_to) == 16 { + let new_en_passant = main_to + 8; + self.en_passant_square = 1 << new_en_passant; + } + else if main_piece == 5 + color_offset as usize + && castling_rights != 0 { + if castling_rights & 0b1 != 0 { + self.castling_rights &= !(1 << castling_offset); + } + if castling_rights & 0b10 != 0 { + self.castling_rights &= !(2 << castling_offset); + } + } + else if main_piece == 3 + color_offset as usize + && castling_rights != 0 { + let back_rank_offset = 56 * self.side_to_move as usize; + + if castling_rights & 0b10 != 0 + && main_from == 7 + back_rank_offset { + self.castling_rights &= !(2 << castling_offset); + } + else if castling_rights & 0b1 != 0 + && main_from == back_rank_offset { + self.castling_rights &= !(1 << castling_offset); + } + } + } + } +} \ No newline at end of file