From f4f0b32d55defe93a79ec7afcce47d1d795879a8 Mon Sep 17 00:00:00 2001 From: Tierynn Byrnes Date: Tue, 6 Feb 2024 14:55:28 +1000 Subject: [PATCH] Refactor timeman.cpp Move optExtra, optConstant and maxConstant into lower scope. closes https://github.com/official-stockfish/Stockfish/pull/5052 No functional change --- AUTHORS | 1 + src/timeman.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/AUTHORS b/AUTHORS index 9b1faee7..40a38bd5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -216,6 +216,7 @@ Taras Vuk (TarasVuk) Thanar2 thaspel theo77186 +TierynnB Ting-Hsuan Huang (fffelix-huang) Tobias Steinmann Tomasz Sobczyk (Sopel97) diff --git a/src/timeman.cpp b/src/timeman.cpp index 121f8edb..72a447af 100644 --- a/src/timeman.cpp +++ b/src/timeman.cpp @@ -28,7 +28,6 @@ namespace Stockfish { - TimePoint TimeManagement::optimum() const { return optimumTime; } TimePoint TimeManagement::maximum() const { return maximumTime; } TimePoint TimeManagement::elapsed(size_t nodes) const { @@ -89,18 +88,19 @@ void TimeManagement::init(Search::LimitsType& limits, TimePoint timeLeft = std::max(TimePoint(1), limits.time[us] + limits.inc[us] * (mtg - 1) - moveOverhead * (2 + mtg)); - // Use extra time with larger increments - double optExtra = std::clamp(1.0 + 12.5 * limits.inc[us] / limits.time[us], 1.0, 1.11); - - // Calculate time constants based on current time left. - double optConstant = std::min(0.00334 + 0.0003 * std::log10(limits.time[us] / 1000.0), 0.0049); - double maxConstant = std::max(3.4 + 3.0 * std::log10(limits.time[us] / 1000.0), 2.76); - // x basetime (+ z increment) // If there is a healthy increment, timeLeft can exceed actual available // game time for the current move, so also cap to 20% of available game time. if (limits.movestogo == 0) { + // Use extra time with larger increments + double optExtra = std::clamp(1.0 + 12.5 * limits.inc[us] / limits.time[us], 1.0, 1.11); + + // Calculate time constants based on current time left. + double optConstant = + std::min(0.00334 + 0.0003 * std::log10(limits.time[us] / 1000.0), 0.0049); + double maxConstant = std::max(3.4 + 3.0 * std::log10(limits.time[us] / 1000.0), 2.76); + optScale = std::min(0.0120 + std::pow(ply + 3.1, 0.44) * optConstant, 0.21 * limits.time[us] / double(timeLeft)) * optExtra;