Rev 96 | Rev 169 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 96 | Rev 154 | ||
---|---|---|---|
Line 31... | Line 31... | ||
31 | namespace { |
31 | namespace { |
32 | 32 | ||
33 | enum TimeType { OptimumTime, MaxTime }; |
33 | enum TimeType { OptimumTime, MaxTime }; |
34 | 34 | ||
35 | const int MoveHorizon = 50; // Plan time management at most this many moves ahead |
35 | const int MoveHorizon = 50; // Plan time management at most this many moves ahead |
36 | const double MaxRatio = 7.09; |
36 | const double MaxRatio = 7.09; // When in trouble, we can step over reserved time with this ratio |
37 | const double StealRatio = 0.35; // However we must not steal time from remaining moves over this ratio |
37 | const double StealRatio = 0.35; // However we must not steal time from remaining moves over this ratio |
38 | 38 | ||
39 | 39 | ||
40 | // move_importance() is a skew-logistic function based on naive statistical |
40 | // move_importance() is a skew-logistic function based on naive statistical |
41 | // analysis of "how many games are still undecided after n half-moves". Game |
41 | // analysis of "how many games are still undecided after n half-moves". Game |
Line 50... | Line 50... | ||
50 | 50 | ||
51 | return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero |
51 | return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero |
52 | } |
52 | } |
53 | 53 | ||
54 | template<TimeType T> |
54 | template<TimeType T> |
55 | int remaining(int myTime, int movesToGo, int ply, int slowMover) |
55 | int remaining(int myTime, int movesToGo, int ply, int slowMover) { |
56 | { |
56 | |
57 | const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio); |
57 | const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio); |
58 | const double TStealRatio = (T == OptimumTime ? 0 : StealRatio); |
58 | const double TStealRatio = (T == OptimumTime ? 0 : StealRatio); |
59 | 59 | ||
60 | double moveImportance = (move_importance(ply) * slowMover) / 100; |
60 | double moveImportance = (move_importance(ply) * slowMover) / 100; |
61 | double otherMovesImportance = 0; |
61 | double otherMovesImportance = 0; |
Line 69... | Line 69... | ||
69 | return int(myTime * std::min(ratio1, ratio2)); // Intel C++ asks for an explicit cast |
69 | return int(myTime * std::min(ratio1, ratio2)); // Intel C++ asks for an explicit cast |
70 | } |
70 | } |
71 | 71 | ||
72 | } // namespace |
72 | } // namespace |
73 | 73 | ||
74 | 74 | ||
75 | /// init() is called at the beginning of the search and calculates the allowed |
75 | /// init() is called at the beginning of the search and calculates the allowed |
76 | /// thinking time out of the time control and current game ply. We support four |
76 | /// thinking time out of the time control and current game ply. We support four |
77 | /// different kinds of time controls, passed in 'limits': |
77 | /// different kinds of time controls, passed in 'limits': |
78 | /// |
78 | /// |
79 | /// inc == 0 && movestogo == 0 means: x basetime [sudden death!] |
79 | /// inc == 0 && movestogo == 0 means: x basetime [sudden death!] |
80 | /// inc == 0 && movestogo != 0 means: x moves in y minutes |
80 | /// inc == 0 && movestogo != 0 means: x moves in y minutes |
81 | /// inc > 0 && movestogo == 0 means: x basetime + z increment |
81 | /// inc > 0 && movestogo == 0 means: x basetime + z increment |
82 | /// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment |
82 | /// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment |
83 | 83 | ||
84 | void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) |
84 | void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) { |
85 | { |
85 | |
86 | int minThinkingTime = Options["Minimum Thinking Time"]; |
86 | int minThinkingTime = Options["Minimum Thinking Time"]; |
87 | int moveOverhead = Options["Move Overhead"]; |
87 | int moveOverhead = Options["Move Overhead"]; |
88 | int slowMover = Options["Slow Mover"]; |
88 | int slowMover = Options["Slow Mover"]; |
89 | int npmsec = Options["nodestime"]; |
89 | int npmsec = Options["nodestime"]; |
90 | 90 |