From c101f2e230a2ed021ce54d6278ce120ad6d850fe Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 18 Jan 2024 22:12:38 +0100 Subject: fix: clamp score to keep it inside the window --- src/grossmeister/search.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs index 0ca5ef4..c195527 100644 --- a/src/grossmeister/search.rs +++ b/src/grossmeister/search.rs @@ -50,18 +50,20 @@ impl Grossmeister { if let Some(transposition) = self.transposition() { if transposition.depth >= depth_left { match transposition.node_type { - NodeType::PV | NodeType::Cut => { + NodeType::PV => { + return transposition.score.clamp(alpha, beta); + } + NodeType::Cut => { if transposition.score >= beta { - return beta - } - if transposition.score > alpha { - alpha = transposition.score + return beta; } + alpha = transposition.score.clamp(alpha, beta); } NodeType::All => { if transposition.score <= alpha { - return alpha + return alpha; } + beta = transposition.score.clamp(alpha, beta); } } } @@ -171,18 +173,20 @@ impl Grossmeister { if let Some(transposition) = self.transposition() { match transposition.node_type { - NodeType::PV | NodeType::Cut => { + NodeType::PV => { + return transposition.score.clamp(alpha, beta); + } + NodeType::Cut => { if transposition.score >= beta { - return beta - } - if transposition.score > alpha { - alpha = transposition.score + return beta; } + alpha = transposition.score.clamp(alpha, beta); } NodeType::All => { if transposition.score <= alpha { - return alpha + return alpha; } + beta = transposition.score.clamp(alpha, beta); } } } -- cgit v1.2.3