From cb47cc3c8b3d431177587150292ea77fcb1620c7 Mon Sep 17 00:00:00 2001 From: stefiosif Date: Wed, 15 Jul 2026 19:29:48 +0300 Subject: [PATCH] Make history heuristic param optional on move ordering to avoid allocating space in q search --- src/search/move_ordering.rs | 17 ++++++----------- src/search/negamax.rs | 2 +- src/search/quiescence.rs | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/search/move_ordering.rs b/src/search/move_ordering.rs index c1beab8..2fc92df 100644 --- a/src/search/move_ordering.rs +++ b/src/search/move_ordering.rs @@ -11,7 +11,7 @@ pub fn score_move( mv: Move, killer_move: Option, color: Color, - history_heuristic: &[[[i32; 64]; 64]; 2], + history_heuristic: Option<&[[[i32; 64]; 64]; 2]>, tt_move: Option, ) -> i32 { if Some(mv) == tt_move { @@ -30,7 +30,9 @@ pub fn score_move( return 6; } - -history_heuristic[color][mv.src()][mv.dst()] + MAX_HISTORY + 6 + 1 + history_heuristic.map_or(MAX_HISTORY + 6 + 1, |hh| { + -hh[color][mv.src()][mv.dst()] + MAX_HISTORY + 6 + 1 + }) } #[cfg(test)] @@ -53,14 +55,7 @@ mod tests { let mut moves = vec![castle, queen_takes_pawn, pawn_takes_queen]; moves.sort_unstable_by_key(|mv| { - score_move( - &game.mailbox, - *mv, - None, - game.current_player(), - &[[[0; 64]; 64]; 2], - None, - ) + score_move(&game.mailbox, *mv, None, game.current_player(), None, None) }); assert_eq!(moves, vec![pawn_takes_queen, queen_takes_pawn, castle]); @@ -71,7 +66,7 @@ mod tests { *mv, None, game.current_player(), - &[[[0; 64]; 64]; 2], + None, Some(castle), ) }); diff --git a/src/search/negamax.rs b/src/search/negamax.rs index 4858795..405d1ec 100644 --- a/src/search/negamax.rs +++ b/src/search/negamax.rs @@ -101,7 +101,7 @@ pub fn negamax( *mv, game.killer[plies as usize], color, - &game.history_heuristic, + Some(&game.history_heuristic), entry.and_then(|entry| entry.mv), ) }); diff --git a/src/search/quiescence.rs b/src/search/quiescence.rs index c036807..e53b665 100644 --- a/src/search/quiescence.rs +++ b/src/search/quiescence.rs @@ -48,7 +48,7 @@ pub fn quiescence( *mv, None, color, - &[[[0; 64]; 64]; 2], + None, entry.and_then(|entry| entry.mv), ) });