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"
29class QTimer;
30namespace Chess { class Board; }
31
32
38class LIB_EXPORT ChessPlayer : public QObject
39{
40 Q_OBJECT
41
42 public:
44 enum State
45 {
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:
191
193 void ready();
194
200 void startedThinking(int timeLeft);
201
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
A chess player, human or AI.
Definition: chessplayer.h:39
State
Definition: chessplayer.h:45
@ Starting
Starting or initializing.
Definition: chessplayer.h:47
@ Observing
Observing a game, or waiting for turn.
Definition: chessplayer.h:49
@ Idle
Idle and ready to start a game.
Definition: chessplayer.h:48
@ Thinking
Thinking of the next move.
Definition: chessplayer.h:50
@ NotStarted
Not started or uninitialized.
Definition: chessplayer.h:46
@ FinishingGame
Finishing or cleaning up after a game.
Definition: chessplayer.h:51
void moveMade(const Chess::Move &move)
void stoppedThinking()
void resultClaim(const Chess::Result &result)
void disconnected()
MoveEvaluation m_eval
Definition: chessplayer.h:299
void ready()
virtual void startGame()=0
void nameChanged(const QString &name)
virtual void startThinking()=0
void debugMessage(const QString &data)
void thinking(const MoveEvaluation &eval)
virtual void makeMove(const Chess::Move &move)=0
void startedThinking(int timeLeft)
virtual bool supportsVariant(const QString &variant) const =0
virtual bool isHuman() const =0
An internal chessboard class.
Definition: board.h:58
A small and efficient chessmove class.
Definition: move.h:43
The result of a chess game.
Definition: result.h:35
Type
Definition: result.h:41
The side or color of a chess player.
Definition: side.h:36
Evaluation data for a chess move.
Definition: moveevaluation.h:36
Time controls of a chess game.
Definition: timecontrol.h:36