diff options
Diffstat (limited to 'src/board/engine.rs')
-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; |