Make en_passant_square an Option<u8>

This commit is contained in:
2024-06-09 15:54:41 +03:00
parent 880df665d5
commit 1f7cbbe577
4 changed files with 33 additions and 28 deletions

View File

@@ -35,7 +35,7 @@ impl Default for Game {
pub struct State {
side_to_move: Color,
castling_ability: u8,
en_passant_target_square: u8,
en_passant_target_square: Option<u8>,
halfmove_clock: u8,
fullmove_counter: u8,
}
@@ -45,7 +45,7 @@ impl State {
Self {
side_to_move: Color::White,
castling_ability: 0b1111,
en_passant_target_square: 0,
en_passant_target_square: None,
halfmove_clock: 0,
fullmove_counter: 1,
}
@@ -54,7 +54,7 @@ impl State {
pub const fn load_state(
side_to_move: Color,
castling_ability: u8,
en_passant_target_square: u8,
en_passant_target_square: Option<u8>,
halfmove_clock: u8,
fullmove_counter: u8,
) -> Self {
@@ -67,7 +67,7 @@ impl State {
}
}
pub const fn get_en_passant_target_square(&self) -> u8 {
pub const fn get_en_passant_target_square(&self) -> Option<u8> {
self.en_passant_target_square
}
}
@@ -78,7 +78,7 @@ impl fmt::Display for State {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f,
"side_to_move: {:?}\ncastling_ability: {:b}\nen_passant_target_square: {:b}\nhalfmove_clock: {}\nfullmove_counter: {}\n",
self.side_to_move, self.castling_ability, 1_u64 << self.en_passant_target_square, self.halfmove_clock, self.fullmove_counter)
self.side_to_move, self.castling_ability, 1_u64 << self.en_passant_target_square.unwrap_or(0), self.halfmove_clock, self.fullmove_counter)
}
}