Make 'half_move_clock' a 'u32'
All checks were successful
ci/woodpecker/push/check Pipeline was successful

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*).
This commit is contained in:
Bruno BELANYI 2024-04-01 23:14:11 +01:00
parent 353271f427
commit a4aa4ae1e4
2 changed files with 6 additions and 6 deletions

View file

@ -8,7 +8,7 @@ pub struct ChessBoardBuilder {
// Same fields as [ChessBoard].
castle_rights: [CastleRights; Color::NUM_VARIANTS],
en_passant: Option<Square>,
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
}

View file

@ -24,7 +24,7 @@ pub struct ChessBoard {
/// `Some(target_square)` if a double-step move was made.
en_passant: Option<Square>,
/// 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<Square>,
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);
}