Compare commits
1 commit
f9ba6fa680
...
e9396cc6cb
| Author | SHA1 | Date | |
|---|---|---|---|
| e9396cc6cb |
1 changed files with 15 additions and 11 deletions
|
|
@ -170,24 +170,28 @@ impl ChessBoard {
|
|||
} else {
|
||||
self.en_passant = None;
|
||||
}
|
||||
let castle_rights = self.castle_rights_mut(self.current_player());
|
||||
*castle_rights = match (move_piece, chess_move.start().file()) {
|
||||
(Piece::Rook, File::A) => castle_rights.without_queen_side(),
|
||||
(Piece::Rook, File::H) => castle_rights.without_king_side(),
|
||||
(Piece::King, _) => CastleRights::NoSide,
|
||||
_ => *castle_rights,
|
||||
};
|
||||
if move_piece == Piece::King {
|
||||
*self.castle_rights_mut(self.current_player()) = CastleRights::NoSide;
|
||||
}
|
||||
if move_piece == Piece::Rook {
|
||||
let castle_rights = self.castle_rights_mut(self.current_player());
|
||||
*castle_rights = match chess_move.start().file() {
|
||||
File::A => castle_rights.without_queen_side(),
|
||||
File::H => castle_rights.without_king_side(),
|
||||
_ => *castle_rights,
|
||||
}
|
||||
}
|
||||
if let Some(piece) = captured_piece {
|
||||
*self.piece_occupancy_mut(piece) ^= chess_move.destination();
|
||||
*self.color_occupancy_mut(opponent) ^= chess_move.destination();
|
||||
self.combined_occupancy ^= chess_move.destination();
|
||||
// If a rook is captured, it loses its castling rights
|
||||
let castle_rights = self.castle_rights_mut(opponent);
|
||||
*castle_rights = match (piece, chess_move.destination().file()) {
|
||||
(Piece::Rook, File::A) => castle_rights.without_queen_side(),
|
||||
(Piece::Rook, File::H) => castle_rights.without_king_side(),
|
||||
*castle_rights = match chess_move.destination().file() {
|
||||
File::A if piece == Piece::Rook => castle_rights.without_queen_side(),
|
||||
File::H if piece == Piece::Rook => castle_rights.without_king_side(),
|
||||
_ => *castle_rights,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Revertible state modification
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue