From 17cb7e7fa3cbc707be1df6793de1928fcb0c6219 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 12 Apr 2014 12:00:37 +0200 Subject: [PATCH] Reshuffle in timeman.cpp Move template definitions before call site. No functional change. --- src/timeman.cpp | 55 +++++++++++++++++-------------------------------- src/timeman.h | 2 +- 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/src/timeman.cpp b/src/timeman.cpp index 051d9726..2092b729 100644 --- a/src/timeman.cpp +++ b/src/timeman.cpp @@ -27,7 +27,7 @@ namespace { - /// Constants + enum TimeType { OptimumTime, MaxTime }; const int MoveHorizon = 50; // Plan time management at most this many moves ahead const double MaxRatio = 7.0; // When in trouble, we can step over reserved time with this ratio @@ -38,30 +38,35 @@ namespace { const double skewfactor = 0.172; - /// move_importance() is a skew-logistic function based on naive statistical - /// analysis of "how many games are still undecided after n half-moves". Game - /// is considered "undecided" as long as neither side has >275cp advantage. - /// Data was extracted from CCRL game database with some simple filtering criteria. + // move_importance() is a skew-logistic function based on naive statistical + // analysis of "how many games are still undecided after n half-moves". Game + // is considered "undecided" as long as neither side has >275cp advantage. + // Data was extracted from CCRL game database with some simple filtering criteria. double move_importance(int ply) { return pow((1 + exp((ply - xshift) / xscale)), -skewfactor) + DBL_MIN; // Ensure non-zero } + template + int remaining(int myTime, int movesToGo, int currentPly, int slowMover) + { + const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio); + const double TStealRatio = (T == OptimumTime ? 0 : StealRatio); - /// Function Prototypes - - enum TimeType { OptimumTime, MaxTime }; + double thisMoveImportance = (move_importance(currentPly) * slowMover) / 100; + double otherMovesImportance = 0; - template - int remaining(int myTime, int movesToGo, int fullMoveNumber, int slowMover); -} + for (int i = 1; i < movesToGo; ++i) + otherMovesImportance += move_importance(currentPly + 2 * i); + double ratio1 = (TMaxRatio * thisMoveImportance) / (TMaxRatio * thisMoveImportance + otherMovesImportance); + double ratio2 = (thisMoveImportance + TStealRatio * otherMovesImportance) / (thisMoveImportance + otherMovesImportance); -void TimeManager::pv_instability(double bestMoveChanges) { + return int(floor(myTime * std::min(ratio1, ratio2))); + } - unstablePvFactor = 1 + bestMoveChanges; -} +} // namespace void TimeManager::init(const Search::LimitsType& limits, int currentPly, Color us) @@ -119,25 +124,3 @@ void TimeManager::init(const Search::LimitsType& limits, int currentPly, Color u // Make sure that maxSearchTime is not over absoluteMaxSearchTime optimumSearchTime = std::min(optimumSearchTime, maximumSearchTime); } - - -namespace { - - template - int remaining(int myTime, int movesToGo, int currentPly, int slowMover) - { - const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio); - const double TStealRatio = (T == OptimumTime ? 0 : StealRatio); - - double thisMoveImportance = (move_importance(currentPly) * slowMover) / 100; - double otherMovesImportance = 0; - - for (int i = 1; i < movesToGo; ++i) - otherMovesImportance += move_importance(currentPly + 2 * i); - - double ratio1 = (TMaxRatio * thisMoveImportance) / (TMaxRatio * thisMoveImportance + otherMovesImportance); - double ratio2 = (thisMoveImportance + TStealRatio * otherMovesImportance) / (thisMoveImportance + otherMovesImportance); - - return int(floor(myTime * std::min(ratio1, ratio2))); - } -} diff --git a/src/timeman.h b/src/timeman.h index 90bd1867..a15551af 100644 --- a/src/timeman.h +++ b/src/timeman.h @@ -26,7 +26,7 @@ class TimeManager { public: void init(const Search::LimitsType& limits, int currentPly, Color us); - void pv_instability(double bestMoveChanges); + void pv_instability(double bestMoveChanges) { unstablePvFactor = 1 + bestMoveChanges; } int available_time() const { return int(optimumSearchTime * unstablePvFactor * 0.71); } int maximum_time() const { return maximumSearchTime; } -- 2.39.2