Cute Chess  0.1
chessplayer.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 CHESSPLAYER_H
20 #define CHESSPLAYER_H
21 
22 #include <QObject>
23 #include <QString>
24 #include <QVector>
25 #include "board/result.h"
26 #include "board/move.h"
27 #include "timecontrol.h"
28 #include "moveevaluation.h"
29 class QTimer;
30 namespace Chess { class Board; }
31 
32 
38 class LIB_EXPORT ChessPlayer : public QObject
39 {
40  Q_OBJECT
41 
42  public:
44  enum State
45  {
48  Idle,
52  Disconnected
53  };
54 
56  ChessPlayer(QObject* parent = nullptr);
57  virtual ~ChessPlayer();
58 
66  virtual bool isReady() const;
67 
69  State state() const;
70 
72  bool hasError() const;
74  QString errorString() const;
75 
87  void newGame(Chess::Side side,
88  ChessPlayer* opponent,
89  Chess::Board* board);
90 
97  virtual void endGame(const Chess::Result& result);
98 
100  const MoveEvaluation& evaluation() const;
101 
103  const TimeControl* timeControl() const;
104 
106  void setTimeControl(const TimeControl& timeControl);
107 
109  Chess::Side side() const;
110 
116  virtual void makeMove(const Chess::Move& move) = 0;
117 
119  virtual void makeBookMove(const Chess::Move& move);
120 
122  QString name() const;
123 
125  void setName(const QString& name);
126 
128  virtual bool supportsVariant(const QString& variant) const = 0;
129 
134  virtual void startPondering();
135 
137  virtual void clearPonderState();
138 
140  virtual bool isHuman() const = 0;
141 
149  bool areClaimsValidated() const;
151  void setClaimsValidated(bool validate);
152 
157  void setCanPlayAfterTimeout(bool enable);
158 
159 
160  public slots:
169  virtual void go();
170 
172  virtual void quit();
173 
183  virtual void kill();
184 
185  signals:
187  void disconnected();
188 
190  void ready();
191 
197  void startedThinking(int timeLeft);
198 
205  void stoppedThinking();
206 
211  void thinking(const MoveEvaluation& eval);
212 
214  void moveMade(const Chess::Move& move);
215 
220  void resultClaim(const Chess::Result& result);
221 
223  void debugMessage(const QString& data);
224 
226  void nameChanged(const QString& name);
227 
228  protected slots:
235  virtual void onCrashed();
236 
241  virtual void onTimeout();
242 
243  protected:
245  Chess::Board* board();
246 
248  virtual void startGame() = 0;
249 
256  virtual void startThinking() = 0;
257 
262  virtual bool canPlayAfterTimeout() const;
263 
265  void claimResult(const Chess::Result& result);
271  void forfeit(Chess::Result::Type type,
272  const QString& description = QString());
273 
278  void emitMove(const Chess::Move& move);
279 
281  const ChessPlayer* opponent() const;
282 
284  void setState(State state);
285 
287  void setError(const QString& error);
288 
297 
298  private:
299  void startClock();
300 
301  QString m_name;
302  QString m_error;
303  State m_state;
304  TimeControl m_timeControl;
305  QTimer* m_timer;
306  bool m_claimedResult;
307  bool m_validateClaims;
308  bool m_canPlayAfterTimeout;
309  Chess::Side m_side;
310  Chess::Board* m_board;
311  ChessPlayer* m_opponent;
312 };
313 
314 #endif // CHESSPLAYER_H
MoveEvaluation m_eval
Definition: chessplayer.h:296
Time controls of a chess game.
Definition: timecontrol.h:35
A chess player, human or AI.
Definition: chessplayer.h:38
Evaluation data for a chess move.
Definition: moveevaluation.h:35
An internal chessboard class.
Definition: board.h:57
Finishing or cleaning up after a game.
Definition: chessplayer.h:51
Thinking of the next move.
Definition: chessplayer.h:50
State
Definition: chessplayer.h:44
Definition: boardscene.h:29
The side or color of a chess player.
Definition: side.h:35
Observing a game, or waiting for turn.
Definition: chessplayer.h:49
The result of a chess game.
Definition: result.h:34
Type
Definition: result.h:40
Not started or uninitialized.
Definition: chessplayer.h:46
A small and efficient chessmove class.
Definition: move.h:42
Starting or initializing.
Definition: chessplayer.h:47
Idle and ready to start a game.
Definition: chessplayer.h:48