diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-02-20 22:52:50 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-02-20 22:52:50 +0300 |
commit | cfea4b23ef73d064001ffa0b17366f13d715ff0a (patch) | |
tree | 0fa0fac51601a672846199145febac7d3f743868 | |
parent | d36ee9b193cfc382c952cce69d0a0af9b576e36f (diff) | |
download | chessnost-cfea4b23ef73d064001ffa0b17366f13d715ff0a.tar.gz |
feat: accept and gracefully handle instability
-rw-r--r-- | src/board/engine.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs index ee5be65..2e22b35 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -566,6 +566,14 @@ impl Board { let mut gradual_widening_counter = 0; let mut root_killers: Vec<Move> = Vec::new(); + // Gracefully handle search instability + #[derive(PartialEq)] + enum Cutoff { + Alpha, + Beta, + } + let mut latest_cutoff = None; + while depth <= max_depth { if print { @@ -595,6 +603,16 @@ impl Board { gradual_widening_counter += 1; beta = alpha + window_size * 0.1; alpha = search_result.0 - window_size * 2.0f32.powi(gradual_widening_counter); + if latest_cutoff == Some(Cutoff::Beta) { + println!("Detected search instability! You are probably in Zugzwang. Aborting..."); + depth += 1; + latest_cutoff = None; + gradual_widening_counter = 0; + alpha = search_result.0 - window_size; + beta = search_result.0 + window_size; + continue; + } + latest_cutoff = Some(Cutoff::Alpha); continue; } if search_result.0 >= beta { // Beta-cutoff @@ -604,11 +622,22 @@ impl Board { gradual_widening_counter += 1; alpha = beta - window_size * 0.1; beta = search_result.0 + window_size * 2.0f32.powi(gradual_widening_counter); + if latest_cutoff == Some(Cutoff::Alpha) { + println!("Detected search instability! You are probably in Zugzwang. Aborting..."); + depth += 1; + latest_cutoff = None; + gradual_widening_counter = 0; + alpha = search_result.0 - window_size; + beta = search_result.0 + window_size; + continue; + } + latest_cutoff = Some(Cutoff::Beta); continue; } if search_result.1.len() > 0 { depth += 1; + latest_cutoff = None; gradual_widening_counter = 0; alpha = search_result.0 - window_size; beta = search_result.0 + window_size; |