Belofte version 2.1.8
A promising chess program using the UCI or Winboard interface
level.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: level.h
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#if !defined(LEVEL_H)
9#define LEVEL_H
10
11constexpr depth_t INFINITE_DEPTH = 50;
12constexpr depth_t DEFAULT_DEPTH = 3;
15constexpr auto MINIMAL_DEPTH_COMPLETED = 1;
16constexpr auto TIME_OVERFLOWMULTIPLYER = 2;
17
18constexpr auto TIME_UNDERFLOWMULTIPLYER = 2;
19// formula time-elapsed > multiplier * movetime / divider
20// 1,3 equals 33% 1,2 equals 50%, 2,3 equals 66%
21constexpr auto TIME_UNDERFLOWDEVIDER = 3;
22
23/// time lost in between UI go command and bestmove return
24/// @todo replace based on actual measurements
25constexpr auto TIME_LOSTINENGINE = 50;
26constexpr auto TIME_LASTMOVEMARGIN = 100;
27
28/** Implements clock
29 * n seconds per game - setGameTime(seconds * 1000)
30 * n seconds per game, increment inc seconds per move
31 * - setGameTime(seconds * 1000, inc * 1000)
32 * n seconds per move - setMoveTime(seconds * 1000)
33 * n seconds per x moves - setMoveTime(seconds * 1000, x)
34 * n seconds per x moves, increment inc seconds per move
35 * - setMoveTime(seconds * 1000, x, inc * 1000)
36 * infinite - setInfinite()
37 * mate search - setMateSearch(depth)
38 *
39 * restrict to depth x - setDepthCommand(depth)
40 * @todo restrict to n nodes - setNodes(nodes)
41 * @todo restrict to moves - setMoves(moves)
42 *
43 * start pondering - setPondering()
44 */
45
48
49class bLevel final {
50public:
51 bLevel();
52 ~bLevel();
53
54 bLevel(bLevel const&) = default;
55 bLevel& operator=(bLevel const&) = default;
56
57 // no move ctor or assignment defined
58 bLevel(bLevel&&) = delete;
59 bLevel& operator=(bLevel&&) = delete;
60
61 operator std::string() const;
62
63 void flagLevelChanged(); /// new level or new game
64
65 // specific levels
66 void setGameTime(int const msPerGame);
67 void setGameTime(int const msPerGame, int const msIncrementPerMove);
68 void setMoveTime(int const msPerMove);
69 void setMoveTime(int const msPerGame, int const nMoves);
70 void setMoveTime(int const msPerGame, int const nMoves, int const msIncrementPerMove);
71 void setInfinite();
72 void setMateSearch(depth_t const d);
73
74 // level modifiers, before start of search
75 void setMoves(std::string movelist);
76 void setNodes(int64_t n);
77 void setPondering();
78 void clearPondering();
79 bool isPondering() const;
80
81 // level info
82 LevelType getType() const;
83 void setSearchDepth(depth_t const d);
84 depth_t getSearchDepth() const;
85 void setQSDepth(depth_t const d) { m_nQSDepth = d; }
86 depth_t getQSDepth() const { return m_nQSDepth; }
87 void setMaxDepth(depth_t const d);
88 depth_t getMaxDepth() const;
89
90 // level search decisions
91 void setDepthCommand(depth_t const d);
92 bool searchDepthReached(depth_t const d) const;
93 bool qsDepthReached(depth_t const d) const;
94 bool stoppingSearch(long const nTimeElapsed) const;
95 bool stillTimeLeft(depth_t const d, long const nTimeElapsed) const;
96
97 // level update
98 void setRemainingTime(int const msPerGame);
99 void setMovePlayed();
100 void undoMovePlayed();
101
102private:
103 void recalibrateTime();
104 std::string prettyDepth(depth_t const d) const;
105 std::string prettyMoves(int const d) const;
106
107 LevelType m_oType;
108 depth_t m_nSearchDepth;
109 depth_t m_nQSDepth;
110 depth_t m_nMaxDepth;
111
112 int m_nTimeForMove = 0; /// indicative time for searching
113 int m_nTimeLeftForGame = 0; /// total time left for n moves or game
114 int m_nRemainingMovesForPeriod = 0; /// total time left for next time control
115
116 // aborting time control
117 int m_nMaxTimeForMove = 0; /// time when to abort search
118 int m_nEstAllowNextIterationTime = 0; /// indicative time for next iteration
119 int m_nAbsoluteAbortTime = 0; /// time after which an abort if forced
120
121 // level as set initially
122 bool m_levelchanged = true;
123 bool m_pondering = false;
124 int64_t m_nNodes = 0; /// maximum number of nodes allowed
125 int m_timeForGame = 0; /// total time per game set
126 int m_movesPerPeriod = 0; /// number of moves per period
127 int m_incrementPerMove = 0; /// number of milliseconds added each move
128};
129
130#endif // defined LEVEL_H
131
132// eof
int_fast8_t depth_t
Definition belofte.h:112
Definition level.h:49
depth_t getQSDepth() const
Definition level.h:86
bool searchDepthReached(depth_t const d) const
Definition level.cpp:306
void clearPondering()
Definition level.cpp:294
void flagLevelChanged()
Definition level.cpp:27
depth_t getSearchDepth() const
Definition level.cpp:279
bLevel & operator=(bLevel &&)=delete
void setGameTime(int const msPerGame)
new level or new game
Definition level.cpp:43
void setQSDepth(depth_t const d)
Definition level.h:85
void setInfinite()
Definition level.cpp:32
void setRemainingTime(int const msPerGame)
xboard issues time command to update available time
Definition level.cpp:157
void setMovePlayed()
Definition level.cpp:167
void setMoveTime(int const msPerMove)
Definition level.cpp:81
void setSearchDepth(depth_t const d)
Definition level.cpp:259
bLevel()
Definition level.cpp:12
bLevel & operator=(bLevel const &)=default
void setMateSearch(depth_t const d)
Definition level.cpp:144
void setMoves(std::string movelist)
void setNodes(int64_t n)
Definition level.cpp:269
bool isPondering() const
Definition level.cpp:299
~bLevel()
Definition level.cpp:21
bool qsDepthReached(depth_t const d) const
Definition level.cpp:311
LevelType getType() const
Definition level.cpp:274
bool stoppingSearch(long const nTimeElapsed) const
Stop search required ?
Definition level.cpp:321
void setPondering()
Definition level.cpp:289
depth_t getMaxDepth() const
Definition level.cpp:284
bLevel(bLevel const &)=default
void setMaxDepth(depth_t const d)
Definition level.cpp:264
bool stillTimeLeft(depth_t const d, long const nTimeElapsed) const
Do we still have time to do another iteration ?
Definition level.cpp:342
void setDepthCommand(depth_t const d)
Definition level.cpp:250
void undoMovePlayed()
used for recalibrating time in case for undo move in xboard moves per period
Definition level.cpp:179
bLevel(bLevel &&)=delete
constexpr auto TIME_OVERFLOWMULTIPLYER
Definition level.h:16
constexpr auto TIME_UNDERFLOWDEVIDER
Definition level.h:21
constexpr depth_t QS_DEPTHEXTENSION
Definition level.h:14
constexpr auto TIME_UNDERFLOWMULTIPLYER
Definition level.h:18
constexpr auto MINIMAL_DEPTH_COMPLETED
Definition level.h:15
constexpr auto TIME_LOSTINENGINE
time lost in between UI go command and bestmove return
Definition level.h:25
constexpr depth_t DEFAULT_DEPTH
Definition level.h:12
constexpr depth_t MAXDEPTH_MULTIPLYER
Definition level.h:13
constexpr depth_t INFINITE_DEPTH
Definition level.h:11
LevelType
Implements clock n seconds per game - setGameTime(seconds * 1000) n seconds per game,...
Definition level.h:46
@ FicherTimeControl
constexpr auto TIME_LASTMOVEMARGIN
Definition level.h:26