Make new fn's to update the State struct

This commit is contained in:
2024-06-29 16:22:43 +03:00
parent b46c5874db
commit f3b2aabf46

View File

@@ -71,6 +71,46 @@ impl State {
self.en_passant_target_square
}
pub fn set_castling_ability(&mut self, color: Color, castle: Castle) {
match color {
Color::White => self.castling_ability[0] = castle,
Color::Black => self.castling_ability[1] = castle,
}
}
pub fn update_castling_state(&mut self, square: u8, color: Color) {
if square == 0 || square == 7 {
match (color, self.get_castling_ability(color)) {
(_, Castle::Both) => self.set_castling_ability(color, Castle::Long),
(_, Castle::Short) => self.set_castling_ability(color, Castle::None),
_ => (),
}
}
if square == 56 || square == 63 {
match (color, self.get_castling_ability(color)) {
(_, Castle::Both) => self.set_castling_ability(color, Castle::Short),
(_, Castle::Short) => self.set_castling_ability(color, Castle::None),
_ => (),
}
}
if square == 4 || square == 60 {
self.set_castling_ability(color, Castle::None)
}
}
pub fn next_turn(&mut self) {
self.side_to_move = match self.side_to_move {
Color::White => Color::Black,
Color::Black => Color::White,
}
}
pub fn set_en_passant_target_square(&mut self, sq: Option<u8>) {
self.en_passant_target_square = sq;
}
pub const fn get_castling_ability(&self, color: Color) -> Castle {
match color {
Color::White => self.castling_ability[0],