diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/board/engine.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs index 985dfb7..18fb731 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -281,7 +281,7 @@ impl Board { alpha } - pub fn iterative_deepening(&mut self, duration: Duration) -> (f32, Vec<Move>) { + pub fn iterative_deepening(&mut self, max_depth: u8, duration: Duration) -> (f32, Vec<Move>) { let start = Instant::now(); let deadline = start + duration; let mut result = None; @@ -290,15 +290,12 @@ impl Board { let mut beta = INFINITY; let window_size = 0.25; - loop { + 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 Instant::now() > deadline { - match result { - Some(r) => return r, - None => panic!("Could not find a move in time"), - } + break; } if search_result.1.len() > 0 { depth += 1; @@ -320,6 +317,11 @@ impl Board { result = Some(search_result); } + + match result { + Some(r) => return r, + None => panic!("Could not find a move in time"), + } } } |