From fb142238613f0a2e0a581807d41089ac63793694 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 27 Jan 2023 16:12:01 +0300 Subject: feat: add max depth to iterative deepening --- src/board/engine.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/board') 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) { + pub fn iterative_deepening(&mut self, max_depth: u8, duration: Duration) -> (f32, Vec) { 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"), + } } } -- cgit v1.2.3