diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/board/mod.rs | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/board/mod.rs b/src/board/mod.rs index 50aa1b9..39248eb 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -208,20 +208,33 @@ impl Board { let source_color = Color::from_piece(source_piece); match source_piece.without_color() { Piece::King => { - self.castling_rights[source_color as usize][CastlingSide::King as usize] = false; - self.castling_rights[source_color as usize][CastlingSide::Queen as usize] = false; - self.zobrist_toggle_castling_right(source_color, CastlingSide::King); - self.zobrist_toggle_castling_right(source_color, CastlingSide::Queen); + let king_side = &mut self.castling_rights[source_color as usize][CastlingSide::King as usize]; + if *king_side { + *king_side = false; + self.zobrist_toggle_castling_right(source_color, CastlingSide::King); + } + + let queen_side = &mut self.castling_rights[source_color as usize][CastlingSide::Queen as usize]; + if *queen_side { + *queen_side = false; + self.zobrist_toggle_castling_right(source_color, CastlingSide::Queen); + } }, Piece::Rook => { match mov.source.file() { 0 => { - self.castling_rights[source_color as usize][CastlingSide::Queen as usize] = false; - self.zobrist_toggle_castling_right(source_color, CastlingSide::Queen); + let queen_side = &mut self.castling_rights[source_color as usize][CastlingSide::Queen as usize]; + if *queen_side { + *queen_side = false; + self.zobrist_toggle_castling_right(source_color, CastlingSide::Queen); + } } 7 => { - self.castling_rights[source_color as usize][CastlingSide::King as usize] = false; - self.zobrist_toggle_castling_right(source_color, CastlingSide::King); + let king_side = &mut self.castling_rights[source_color as usize][CastlingSide::King as usize]; + if *king_side { + *king_side = false; + self.zobrist_toggle_castling_right(source_color, CastlingSide::King); + } } _ => {}, } |