aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/board/mod.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/board/mod.rs b/src/board/mod.rs
index 8f5fbde..f710057 100644
--- a/src/board/mod.rs
+++ b/src/board/mod.rs
@@ -540,7 +540,7 @@ impl Board {
}
/// *Blindlessly* apply a move without any validation
- /// Move should be validated beforehand
+ /// Legality test should still be performed
pub fn make_move(&mut self, mov: Move) -> Option<PieceType> {
let move_source_bb = mov.source.to_bitboard();
let move_target_bb = mov.target.to_bitboard();
@@ -645,7 +645,7 @@ impl Board {
// Withdraw castling rights when moving rooks or king
let source_color = Color::from_piece(source_piece) as usize;
- match source_piece {
+ match source_piece.without_color() {
PieceType::King => {
self.castling_rights[source_color][CastlingSide::King as usize] = false;
self.castling_rights[source_color][CastlingSide::Queen as usize] = false;
@@ -978,4 +978,22 @@ mod tests {
assert_eq!(board.is_square_attacked(Square::B6, Color::Black), true);
}
+ #[test]
+ fn moved_king_castle() {
+ let fen = String::from("4k2r/ppp1n3/8/4R1Pp/5P2/q1P5/P1P1BP2/1K1R4 b - - 2 22");
+ let mut board = Board::from_FEN(fen);
+ board.ply += 1;
+
+ // Shuffle kings around, returning to the same position
+ board.make_move(Move { source: Square::E8, target: Square::F8, kind: MoveKind::Quiet });
+ board.make_move(Move { source: Square::B1, target: Square::A1, kind: MoveKind::Quiet });
+ board.make_move(Move { source: Square::F8, target: Square::E8, kind: MoveKind::Quiet });
+ board.make_move(Move { source: Square::A1, target: Square::B1, kind: MoveKind::Quiet });
+
+ let moves = board.generate_pseudolegal_moves(board.color());
+
+ let castle = moves.iter().find(|m| **m == Move { source: Square::E8, target: Square::G8, kind: MoveKind::Castle });
+ println!("{:?}", board.castling_rights);
+ assert!(castle.is_none(), "Castle should not be allowed after king has moved");
+ }
}