mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-20 09:06:45 +08:00
Mark all compile-time constants as constexpr.
To more clearly distinguish them from "const" local variables, this patch defines compile-time local constants as constexpr. This is consistent with the definition of PvNode as constexpr in search() and qsearch(). It also makes the code more robust, since the compiler will now check that those constants are indeed compile-time constants. We can go even one step further and define all the evaluation and search compile-time constants as constexpr. In generate_castling() I replaced "K" with "step", since K was incorrectly capitalised (in the Chess960 case). In timeman.cpp I had to make the non-local constants MaxRatio and StealRatio constepxr, since otherwise gcc would complain when calculating TMaxRatio and TStealRatio. (Strangely, I did not have to make Is64Bit constexpr even though it is used in ucioption.cpp in the calculation of constexpr MaxHashMB.) I have renamed PieceCount to pieceCount in material.h, since the values of the array are not compile-time constants. Some compile-time constants in tbprobe.cpp were overlooked. Sides and MaxFile are not compile-time constants, so were renamed to sides and maxFile. Non-functional change.
This commit is contained in:
committed by
Stéphane Nicolet
parent
350dff4464
commit
759b3c79cf
@@ -32,9 +32,9 @@ namespace {
|
||||
|
||||
enum TimeType { OptimumTime, MaxTime };
|
||||
|
||||
const int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
||||
const double MaxRatio = 7.3; // When in trouble, we can step over reserved time with this ratio
|
||||
const double StealRatio = 0.34; // However we must not steal time from remaining moves over this ratio
|
||||
constexpr int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
||||
constexpr double MaxRatio = 7.3; // When in trouble, we can step over reserved time with this ratio
|
||||
constexpr double StealRatio = 0.34; // However we must not steal time from remaining moves over this ratio
|
||||
|
||||
|
||||
// move_importance() is a skew-logistic function based on naive statistical
|
||||
@@ -44,9 +44,9 @@ namespace {
|
||||
|
||||
double move_importance(int ply) {
|
||||
|
||||
const double XScale = 6.85;
|
||||
const double XShift = 64.5;
|
||||
const double Skew = 0.171;
|
||||
constexpr double XScale = 6.85;
|
||||
constexpr double XShift = 64.5;
|
||||
constexpr double Skew = 0.171;
|
||||
|
||||
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
||||
}
|
||||
@@ -54,8 +54,8 @@ namespace {
|
||||
template<TimeType T>
|
||||
int remaining(int myTime, int movesToGo, int ply, int slowMover) {
|
||||
|
||||
const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
||||
const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
||||
constexpr double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
||||
constexpr double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
||||
|
||||
double moveImportance = (move_importance(ply) * slowMover) / 100;
|
||||
double otherMovesImportance = 0;
|
||||
@@ -106,12 +106,12 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
||||
startTime = limits.startTime;
|
||||
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);
|
||||
|
||||
const int MaxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
||||
const int maxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
||||
|
||||
// We calculate optimum time usage for different hypothetical "moves to go"-values
|
||||
// and choose the minimum of calculated search time values. Usually the greatest
|
||||
// hypMTG gives the minimum values.
|
||||
for (int hypMTG = 1; hypMTG <= MaxMTG; ++hypMTG)
|
||||
for (int hypMTG = 1; hypMTG <= maxMTG; ++hypMTG)
|
||||
{
|
||||
// Calculate thinking time for hypothetical "moves to go"-value
|
||||
int hypMyTime = limits.time[us]
|
||||
|
||||
Reference in New Issue
Block a user