X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Ftimeman.cpp;h=7a5db255142e91b6d696f516ccd58e4945e948d9;hp=c3f66d6cadbfe10f70f93ef3f4ce7148d066c625;hb=27efc5ac996ffc679395317c8bbb16aca996296c;hpb=2416242c966bfccd5a779e037dfe0d2d4cd8f3fe diff --git a/src/timeman.cpp b/src/timeman.cpp index c3f66d6c..7a5db255 100644 --- a/src/timeman.cpp +++ b/src/timeman.cpp @@ -1,7 +1,7 @@ /* Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008-2014 Marco Costalba, Joona Kiiski, Tord Romstad + Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,6 +25,8 @@ #include "timeman.h" #include "uci.h" +TimeManagement Time; // Our global time management object + namespace { enum TimeType { OptimumTime, MaxTime }; @@ -63,7 +65,7 @@ namespace { double ratio1 = (TMaxRatio * moveImportance) / (TMaxRatio * moveImportance + otherMovesImportance); double ratio2 = (moveImportance + TStealRatio * otherMovesImportance) / (moveImportance + otherMovesImportance); - return myTime * std::min(ratio1, ratio2); + return int(myTime * std::min(ratio1, ratio2)); // Intel C++ asks an explicit cast } } // namespace @@ -78,15 +80,31 @@ namespace { /// inc > 0 && movestogo == 0 means: x basetime + z increment /// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment -void TimeManager::init(const Search::LimitsType& limits, Color us, int ply) +void TimeManagement::init(Search::LimitsType& limits, Color us, int ply, TimePoint now) { int minThinkingTime = Options["Minimum Thinking Time"]; int moveOverhead = Options["Move Overhead"]; int slowMover = Options["Slow Mover"]; + int npmsec = Options["nodestime"]; + + // If we have to play in 'nodes as time' mode, then convert from time + // to nodes, and use resulting values in time management formulas. + // WARNING: Given npms (nodes per millisecond) must be much lower then + // real engine speed to avoid time losses. + if (npmsec) + { + if (!availableNodes) // Only once at game start + availableNodes = npmsec * limits.time[us]; // Time is in msec + + // Convert from millisecs to nodes + limits.time[us] = (int)availableNodes; + limits.inc[us] *= npmsec; + limits.npmsec = npmsec; + } - // Initialize unstablePvFactor to 1 and search times to maximum values + start = now; unstablePvFactor = 1; - optimumSearchTime = maximumSearchTime = std::max(limits.time[us], minThinkingTime); + optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime); const int MaxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon; @@ -105,12 +123,12 @@ void TimeManager::init(const Search::LimitsType& limits, Color us, int ply) int t1 = minThinkingTime + remaining(hypMyTime, hypMTG, ply, slowMover); int t2 = minThinkingTime + remaining(hypMyTime, hypMTG, ply, slowMover); - optimumSearchTime = std::min(t1, optimumSearchTime); - maximumSearchTime = std::min(t2, maximumSearchTime); + optimumTime = std::min(t1, optimumTime); + maximumTime = std::min(t2, maximumTime); } if (Options["Ponder"]) - optimumSearchTime += optimumSearchTime / 4; + optimumTime += optimumTime / 4; - optimumSearchTime = std::min(optimumSearchTime, maximumSearchTime); + optimumTime = std::min(optimumTime, maximumTime); }