mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Reshuffle in timeman.cpp
Move template definitions before call site. No functional change.
This commit is contained in:
parent
800ba28e83
commit
17cb7e7fa3
2 changed files with 20 additions and 37 deletions
|
@ -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<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>
|
||||
int remaining(int myTime, int movesToGo, int fullMoveNumber, int slowMover);
|
||||
}
|
||||
double ratio1 = (TMaxRatio * thisMoveImportance) / (TMaxRatio * thisMoveImportance + otherMovesImportance);
|
||||
double ratio2 = (thisMoveImportance + TStealRatio * otherMovesImportance) / (thisMoveImportance + otherMovesImportance);
|
||||
|
||||
return int(floor(myTime * std::min(ratio1, ratio2)));
|
||||
}
|
||||
|
||||
void TimeManager::pv_instability(double bestMoveChanges) {
|
||||
|
||||
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<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)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue