diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-26 17:11:35 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-26 17:11:35 +0300 |
commit | 5645b7acf228d9f8127ad834023afc727ccb4f88 (patch) | |
tree | f4338692b939ff47a884c35bd5873d439a29a062 /src/board | |
parent | 5237987cf62f8e031a979ba7945f11c710c28c57 (diff) | |
download | chessnost-5645b7acf228d9f8127ad834023afc727ccb4f88.tar.gz |
fix: do not write result after window cutoff
Diffstat (limited to 'src/board')
-rw-r--r-- | src/board/engine.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs index 1d01e06..a4b72eb 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -271,6 +271,13 @@ impl Board { 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"), + } + } + if search_result.1.len() > 0 { depth += 1; alpha = search_result.0 - window_size; @@ -278,22 +285,16 @@ impl Board { } else if search_result.0 <= alpha { // Alpha-cutoff println!("Alpha cutoff {} <= {:?}", search_result.0, (alpha, beta)); alpha = search_result.0 - window_size; + continue; } else if search_result.0 >= beta { // Beta-cutoff println!("Beta cutoff {:?} <= {}", (alpha, beta), search_result.0); beta = search_result.0 + window_size; + continue; } 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); - } } } |