Make new fn's to update the State struct
This commit is contained in:
40
src/game.rs
40
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<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],
|
||||
|
||||
Reference in New Issue
Block a user