Cute Chess  0.1
timecontrol.h
1 /*
2  This file is part of Cute Chess.
3  Copyright (C) 2008-2018 Cute Chess authors
4 
5  Cute Chess is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Cute Chess is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef TIMECONTROL_H
20 #define TIMECONTROL_H
21 
22 #include <QElapsedTimer>
23 #include <QString>
24 #include <QCoreApplication>
25 class QSettings;
26 
35 class LIB_EXPORT TimeControl
36 {
37  Q_DECLARE_TR_FUNCTIONS(TimeControl)
38 
39  public:
41  TimeControl();
42 
67  TimeControl(const QString& str);
68 
75  bool operator==(const TimeControl& other) const;
76 
78  bool isValid() const;
79 
81  QString toString() const;
82 
84  QString toVerboseString() const;
85 
87  void initialize();
88 
90  bool isInfinite() const;
91 
93  bool isHourglass() const;
94 
99  int timePerTc() const;
100 
105  int movesPerTc() const;
106 
108  int timeIncrement() const;
109 
116  int timePerMove() const;
117 
119  int timeLeft() const;
120 
125  int movesLeft() const;
126 
128  int plyLimit() const;
129 
131  qint64 nodeLimit() const;
132 
140  int expiryMargin() const;
141 
142 
147  void setInfinity(bool enabled = true);
148 
153  void setHourglass(bool enabled = false);
154 
156  void setTimePerTc(int timePerTc);
157 
159  void setMovesPerTc(int movesPerTc);
160 
162  void setTimeIncrement(int increment);
163 
165  void setTimePerMove(int timePerMove);
166 
168  void setTimeLeft(int timeLeft);
169 
171  void setMovesLeft(int movesLeft);
172 
174  void setPlyLimit(int plies);
175 
177  void setNodeLimit(qint64 nodes);
178 
180  void setExpiryMargin(int expiryMargin);
181 
182 
184  void startTimer();
185 
193  void update(bool applyIncrement = true);
194 
196  int lastMoveTime() const;
197 
199  bool expired() const;
200 
208  int activeTimeLeft() const;
209 
211  void readSettings(QSettings* settings);
212 
214  void writeSettings(QSettings* settings);
215 
216  private:
217  int m_movesPerTc;
218  int m_timePerTc;
219  int m_timePerMove;
220  int m_increment;
221  int m_timeLeft;
222  int m_movesLeft;
223  int m_plyLimit;
224  qint64 m_nodeLimit;
225  int m_lastMoveTime;
226  int m_expiryMargin;
227  bool m_expired;
228  bool m_infinite;
229  bool m_hourglass;
230  QElapsedTimer m_time;
231 };
232 
233 #endif // TIMECONTROL_H
Time controls of a chess game.
Definition: timecontrol.h:35