diff options
Diffstat (limited to 'src/board')
-rw-r--r-- | src/board/engine.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs index 2c294a3..821c4a4 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -267,6 +267,7 @@ impl Board { return (self.quiscence(alpha, beta), principal_variation); } + let mut should_pv_search = true; let mut legal_move_found = false; for mov in moves { let ep_target_before = self.ep_target.clone(); @@ -276,7 +277,22 @@ impl Board { if !self.is_king_in_check(color) { legal_move_found = true; - let (mut score, mut subtree_pv) = self.negamax_search(-beta, -alpha, depth_left - 1, deadline); + + let (mut score, mut subtree_pv) = if should_pv_search { + // Assume PV-node is high in the list (if move ordering is good) + self.negamax_search(-beta, -alpha, depth_left - 1, deadline) + } else { + // After we have PV-node (that raised alpha) all other nodes will be searched + // with zero-window first to confirm this assumption + let result = self.negamax_search(-(alpha + 0.0001), -alpha, depth_left - 1, deadline); + // In case some of the other nodes raises alpha, then it's true PV node now, + // let's research with full window to find its exact value + if -result.0 > alpha { + self.negamax_search(-beta, -alpha, depth_left - 1, deadline) + } else { + result + } + }; score *= -1.; self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before); @@ -293,6 +309,7 @@ impl Board { } if score > alpha { alpha = score; + should_pv_search = false; // Once we have PV-node we can start zero-window searching principal_variation = Vec::with_capacity(depth_left as usize); principal_variation.push(mov); principal_variation.append(&mut subtree_pv); |