[explorer] Add a load command

Loads a board position from a FEN string.

Plumb through setting the Zobrist state on an existing board. Rebuild the hash
when setting the state.
This commit is contained in:
Eryn Wells 2025-06-08 16:49:55 -07:00
parent 428ace13dc
commit 634876822b
3 changed files with 47 additions and 1 deletions

View file

@ -2,6 +2,7 @@
mod captures;
use crate::fen::{FromFenStr, FromFenStrError};
use captures::CapturesList;
use chessfriend_bitboard::BitBoard;
use chessfriend_board::{
@ -230,6 +231,10 @@ impl Position {
pub fn zobrist_hash(&self) -> Option<u64> {
self.board.zobrist_hash()
}
pub fn set_zobrist_state(&mut self, state: Arc<ZobristState>) {
self.board.set_zobrist_state(state);
}
}
impl Position {
@ -238,6 +243,15 @@ impl Position {
}
}
impl FromFenStr for Position {
type Error = FromFenStrError;
fn from_fen_str(string: &str) -> Result<Self, Self::Error> {
let board = Board::from_fen_str(string)?;
Ok(Position::new(board))
}
}
impl ToFenStr for Position {
type Error = <Board as ToFenStr>::Error;