Skip to content

Commit

Permalink
cheng: Fix captures not reseting half move clock
Browse files Browse the repository at this point in the history
  • Loading branch information
francorbacho committed Feb 1, 2024
1 parent fa6030a commit a4b1cc5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
19 changes: 10 additions & 9 deletions cheng/src/board/borked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,7 @@ impl BorkedBoard {
pawn_pieces.reset(actual_pawn_square);
}

self.side_mut(self.turn.opposite())
.remove(movement.destination);

self.white_side.update_threats(&self.black_side);
self.black_side.update_threats(&self.white_side);

self.white_side.update_king_in_check(&self.black_side);
self.black_side.update_king_in_check(&self.white_side);

// This handles en passant capture as well.
if piece_is_pawn
|| self
.side(self.turn.opposite())
Expand All @@ -155,6 +147,15 @@ impl BorkedBoard {
self.fullmove_clock += 1;
}

self.side_mut(self.turn.opposite())
.remove(movement.destination);

self.white_side.update_threats(&self.black_side);
self.black_side.update_threats(&self.white_side);

self.white_side.update_king_in_check(&self.black_side);
self.black_side.update_king_in_check(&self.white_side);

self.turn = self.turn.opposite();
}

Expand Down
11 changes: 11 additions & 0 deletions cheng/tests/correctness_game_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ fn correctness_game_result_50_move_draw() {
board.try_feed("f5e5").unwrap_err();
}

#[test]
fn correctness_game_result_50_move_draw_capture() {
// https://lichess.org/analysis/fromPosition/4k3/8/8/1p6/8/2b5/3N4/4K3_b_-_-_99_1
cheng::init();

let mut board = Board::from_fen("4k3/8/8/1p6/8/2b5/3N4/4K3 b - - 99 1").unwrap();
board.try_feed("c3d2").unwrap();

assert_eq!(board.result(), GameResult::Undecided);
}

#[test]
fn correctness_game_result_stalemate() {
// https://lichess.org/analysis/7k/8/8/6Q1/8/8/8/4K3_w_-_-_0_1?color=white
Expand Down

0 comments on commit a4b1cc5

Please sign in to comment.