Add utility functions for readability and refactor make_move
This commit is contained in:
@@ -3,10 +3,10 @@ use crate::{board::board::Color, movegen::r#move::MoveType};
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub struct State {
|
||||
side_to_move: Color,
|
||||
castling_ability: [Castle; 2],
|
||||
en_passant_target_square: Option<usize>,
|
||||
halfmove_clock: u8,
|
||||
fullmove_counter: u8,
|
||||
pub castling_ability: [Castle; 2],
|
||||
pub en_passant_target_square: Option<usize>,
|
||||
pub halfmove_clock: u8,
|
||||
pub fullmove_counter: u8,
|
||||
}
|
||||
|
||||
impl State {
|
||||
@@ -40,6 +40,17 @@ impl State {
|
||||
self.en_passant_target_square
|
||||
}
|
||||
|
||||
pub fn set_en_passant_target_square(&mut self, square: Option<usize>) {
|
||||
self.en_passant_target_square = square;
|
||||
}
|
||||
|
||||
pub const fn castling_ability(&self, color: Color) -> Castle {
|
||||
match color {
|
||||
Color::White => self.castling_ability[0],
|
||||
Color::Black => self.castling_ability[1],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_castling_ability(&mut self, color: Color, castle: Castle) {
|
||||
match color {
|
||||
Color::White => self.castling_ability[0] = castle,
|
||||
@@ -95,26 +106,23 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn change_side(&mut self) {
|
||||
pub fn revert_full_move(&mut self, color: Color) {
|
||||
match color {
|
||||
Color::White => (),
|
||||
Color::Black => self.fullmove_counter -= 1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn change_side(&mut self) -> Color {
|
||||
self.side_to_move = match self.side_to_move {
|
||||
Color::White => Color::Black,
|
||||
Color::Black => Color::White,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn next_turn(&self) -> Color {
|
||||
};
|
||||
self.side_to_move
|
||||
}
|
||||
|
||||
pub fn set_en_passant_target_square(&mut self, square: Option<usize>) {
|
||||
self.en_passant_target_square = square;
|
||||
}
|
||||
|
||||
pub const fn castling_ability(&self, color: Color) -> Castle {
|
||||
match color {
|
||||
Color::White => self.castling_ability[0],
|
||||
Color::Black => self.castling_ability[1],
|
||||
}
|
||||
pub const fn current_player(&self) -> Color {
|
||||
self.side_to_move
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user