From f3b2aabf463fac05f7a0115a8fc2f72a529db48b Mon Sep 17 00:00:00 2001 From: stefiosif Date: Sat, 29 Jun 2024 16:22:43 +0300 Subject: [PATCH] Make new fn's to update the State struct --- src/game.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/game.rs b/src/game.rs index 67a674f..b8a2b8f 100644 --- a/src/game.rs +++ b/src/game.rs @@ -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) { + self.en_passant_target_square = sq; + } + pub const fn get_castling_ability(&self, color: Color) -> Castle { match color { Color::White => self.castling_ability[0],