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.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index b6daacf..0a99def 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -1,4 +1,4 @@
-use std::{cmp::Ordering, time::{Instant, Duration}, f32::INFINITY};
+use std::{time::{Instant, Duration}, f32::INFINITY};
use crate::{bitboard::pop_count, board::*};
use super::ttable::{NodeType, TranspositionTableItem};
@@ -245,20 +245,38 @@ impl Board {
let start = Instant::now();
let deadline = start + duration;
let mut result = None;
- let mut depth = 0;
+ let mut depth = 1;
+ let mut alpha = -INFINITY;
+ let mut beta = INFINITY;
+ let window_size = 0.5;
loop {
- let search_result = self.negamax_search(-INFINITY, INFINITY, depth, deadline);
+ let search_result = self.negamax_search(alpha, beta, depth, deadline);
println!("Finished depth({}) {:?} [{:?} left]", depth, search_result, deadline - Instant::now());
+ if search_result.1.len() > 0 {
+ depth += 1;
+ 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));
+ alpha = search_result.0 - window_size;
+ } else if search_result.0 >= beta { // Beta-cutoff
+ println!("Beta cutoff {:?} <= {}", (alpha, beta), search_result.0);
+ beta = search_result.0 + window_size;
+ } else {
+ panic!("Can this ever be possible? (probably not)");
+ }
+
if Instant::now() > deadline {
match result {
Some(r) => return r,
None => panic!("Could not find a move in time"),
}
}
+
result = Some(search_result);
- depth += 1;
+
}
}
}