From d36ee9b193cfc382c952cce69d0a0af9b576e36f Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 20 Feb 2023 19:51:26 +0300 Subject: feat: apply null move heuristic --- src/board/engine.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/board/engine.rs b/src/board/engine.rs index 7f2fef3..ee5be65 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -371,13 +371,32 @@ impl Board { None => {}, } - let mut moves = self.generate_pseudolegal_moves(color); - moves = self.order_moves(moves, parent_killers.to_vec()); - if depth_left == 0 { return (self.quiscence(alpha, beta), principal_variation); } + // Try a Null Move heuristic + if !is_in_check && depth_left >= 3 { + let reduction = 3; + // Apply Null Move + self.ply += 1; + self.hash ^= self.zobrist_seed[780]; + + let (mut score, ..) = self.negamax_search(-beta, -alpha, (depth_left as i8 - 1 - reduction).max(0) as u8, &mut Vec::new(), deadline); + score *= -1.; + + // Undo Null Move + self.ply -= 1; + self.hash ^= self.zobrist_seed[780]; + + if score >= beta { + return (beta, principal_variation); + } + } + + let mut moves = self.generate_pseudolegal_moves(color); + moves = self.order_moves(moves, parent_killers.to_vec()); + let mut should_pv_search = true; // = !should_apply_LMR let mut legal_move_found = false; for mov in moves { -- cgit v1.2.3