From 1265ee0ad113ec48865c1d44fd08bdbf53685bcc Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 25 Jan 2023 11:05:57 +0300 Subject: feat: add aspiration windows to iterative_deepning --- src/board/engine.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/board/engine.rs') 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; + } } } -- cgit v1.2.3