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 
96  int timePerTc() const;
97 
102  int movesPerTc() const;
103 
105  int timeIncrement() const;
106 
113  int timePerMove() const;
114 
116  int timeLeft() const;
117 
122  int movesLeft() const;
123 
125  int plyLimit() const;
126 
128  qint64 nodeLimit() const;
129 
137  int expiryMargin() const;
138 
139 
144  void setInfinity(bool enabled = true);
145 
147  void setTimePerTc(int timePerTc);
148 
150  void setMovesPerTc(int movesPerTc);
151 
153  void setTimeIncrement(int increment);
154 
156  void setTimePerMove(int timePerMove);
157 
159  void setTimeLeft(int timeLeft);
160 
162  void setMovesLeft(int movesLeft);
163 
165  void setPlyLimit(int plies);
166 
168  void setNodeLimit(qint64 nodes);
169 
171  void setExpiryMargin(int expiryMargin);
172 
173 
175  void startTimer();
176 
184  void update(bool applyIncrement = true);
185 
187  int lastMoveTime() const;
188 
190  bool expired() const;
191 
199  int activeTimeLeft() const;
200 
202  void readSettings(QSettings* settings);
203 
205  void writeSettings(QSettings* settings);
206 
207  private:
208  int m_movesPerTc;
209  int m_timePerTc;
210  int m_timePerMove;
211  int m_increment;
212  int m_timeLeft;
213  int m_movesLeft;
214  int m_plyLimit;
215  qint64 m_nodeLimit;
216  int m_lastMoveTime;
217  int m_expiryMargin;
218  bool m_expired;
219  bool m_infinite;
220  QElapsedTimer m_time;
221 };
222 
223 #endif // TIMECONTROL_H
Time controls of a chess game.
Definition: timecontrol.h:35