aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-20 19:51:26 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-20 22:52:25 +0300
commitd36ee9b193cfc382c952cce69d0a0af9b576e36f (patch)
tree0df119e58df9e8a579ee8e2413752f9be600c550 /src
parent5e4a7b49b0be5128b56ed6107f8593f134a49522 (diff)
downloadchessnost-d36ee9b193cfc382c952cce69d0a0af9b576e36f.tar.gz
feat: apply null move heuristic
Diffstat (limited to 'src')
-rw-r--r--src/board/engine.rs25
1 files 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 {