diff --git a/src/bm/bm_runner/ab_runner.rs b/src/bm/bm_runner/ab_runner.rs index e2a07262..5b923bab 100644 --- a/src/bm/bm_runner/ab_runner.rs +++ b/src/bm/bm_runner/ab_runner.rs @@ -361,6 +361,15 @@ impl AbRunner { } local_context.window.set(score); local_context.eval = score; + + shared_context.time_manager.deepen( + thread, + depth, + nodes, + local_context.eval, + best_move.unwrap_or(make_move.unwrap()), + search_start.elapsed(), + ); if (score > alpha && score < beta) || score.is_mate() { best_move = make_move; eval = Some(score); @@ -406,15 +415,6 @@ impl AbRunner { } } depth += 1; - - shared_context.time_manager.deepen( - thread, - depth, - nodes, - local_context.eval, - best_move.unwrap(), - search_start.elapsed(), - ); } if let Some(evaluation) = eval { debugger.complete(); diff --git a/src/bm/bm_runner/time.rs b/src/bm/bm_runner/time.rs index c6c70fc9..94451ba9 100644 --- a/src/bm/bm_runner/time.rs +++ b/src/bm/bm_runner/time.rs @@ -6,6 +6,7 @@ use std::sync::Mutex; use std::time::{Duration, Instant}; const EXPECTED_MOVES: u32 = 40; +const MOVE_CHANGE_MARGIN: u32 = 9; const TIME_DEFAULT: Duration = Duration::from_secs(0); const INC_DEFAULT: Duration = Duration::from_secs(0); @@ -42,6 +43,8 @@ pub struct TimeManager { max_duration: AtomicU32, normal_duration: AtomicU32, target_duration: AtomicU32, + + same_move_depth: AtomicU32, prev_move: Mutex>, board: Mutex, @@ -62,6 +65,7 @@ impl TimeManager { max_duration: AtomicU32::new(0), normal_duration: AtomicU32::new(0), target_duration: AtomicU32::new(0), + same_move_depth: AtomicU32::new(0), prev_move: Mutex::new(None), board: Mutex::new(Board::default()), abort_now: AtomicBool::new(false), @@ -100,22 +104,24 @@ impl TimeManager { } *prev_move = Some(current_move); - let move_factor = if move_changed { 3.0 } else { -1.0 }; + let move_change_depth = if move_changed { + self.same_move_depth.store(0, Ordering::SeqCst); + 0 + } else { + self.same_move_depth.fetch_add(1, Ordering::SeqCst) + }; - let mut eval_diff = (current_eval as f32 - last_eval as f32) / 25.0; + let eval_diff = (current_eval as f32 - last_eval as f32).abs() / 25.0; - if eval_diff < 0.0 { - eval_diff *= 2.0; - }; - eval_diff = eval_diff.max(-4.0).min(2.0).abs(); + time *= 1.05_f32.powf(eval_diff.min(1.0)); - time *= 1.05_f32.powf(eval_diff + move_factor); + let move_change_factor = 1.05_f32.powf(MOVE_CHANGE_MARGIN as f32 - move_change_depth as f32).max(0.4); let time = time.min(self.max_duration.load(Ordering::SeqCst) as f32 * 1000.0); self.normal_duration .store((time * 0.001) as u32, Ordering::SeqCst); self.target_duration - .store((time * 0.001) as u32, Ordering::SeqCst); + .store((time * 0.001 * move_change_factor) as u32, Ordering::SeqCst); self.last_eval.store(current_eval, Ordering::SeqCst); } @@ -218,6 +224,7 @@ impl TimeManager { pub fn clear(&self) { *self.prev_move.lock().unwrap() = None; + self.same_move_depth.store(0, Ordering::SeqCst); self.abort_now.store(false, Ordering::SeqCst); self.no_manage.store(false, Ordering::SeqCst); let expected_moves = self.expected_moves.load(Ordering::SeqCst);