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>
25class QSettings;
26
35class LIB_EXPORT TimeControl
36{
37 Q_DECLARE_TR_FUNCTIONS(TimeControl)
38
39 public:
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
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
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
void setExpiryMargin(int expiryMargin)
Definition timecontrol.cpp:314
void setTimePerMove(int timePerMove)
Definition timecontrol.cpp:285
void setPlyLimit(int plies)
Definition timecontrol.cpp:302
void setTimeLeft(int timeLeft)
Definition timecontrol.cpp:291
int expiryMargin() const
Definition timecontrol.cpp:257
TimeControl()
Definition timecontrol.cpp:45
int timeIncrement() const
Definition timecontrol.cpp:227
void setNodeLimit(qint64 nodes)
Definition timecontrol.cpp:308
void setTimeIncrement(int increment)
Definition timecontrol.cpp:279
bool expired() const
Definition timecontrol.cpp:367
QString toVerboseString() const
Definition timecontrol.cpp:165
int plyLimit() const
Definition timecontrol.cpp:247
bool isInfinite() const
Definition timecontrol.cpp:212
void setMovesPerTc(int movesPerTc)
Definition timecontrol.cpp:273
void setInfinity(bool enabled=true)
Definition timecontrol.cpp:262
int movesPerTc() const
Definition timecontrol.cpp:222
bool isValid() const
Definition timecontrol.cpp:130
int lastMoveTime() const
Definition timecontrol.cpp:362
int movesLeft() const
Definition timecontrol.cpp:242
int timePerMove() const
Definition timecontrol.cpp:232
void update(bool applyIncrement=true)
Definition timecontrol.cpp:325
void writeSettings(QSettings *settings)
Definition timecontrol.cpp:395
qint64 nodeLimit() const
Definition timecontrol.cpp:252
void readSettings(QSettings *settings)
Definition timecontrol.cpp:379
void startTimer()
Definition timecontrol.cpp:320
void initialize()
Definition timecontrol.cpp:198
void setMovesLeft(int movesLeft)
Definition timecontrol.cpp:296
int timePerTc() const
Definition timecontrol.cpp:217
int timeLeft() const
Definition timecontrol.cpp:237
bool operator==(const TimeControl &other) const
Definition timecontrol.cpp:117
QString toString() const
Definition timecontrol.cpp:144
void setTimePerTc(int timePerTc)
Definition timecontrol.cpp:267
int activeTimeLeft() const
Definition timecontrol.cpp:372