aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-08-19 21:16:26 +0300
committereug-vs <eugene@eug-vs.xyz>2023-08-19 21:16:26 +0300
commit9bf3c532018bb96792d60840b1c37cd9df94b927 (patch)
treeb357d0ca99b48e23a74a9a786f66467b4da84629
parenta6fe0cf85e3664013f50bad0f77d3003c3c2700b (diff)
downloadchessnost-9bf3c532018bb96792d60840b1c37cd9df94b927.tar.gz
fix: do not toggle castling rights when not needed
-rw-r--r--src/board/mod.rs29
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);
+ }
}
_ => {},
}