aboutsummaryrefslogtreecommitdiff
path: root/src/board
diff options
context:
space:
mode:
Diffstat (limited to 'src/board')
-rw-r--r--src/board/engine.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index 18abaa0..46cf8ed 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -507,7 +507,7 @@ impl Board {
alpha
}
- pub fn iterative_deepening(&mut self, max_depth: u8, duration: Duration) -> (f32, Vec<Move>) {
+ pub fn iterative_deepening(&mut self, max_depth: u8, duration: Duration, print: bool) -> (f32, Vec<Move>) {
let start = Instant::now();
let deadline = start + duration;
let mut result = None;
@@ -520,7 +520,9 @@ impl Board {
while depth <= max_depth {
- println!("\nSearching depth({}) in the window {:?}", depth, (alpha, beta));
+ if print {
+ println!("\nSearching depth({}) in the window {:?}", depth, (alpha, beta));
+ }
let search_result = self.negamax_search(alpha, beta, depth, &mut root_killers, deadline);
if search_result.0.abs() >= VALUE_WIN {
@@ -528,21 +530,29 @@ impl Board {
}
if Instant::now() > deadline {
- println!("Aborting...");
+ if print {
+ println!("Aborting...");
+ }
break;
}
- println!("Finished depth({}) {:?} [{:?} left]", depth, search_result, deadline - Instant::now());
+ if print {
+ println!("Finished depth({}) {:?} [{:?} left]", depth, search_result, deadline - Instant::now());
+ }
if search_result.0 <= alpha { // Alpha-cutoff
- println!("Alpha cutoff {} <= {:?}", search_result.0, (alpha, beta));
+ if print {
+ println!("Alpha cutoff {} <= {:?}", search_result.0, (alpha, beta));
+ }
gradual_widening_counter += 1;
beta = alpha + window_size * 0.1;
alpha = search_result.0 - window_size * 2.0f32.powi(gradual_widening_counter);
continue;
}
if search_result.0 >= beta { // Beta-cutoff
- println!("Beta cutoff {:?} <= {}", (alpha, beta), search_result.0);
+ if print {
+ println!("Beta cutoff {:?} <= {}", (alpha, beta), search_result.0);
+ }
gradual_widening_counter += 1;
alpha = beta - window_size * 0.1;
beta = search_result.0 + window_size * 2.0f32.powi(gradual_widening_counter);
@@ -619,7 +629,7 @@ mod tests {
fn checkmate() {
let fen = String::from("2kr1b1r/pp1npppp/2p1bn2/7q/5B2/2NB1Q1P/PPP1N1P1/2KR3R w - - 0 1");
let mut board = Board::from_FEN(fen);
- let (score, pv) = board.iterative_deepening(8, Duration::from_secs(15));
+ let (score, pv) = board.iterative_deepening(8, Duration::from_secs(15), true);
assert_eq!(score, VALUE_WIN);
assert_eq!(pv, vec![
@@ -635,7 +645,7 @@ mod tests {
let mut board = Board::from_FEN(fen);
board.ply += 1; // TODO: remove me when FEN parsing includes side to move
- let (_, pv) = board.iterative_deepening(6, Duration::from_secs(60));
+ let (_, pv) = board.iterative_deepening(6, Duration::from_secs(60), true);
assert_eq!(
pv[0],
Move { source: Square::F5, target: Square::H4, kind: MoveKind::Quiet },
@@ -648,7 +658,7 @@ mod tests {
let fen = String::from("r1b1k1nr/p4pp1/1pp1p3/4n2p/1b1qP3/1B1P3N/PPPBQPPP/RN2K2R w KQkq - 7 10");
let mut board = Board::from_FEN(fen);
- let (_, pv) = board.iterative_deepening(5, Duration::from_secs(60));
+ let (_, pv) = board.iterative_deepening(5, Duration::from_secs(60), true);
assert_eq!(
pv[0],
Move { source: Square::C2, target: Square::C3, kind: MoveKind::Quiet },