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  void addTime(int bonus);
110 
112  Chess::Side side() const;
113 
119  virtual void makeMove(const Chess::Move& move) = 0;
120 
122  virtual void makeBookMove(const Chess::Move& move);
123 
125  QString name() const;
126 
128  void setName(const QString& name);
129 
131  virtual bool supportsVariant(const QString& variant) const = 0;
132 
137  virtual void startPondering();
138 
140  virtual void clearPonderState();
141 
143  virtual bool isHuman() const = 0;
144 
152  bool areClaimsValidated() const;
154  void setClaimsValidated(bool validate);
155 
160  void setCanPlayAfterTimeout(bool enable);
161 
162 
163  public slots:
172  virtual void go();
173 
175  virtual void quit();
176 
186  virtual void kill();
187 
188  signals:
190  void disconnected();
191 
193  void ready();
194 
200  void startedThinking(int timeLeft);
201 
208  void stoppedThinking();
209 
214  void thinking(const MoveEvaluation& eval);
215 
217  void moveMade(const Chess::Move& move);
218 
223  void resultClaim(const Chess::Result& result);
224 
226  void debugMessage(const QString& data);
227 
229  void nameChanged(const QString& name);
230 
231  protected slots:
238  virtual void onCrashed();
239 
244  virtual void onTimeout();
245 
246  protected:
248  Chess::Board* board();
249 
251  virtual void startGame() = 0;
252 
259  virtual void startThinking() = 0;
260 
265  virtual bool canPlayAfterTimeout() const;
266 
268  void claimResult(const Chess::Result& result);
274  void forfeit(Chess::Result::Type type,
275  const QString& description = QString());
276 
281  void emitMove(const Chess::Move& move);
282 
284  const ChessPlayer* opponent() const;
285 
287  void setState(State state);
288 
290  void setError(const QString& error);
291 
300 
301  private:
302  void startClock();
303 
304  QString m_name;
305  QString m_error;
306  State m_state;
307  TimeControl m_timeControl;
308  QTimer* m_timer;
309  bool m_claimedResult;
310  bool m_validateClaims;
311  bool m_canPlayAfterTimeout;
312  Chess::Side m_side;
313  Chess::Board* m_board;
314  ChessPlayer* m_opponent;
315 };
316 
317 #endif // CHESSPLAYER_H
MoveEvaluation m_eval
Definition: chessplayer.h:299
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