Add State struct as part of Board struct

This commit is contained in:
2024-06-09 15:21:11 +03:00
parent a6d6347270
commit 2133fb3cad
3 changed files with 33 additions and 20 deletions

View File

@@ -5,7 +5,7 @@ use String as FenError;
pub fn from_fen(fen: &str) -> Result<Game, FenError> {
let fen_parts: Vec<_> = fen.split_whitespace().collect();
let board = piece_placement(fen_parts[0])?;
let mut board = piece_placement(fen_parts[0])?;
let side_to_move = side_to_move(fen_parts[1])?;
@@ -17,16 +17,14 @@ pub fn from_fen(fen: &str) -> Result<Game, FenError> {
let fullmove_counter = fullmove_counter(fen_parts[5])?;
Ok(Game {
board,
state: State::load_state(
side_to_move,
castling_ability,
en_passant_target_square,
halfmove_clock,
fullmove_counter,
),
})
board.set_state(State::load_state(
side_to_move,
castling_ability,
en_passant_target_square,
halfmove_clock,
fullmove_counter,
));
Ok(Game { board })
}
pub fn piece_placement(pieces: &str) -> Result<Board, FenError> {