From a47778ae6cf909cf86e9123e87918254737dfe4c Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Mon, 30 Dec 2024 17:08:27 -0500 Subject: [PATCH] fix: board not same after running minmax caused by an early return from hard stop that bypasses unmake move --- src/search.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/search.rs b/src/search.rs index f4e3643..f0f2b1a 100644 --- a/src/search.rs +++ b/src/search.rs @@ -363,6 +363,7 @@ fn minmax(board: &mut Board, state: &mut EngineState, mm: MinmaxState) -> (Vec (Vec= beta && state.config.alpha_beta_on { // alpha-beta prune. // @@ -596,3 +596,30 @@ pub fn is_quiescent_position(board: &Board, eval: SearchEval) -> bool { (board.eval() - EvalInt::from(abs_eval)).abs() <= THRESHOLD.abs() } + +#[cfg(test)] +mod tests { + use super::*; + + /// Test that running minmax does not alter the board. + #[test] + fn test_board_same() { + let (_tx, rx) = mpsc::channel(); + let cache = TranspositionTable::new(1); + let mut engine_state = EngineState::new( + SearchConfig { + depth: 3, + ..Default::default() + }, + rx, + cache, + TimeLimits::from_movetime(20), + ); + let mut board = + Board::from_fen("2rq1rk1/pp1bbppp/3p4/4p1B1/2B1P1n1/1PN5/P1PQ1PPP/R3K2R w KQ - 1 14") + .unwrap(); + let orig_board = board; + let (_line, _eval) = best_line(&mut board, &mut engine_state); + assert_eq!(board, orig_board) + } +}