fix: board not same after running minmax

caused by an early return from hard stop that bypasses unmake move
This commit is contained in:
dogeystamp 2024-12-30 17:08:27 -05:00
parent 4bd2fd1d9a
commit a47778ae6c
No known key found for this signature in database

View File

@ -363,6 +363,7 @@ fn minmax(board: &mut Board, state: &mut EngineState, mm: MinmaxState) -> (Vec<M
quiesce: mm.quiesce,
},
);
anti_mv.unmake(board);
// propagate hard stops
if matches!(score, SearchEval::Stopped) {
@ -376,7 +377,6 @@ fn minmax(board: &mut Board, state: &mut EngineState, mm: MinmaxState) -> (Vec<M
best_continuation = continuation;
}
alpha = max(alpha, abs_best.into());
anti_mv.unmake(board);
if alpha >= 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)
}
}