diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-27 16:12:01 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-27 16:12:01 +0300 |
commit | fb142238613f0a2e0a581807d41089ac63793694 (patch) | |
tree | 31325b346477ddae3042902e810910426f0d8bbf /src | |
parent | 0388a79799902e5640c28f43d29f1597a14b0f24 (diff) | |
download | chessnost-fb142238613f0a2e0a581807d41089ac63793694.tar.gz |
feat: add max depth to iterative deepening
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"), + } } } |