Make from_fen return Result<Board, FenError>

This commit is contained in:
2024-05-29 20:39:38 +03:00
parent 9876fc0465
commit b471aaf109
2 changed files with 37 additions and 26 deletions

View File

@@ -2,6 +2,7 @@ use crate::{
board::{Board, Color},
fen::from_fen,
};
use String as FenError;
#[derive(Debug, PartialEq)]
pub struct Game {
@@ -17,7 +18,7 @@ impl Game {
}
}
pub fn new_from_fen(fen: &str) -> Game {
pub fn new_from_fen(fen: &str) -> Result<Game, FenError> {
from_fen(fen)
}
@@ -75,7 +76,7 @@ impl fmt::Display for State {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f,
"side_to_move: {:?}\ncastling_ability: {:b}\nen_passant_target_square: {:b}\nhalfmove_clock: {}\nfullmove_counter: {}\n",
self.side_to_move, self.castling_ability, 1u64 << self.en_passant_target_square, self.halfmove_clock, self.fullmove_counter)
self.side_to_move, self.castling_ability, 1_u64 << self.en_passant_target_square, self.halfmove_clock, self.fullmove_counter)
}
}