Cute Chess  0.1
chessplayer.h
1 /*
2  This file is part of Cute Chess.
3 
4  Cute Chess is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  Cute Chess is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef CHESSPLAYER_H
19 #define CHESSPLAYER_H
20 
21 #include <QObject>
22 #include <QString>
23 #include <QVector>
24 #include "board/result.h"
25 #include "board/move.h"
26 #include "timecontrol.h"
27 #include "moveevaluation.h"
28 class QTimer;
29 namespace Chess { class Board; }
30 
31 
37 class LIB_EXPORT ChessPlayer : public QObject
38 {
39  Q_OBJECT
40 
41  public:
43  enum State
44  {
47  Idle,
51  Disconnected
52  };
53 
55  ChessPlayer(QObject* parent = nullptr);
56  virtual ~ChessPlayer();
57 
65  virtual bool isReady() const;
66 
68  State state() const;
69 
81  void newGame(Chess::Side side,
82  ChessPlayer* opponent,
83  Chess::Board* board);
84 
91  virtual void endGame(const Chess::Result& result);
92 
94  const MoveEvaluation& evaluation() const;
95 
97  const TimeControl* timeControl() const;
98 
100  void setTimeControl(const TimeControl& timeControl);
101 
103  Chess::Side side() const;
104 
110  virtual void makeMove(const Chess::Move& move) = 0;
111 
113  virtual void makeBookMove(const Chess::Move& move);
114 
116  QString name() const;
117 
119  void setName(const QString& name);
120 
122  virtual bool supportsVariant(const QString& variant) const = 0;
123 
128  virtual void startPondering();
129 
131  virtual void clearPonderState();
132 
134  virtual bool isHuman() const = 0;
135 
143  bool areClaimsValidated() const;
145  void setClaimsValidated(bool validate);
146 
147  public slots:
156  virtual void go();
157 
159  virtual void quit();
160 
170  virtual void kill();
171 
172  signals:
174  void disconnected();
175 
177  void ready() const;
178 
184  void startedThinking(int timeLeft) const;
185 
192  void stoppedThinking() const;
193 
198  void thinking(const MoveEvaluation& eval) const;
199 
201  void moveMade(const Chess::Move& move) const;
202 
207  void resultClaim(const Chess::Result& result) const;
208 
210  void debugMessage(const QString& data) const;
211 
213  void nameChanged(const QString& name);
214 
215  protected slots:
222  virtual void onCrashed();
223 
228  virtual void onTimeout();
229 
230  protected:
232  Chess::Board* board();
233 
235  virtual void startGame() = 0;
236 
243  virtual void startThinking() = 0;
244 
251  virtual bool canPlayAfterTimeout() const;
252 
254  void claimResult(const Chess::Result& result);
260  void forfeit(Chess::Result::Type type,
261  const QString& description = QString());
262 
267  void emitMove(const Chess::Move& move);
268 
270  const ChessPlayer* opponent() const;
271 
273  void setState(State state);
274 
283 
284  private:
285  void startClock();
286 
287  QString m_name;
288  State m_state;
289  TimeControl m_timeControl;
290  QTimer* m_timer;
291  bool m_claimedResult;
292  bool m_validateClaims;
293  Chess::Side m_side;
294  Chess::Board* m_board;
295  ChessPlayer* m_opponent;
296 };
297 
298 #endif // CHESSPLAYER_H
MoveEvaluation m_eval
Definition: chessplayer.h:282
Time controls of a chess game.
Definition: timecontrol.h:34
A chess player, human or AI.
Definition: chessplayer.h:37
Evaluation data for a chess move.
Definition: moveevaluation.h:34
An internal chessboard class.
Definition: board.h:56
Finishing or cleaning up after a game.
Definition: chessplayer.h:50
Thinking of the next move.
Definition: chessplayer.h:49
State
Definition: chessplayer.h:43
Definition: boardscene.h:28
The side or color of a chess player.
Definition: side.h:34
Observing a game, or waiting for turn.
Definition: chessplayer.h:48
The result of a chess game.
Definition: result.h:33
Type
Definition: result.h:39
Not started or uninitialized.
Definition: chessplayer.h:45
A small and efficient chessmove class.
Definition: move.h:41
Starting or initializing.
Definition: chessplayer.h:46
Idle and ready to start a game.
Definition: chessplayer.h:47