From a4aa4ae1e47a221d5b932e81bfe0d51fa7e0c4ac Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 1 Apr 2024 23:14:11 +0100 Subject: [PATCH] Make 'half_move_clock' a 'u32' It *could* be set to a high value due to e.g: starting the engine in the middle of a game. Moving from a `u8` to a `u32` does not change the size of the type, so let's just do that. Use that opportunity to fix the comment about the number of *half-moves* (it's 50 moves *per player*). --- src/board/chess_board/builder.rs | 4 ++-- src/board/chess_board/mod.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/board/chess_board/builder.rs b/src/board/chess_board/builder.rs index d509e67..d16c881 100644 --- a/src/board/chess_board/builder.rs +++ b/src/board/chess_board/builder.rs @@ -8,7 +8,7 @@ pub struct ChessBoardBuilder { // Same fields as [ChessBoard]. castle_rights: [CastleRights; Color::NUM_VARIANTS], en_passant: Option, - half_move_clock: u8, + half_move_clock: u32, side: Color, // 1-based, a turn is *two* half-moves (i.e: both players have played). turn_count: u32, @@ -41,7 +41,7 @@ impl ChessBoardBuilder { self } - pub fn with_half_move_clock(&mut self, clock: u8) -> &mut Self { + pub fn with_half_move_clock(&mut self, clock: u32) -> &mut Self { self.half_move_clock = clock; self } diff --git a/src/board/chess_board/mod.rs b/src/board/chess_board/mod.rs index d28d69c..9ceb673 100644 --- a/src/board/chess_board/mod.rs +++ b/src/board/chess_board/mod.rs @@ -24,7 +24,7 @@ pub struct ChessBoard { /// `Some(target_square)` if a double-step move was made. en_passant: Option, /// The number of half-turns without either a pawn push or capture. - half_move_clock: u8, // Should never go higher than 50. + half_move_clock: u32, // Should *probably* never go higher than 100. /// The number of half-turns so far. total_plies: u32, // Should be plenty. /// The current player turn. @@ -36,7 +36,7 @@ pub struct ChessBoard { pub struct NonReversibleState { castle_rights: [CastleRights; Color::NUM_VARIANTS], en_passant: Option, - half_move_clock: u8, // Should never go higher than 50. + half_move_clock: u32, // Should *probably* never go higher than 100. } impl ChessBoard { @@ -105,7 +105,7 @@ impl ChessBoard { /// Return the number of half-turns without either a pawn push or a capture. #[inline(always)] - pub fn half_move_clock(&self) -> u8 { + pub fn half_move_clock(&self) -> u32 { self.half_move_clock } @@ -214,7 +214,7 @@ impl ChessBoard { } // Make sure the clocks are in agreement. - if u32::from(self.half_move_clock()) > self.total_plies() { + if self.half_move_clock() > self.total_plies() { return Err(InvalidError::HalfMoveClockTooHigh); }