29 m_levelchanged =
true;
47 m_timeForGame = msPerGame;
48 m_levelchanged =
false;
52 m_incrementPerMove = 0;
53 m_nTimeLeftForGame = msPerGame;
66 m_timeForGame = msPerGame;
67 m_levelchanged =
false;
70 m_incrementPerMove = msIncrementPerMove;
72 m_nTimeLeftForGame = msPerGame;
85 m_levelchanged =
false;
89 m_nTimeForMove = msPerMove;
97 m_nMaxTimeForMove = m_nTimeForMove;
106 if (m_levelchanged) {
107 m_timeForGame = msPerGame;
108 m_movesPerPeriod = nMoves;
109 m_levelchanged =
false;
112 m_incrementPerMove = 0;
113 m_nRemainingMovesForPeriod = nMoves;
114 m_nTimeLeftForGame = msPerGame;
124 int const nMoves,
int const msIncrementPerMove)
127 if (m_levelchanged) {
128 m_movesPerPeriod = nMoves;
129 m_timeForGame = msPerGame;
130 m_levelchanged =
false;
132 m_incrementPerMove = msIncrementPerMove;
134 m_nRemainingMovesForPeriod = nMoves;
135 m_nTimeLeftForGame = msPerGame;
159 m_nTimeLeftForGame = msPerGame;
161 int nInc = m_incrementPerMove;
162 m_incrementPerMove = 0;
164 m_incrementPerMove = nInc;
169 m_nRemainingMovesForPeriod--;
170 if (m_nRemainingMovesForPeriod < 1)
171 m_nRemainingMovesForPeriod = m_movesPerPeriod;
181 m_nRemainingMovesForPeriod++;
186void bLevel::recalibrateTime()
191 m_nTimeForMove = m_nTimeLeftForGame / 20;
192 m_nMaxTimeForMove = m_nTimeLeftForGame / 15;
196 if (!m_nRemainingMovesForPeriod) m_nRemainingMovesForPeriod = 1;
197 if (m_nRemainingMovesForPeriod <= 4) {
198 m_nTimeForMove = m_nTimeLeftForGame / m_nRemainingMovesForPeriod;
199 m_nMaxTimeForMove = m_nTimeForMove;
201 m_nTimeForMove = (m_nTimeLeftForGame / m_nRemainingMovesForPeriod) + m_incrementPerMove;
202 m_nMaxTimeForMove = (m_nTimeLeftForGame / (m_nRemainingMovesForPeriod - 3)) + m_incrementPerMove;
205 if (m_nTimeLeftForGame > m_incrementPerMove * 5) {
206 m_nTimeForMove = (m_nTimeLeftForGame / 20) + m_incrementPerMove;
207 m_nMaxTimeForMove = (m_nTimeLeftForGame / 10) + m_incrementPerMove;
209 m_nTimeForMove = m_nTimeLeftForGame / 20;
210 m_nMaxTimeForMove = m_nTimeLeftForGame / 10;
215 if (!m_nRemainingMovesForPeriod) m_nRemainingMovesForPeriod = 1;
216 if (m_nRemainingMovesForPeriod > 10) {
217 m_nTimeForMove = m_nTimeLeftForGame / m_nRemainingMovesForPeriod;
218 m_nMaxTimeForMove = m_nTimeLeftForGame / (m_nRemainingMovesForPeriod - 5);
220 m_nTimeForMove = m_nTimeLeftForGame / m_nRemainingMovesForPeriod;
221 m_nMaxTimeForMove = m_nTimeForMove;
230 m_nTimeForMove = (m_nTimeForMove + m_nMaxTimeForMove) / 2;
232 if (m_nTimeForMove > m_nMaxTimeForMove)
233 m_nTimeForMove = m_nMaxTimeForMove;
239 if (m_nRemainingMovesForPeriod < 1) {
281 return m_nSearchDepth;
308 return d >= m_nSearchDepth;
313 return d >= m_nQSDepth;
328 if (nTimeElapsed > m_nTimeForMove)
return true;
329 if (nTimeElapsed > m_nMaxTimeForMove)
return true;
330 if (nTimeElapsed > m_nAbsoluteAbortTime)
return true;
349 if (nTimeElapsed > m_nEstAllowNextIterationTime)
return false;
357std::string bLevel::prettyDepth(
depth_t const d)
const
360 if (d)
return belofte::to_string(
static_cast<int>(d));
364std::string bLevel::prettyMoves(
int const d)
const
366 if (d)
return belofte::to_string(d);
372bLevel::operator std::string()
const
376 s =
"SD " + belofte::prettyTime(m_timeForGame)
377 +
" Left for game = " + belofte::prettyTime(m_nTimeLeftForGame)
378 +
" for move est/max "
379 + belofte::prettyTime(m_nTimeForMove)
380 +
"/" + belofte::prettyTime(m_nAbsoluteAbortTime);
382 s =
"FC " + belofte::prettyTime(m_timeForGame)
383 +
"/" + prettyMoves(m_movesPerPeriod)
384 +
"+" + belofte::prettyTime(m_incrementPerMove)
385 +
" Left for #" + prettyMoves(m_nRemainingMovesForPeriod)
386 +
" moves = " + belofte::prettyTime(m_nTimeLeftForGame)
387 +
" for move est/max "
388 + belofte::prettyTime(m_nTimeForMove)
389 +
"/" + belofte::prettyTime(m_nAbsoluteAbortTime);
391 s =
"FC " + belofte::prettyTime(m_timeForGame)
392 +
"+" + belofte::prettyTime(m_incrementPerMove)
393 +
" Left for game = " + belofte::prettyTime(m_nTimeLeftForGame)
394 +
" for move est/max "
395 + belofte::prettyTime(m_nTimeForMove)
396 +
"/" + belofte::prettyTime(m_nAbsoluteAbortTime);
398 s =
"TC " + belofte::prettyTime(m_timeForGame)
399 +
"/" + prettyMoves(m_movesPerPeriod)
400 +
" Left for #" + prettyMoves(m_nRemainingMovesForPeriod)
401 +
" moves = " + belofte::prettyTime(m_nTimeLeftForGame)
402 +
" for move est/max "
403 + belofte::prettyTime(m_nTimeForMove)
404 +
"/" + belofte::prettyTime(m_nAbsoluteAbortTime);
406 s =
"ST " + belofte::prettyTime(m_nTimeLeftForGame)
407 +
" Time left for move = " + belofte::prettyTime(m_nTimeForMove);
409 s =
"Search mate in " + belofte::to_string(
static_cast<int>(m_nSearchDepth));
415 s =
"To be implemented";
420 s +=
", depth limited to " + belofte::to_string(
static_cast<int>(m_nMaxDepth));
This is the main include file, needs to be included before any other include.
bool searchDepthReached(depth_t const d) const
depth_t getSearchDepth() const
void setGameTime(int const msPerGame)
new level or new game
void setRemainingTime(int const msPerGame)
xboard issues time command to update available time
void setMoveTime(int const msPerMove)
void setSearchDepth(depth_t const d)
void setMateSearch(depth_t const d)
bool qsDepthReached(depth_t const d) const
LevelType getType() const
bool stoppingSearch(long const nTimeElapsed) const
Stop search required ?
depth_t getMaxDepth() const
void setMaxDepth(depth_t const d)
bool stillTimeLeft(depth_t const d, long const nTimeElapsed) const
Do we still have time to do another iteration ?
void setDepthCommand(depth_t const d)
void undoMovePlayed()
used for recalibrating time in case for undo move in xboard moves per period
constexpr auto TIME_OVERFLOWMULTIPLYER
constexpr auto TIME_UNDERFLOWDEVIDER
constexpr depth_t QS_DEPTHEXTENSION
constexpr auto TIME_UNDERFLOWMULTIPLYER
constexpr auto MINIMAL_DEPTH_COMPLETED
constexpr auto TIME_LOSTINENGINE
time lost in between UI go command and bestmove return
constexpr depth_t DEFAULT_DEPTH
constexpr depth_t MAXDEPTH_MULTIPLYER
constexpr depth_t INFINITE_DEPTH
LevelType
Implements clock n seconds per game - setGameTime(seconds * 1000) n seconds per game,...
constexpr auto TIME_LASTMOVEMARGIN