diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-25 11:05:57 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-25 11:05:57 +0300 |
commit | 1265ee0ad113ec48865c1d44fd08bdbf53685bcc (patch) | |
tree | 6f12ae8fa6c4f73b8ce0bc0f3f7aacc1f5b68767 /src | |
parent | a905ddb6104849d561a2559182d3c09735ebf5ef (diff) | |
download | chessnost-1265ee0ad113ec48865c1d44fd08bdbf53685bcc.tar.gz |
feat: add aspiration windows to iterative_deepning
Diffstat (limited to 'src')
-rw-r--r-- | src/board/engine.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs index b6daacf..0a99def 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -1,4 +1,4 @@ -use std::{cmp::Ordering, time::{Instant, Duration}, f32::INFINITY}; +use std::{time::{Instant, Duration}, f32::INFINITY}; use crate::{bitboard::pop_count, board::*}; use super::ttable::{NodeType, TranspositionTableItem}; @@ -245,20 +245,38 @@ impl Board { let start = Instant::now(); let deadline = start + duration; let mut result = None; - let mut depth = 0; + let mut depth = 1; + let mut alpha = -INFINITY; + let mut beta = INFINITY; + let window_size = 0.5; loop { - let search_result = self.negamax_search(-INFINITY, INFINITY, depth, deadline); + let search_result = self.negamax_search(alpha, beta, depth, deadline); println!("Finished depth({}) {:?} [{:?} left]", depth, search_result, deadline - Instant::now()); + if search_result.1.len() > 0 { + depth += 1; + alpha = search_result.0 - window_size; + beta = search_result.0 + window_size; + } else if search_result.0 <= alpha { // Alpha-cutoff + println!("Alpha cutoff {} <= {:?}", search_result.0, (alpha, beta)); + alpha = search_result.0 - window_size; + } else if search_result.0 >= beta { // Beta-cutoff + println!("Beta cutoff {:?} <= {}", (alpha, beta), search_result.0); + beta = search_result.0 + window_size; + } 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); - depth += 1; + } } } |