From e06d6148859bddc0e4a80a3cb6983ca3700b768b Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Wed, 25 Dec 2024 17:31:32 -0500 Subject: [PATCH] tune: only push history for real moves --- src/lib.rs | 5 +++++ src/main.rs | 1 + src/movegen.rs | 4 ---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5661445..3b5a239 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -628,6 +628,11 @@ impl Board { Board::from_fen(START_POSITION).unwrap() } + /// Save the current position's hash in the history. + pub fn push_history(&mut self) { + self.history.push(self.zobrist); + } + /// Get iterator over all squares. pub fn squares() -> impl Iterator { (0..N_SQUARES).map(Square::try_from).map(|x| x.unwrap()) diff --git a/src/main.rs b/src/main.rs index 088de22..ffd7d1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,6 +64,7 @@ fn cmd_position_moves(mut tokens: std::str::SplitWhitespace<'_>, mut board: Boar for mv in tokens.by_ref() { let mv = Move::from_uci_algebraic(mv).unwrap(); let _ = mv.make(&mut board); + board.push_history(); } } _ => ignore!(), diff --git a/src/movegen.rs b/src/movegen.rs index 0db883b..3ae2ac7 100644 --- a/src/movegen.rs +++ b/src/movegen.rs @@ -98,8 +98,6 @@ pub struct AntiMove { impl AntiMove { /// Undo the move. pub fn unmake(self, pos: &mut Board) { - pos.history.pop(); - Zobrist::toggle_board_info(pos); pos.move_piece(self.dest, self.src); @@ -186,8 +184,6 @@ impl Move { ep_square: pos.ep_square, }; - pos.history.push(pos.zobrist); - // undo hashes (we will update them at the end of this function) Zobrist::toggle_board_info(pos);