aboutsummaryrefslogtreecommitdiff
path: root/src/board/engine.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/board/engine.rs')
-rw-r--r--src/board/engine.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index 53d2564..35aec11 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -5,6 +5,8 @@ use super::ttable::{NodeType, TranspositionTableItem};
static A_FILE: Bitboard = 0x0101010101010101;
+const VALUE_WIN: f32 = 20_000.0;
+
#[derive(Debug, Default, PartialEq)]
pub struct PerftResult {
leaf_nodes: u64,
@@ -320,6 +322,10 @@ impl Board {
}
}
+ if principal_variation.len() == 0 {
+ return (-VALUE_WIN, principal_variation);
+ }
+
(alpha, principal_variation)
}
@@ -376,27 +382,35 @@ impl Board {
let mut alpha = -INFINITY;
let mut beta = INFINITY;
let window_size = 0.25;
+ let mut gradual_widening_multiplier = 1.0; // Grows on cutoffs
while depth <= max_depth {
let search_result = self.negamax_search(alpha, beta, depth, deadline);
println!("Finished depth({}) {:?} [{:?} left]", depth, search_result, deadline - Instant::now());
+ if search_result.0.abs() >= VALUE_WIN {
+ return search_result
+ }
+
if Instant::now() > deadline {
break;
}
if search_result.1.len() > 0 {
depth += 1;
+ gradual_widening_multiplier = 1.0;
alpha = search_result.0 - window_size;
beta = search_result.0 + window_size;
} else if search_result.0 <= alpha { // Alpha-cutoff
println!("Alpha cutoff {} <= {:?}", search_result.0, (alpha, beta));
+ gradual_widening_multiplier *= 4.0;
beta = alpha;
- alpha = search_result.0 - window_size * 4.0;
+ alpha = search_result.0 - window_size * gradual_widening_multiplier;
continue;
} else if search_result.0 >= beta { // Beta-cutoff
println!("Beta cutoff {:?} <= {}", (alpha, beta), search_result.0);
+ gradual_widening_multiplier *= 4.0;
alpha = beta;
- beta = search_result.0 + window_size * 4.0;
+ beta = search_result.0 + window_size * gradual_widening_multiplier;
continue;
} else {
panic!("Can this ever be possible? (probably not)");