1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 09:39:36 +00:00

Reshuffle in timeman.cpp

Move template definitions before call site.

No functional change.
This commit is contained in:
Marco Costalba 2014-04-12 12:00:37 +02:00
parent 800ba28e83
commit 17cb7e7fa3
2 changed files with 20 additions and 37 deletions

View file

@ -27,7 +27,7 @@
namespace { namespace {
/// Constants enum TimeType { OptimumTime, MaxTime };
const int MoveHorizon = 50; // Plan time management at most this many moves ahead 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 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; const double skewfactor = 0.172;
/// move_importance() is a skew-logistic function based on naive statistical // move_importance() is a skew-logistic function based on naive statistical
/// analysis of "how many games are still undecided after n half-moves". Game // analysis of "how many games are still undecided after n half-moves". Game
/// is considered "undecided" as long as neither side has >275cp advantage. // is considered "undecided" as long as neither side has >275cp advantage.
/// Data was extracted from CCRL game database with some simple filtering criteria. // Data was extracted from CCRL game database with some simple filtering criteria.
double move_importance(int ply) { double move_importance(int ply) {
return pow((1 + exp((ply - xshift) / xscale)), -skewfactor) + DBL_MIN; // Ensure non-zero return pow((1 + exp((ply - xshift) / xscale)), -skewfactor) + DBL_MIN; // Ensure non-zero
} }
template<TimeType T>
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 double thisMoveImportance = (move_importance(currentPly) * slowMover) / 100;
double otherMovesImportance = 0;
enum TimeType { OptimumTime, MaxTime }; for (int i = 1; i < movesToGo; ++i)
otherMovesImportance += move_importance(currentPly + 2 * i);
template<TimeType> double ratio1 = (TMaxRatio * thisMoveImportance) / (TMaxRatio * thisMoveImportance + otherMovesImportance);
int remaining(int myTime, int movesToGo, int fullMoveNumber, int slowMover); double ratio2 = (thisMoveImportance + TStealRatio * otherMovesImportance) / (thisMoveImportance + otherMovesImportance);
}
return int(floor(myTime * std::min(ratio1, ratio2)));
}
void TimeManager::pv_instability(double bestMoveChanges) { } // namespace
unstablePvFactor = 1 + bestMoveChanges;
}
void TimeManager::init(const Search::LimitsType& limits, int currentPly, Color us) 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 // Make sure that maxSearchTime is not over absoluteMaxSearchTime
optimumSearchTime = std::min(optimumSearchTime, maximumSearchTime); optimumSearchTime = std::min(optimumSearchTime, maximumSearchTime);
} }
namespace {
template<TimeType T>
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)));
}
}

View file

@ -26,7 +26,7 @@
class TimeManager { class TimeManager {
public: public:
void init(const Search::LimitsType& limits, int currentPly, Color us); 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 available_time() const { return int(optimumSearchTime * unstablePvFactor * 0.71); }
int maximum_time() const { return maximumSearchTime; } int maximum_time() const { return maximumSearchTime; }