use super::castling_rights::CastlingRights;
use super::enpassant::Enpassant;
use super::{Board, Side};
use chess_notation_parser::{Piece, Square};
const TURN_STR_MAX: usize = 12;
pub struct State {
pub moving_piece_src: Option<Square>,
pub enpassant: Option<Enpassant>,
pub captured: Option<(Square, (Piece, Side))>,
pub fifty_move_rule: u8,
pub castling_rights: CastlingRights,
turn: [u8; TURN_STR_MAX],
}
impl State {
pub fn new(board: &Board, next_turn: String) -> Self {
let mut turn: [u8; TURN_STR_MAX] = [0; 12];
next_turn.as_bytes().iter().enumerate().for_each(|(i, b)| {
turn[i] = *b;
});
Self {
turn,
moving_piece_src: None,
enpassant: board.enpassant.clone(),
fifty_move_rule: board.fifty_move_rule,
castling_rights: board.castling_rights,
captured: None,
}
}
pub fn get_turn(&self) -> &str {
std::str::from_utf8(&self.turn)
.unwrap()
.trim_end_matches('\0')
}
}