Cute Chess 0.1
chessgame.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 CHESSGAME_H
19#define CHESSGAME_H
20
21#include <QObject>
22#include <QVector>
23#include <QStringList>
24#include <QMap>
25#include <QSemaphore>
26#include "pgngame.h"
27#include "board/result.h"
28#include "board/move.h"
29#include "timecontrol.h"
30#include "gameadjudicator.h"
31
32namespace Chess { class Board; }
33class ChessPlayer;
34class OpeningBook;
35class MoveEvaluation;
36
37
38class LIB_EXPORT ChessGame : public QObject
39{
40 Q_OBJECT
41
42 public:
43 ChessGame(Chess::Board* board, PgnGame* pgn, QObject* parent = nullptr);
44 virtual ~ChessGame();
45
46 QString errorString() const;
47 ChessPlayer* player(Chess::Side side) const;
48 ChessPlayer* playerToMove() const;
49 ChessPlayer* playerToWait() const;
50 bool isFinished() const;
51 bool boardShouldBeFlipped() const;
52 void setBoardShouldBeFlipped(bool flip);
53
54 PgnGame* pgn() const;
55 Chess::Board* board() const;
56 QString startingFen() const;
57 const QVector<Chess::Move>& moves() const;
58 const QMap<int,int>& scores() const;
59 Chess::Result result() const;
60
61 void setError(const QString& message);
62 void setPlayer(Chess::Side side, ChessPlayer* player);
63 void setStartingFen(const QString& fen);
64 void setTimeControl(const TimeControl& timeControl,
65 Chess::Side side = Chess::Side());
66 void setMoves(const QVector<Chess::Move>& moves);
67 bool setMoves(const PgnGame& pgn);
68 void setOpeningBook(const OpeningBook* book,
69 Chess::Side side = Chess::Side(),
70 int depth = 1000);
71 void setAdjudicator(const GameAdjudicator& adjudicator);
72 void setStartDelay(int time);
73 void setBookOwnership(bool enabled);
74
75 void generateOpening();
76
77 void lockThread();
78 void unlockThread();
79
80 public slots:
81 void start();
82 void pause();
83 void resume();
84 void stop(bool emitMoveChanged = true);
85 void kill();
86 void emitStartFailed();
87 void onMoveMade(const Chess::Move& move);
88 void onAdjudication(const Chess::Result& result);
89 void onResignation(const Chess::Result& result);
90
91 signals:
92 void humanEnabled(bool);
93 void fenChanged(const QString& fenString);
94 void moveMade(const Chess::GenericMove& move,
95 const QString& sanString,
96 const QString& comment);
97 void moveChanged(int ply,
98 const Chess::GenericMove& move,
99 const QString& sanString,
100 const QString& comment);
101 void scoreChanged(int ply, int score);
102 void initialized(ChessGame* game = nullptr);
103 void started(ChessGame* game = nullptr);
104 void finished(ChessGame* game = nullptr,
105 Chess::Result result = Chess::Result());
106 void startFailed(ChessGame* game = nullptr);
107 void playersReady();
108
109 private slots:
110 void startGame();
111 void startTurn();
112 void finish();
113 void onResultClaim(const Chess::Result& result);
114 void onPlayerReady();
115 void syncPlayers();
116 void pauseThread();
117
118 private:
119 Chess::Move bookMove(Chess::Side side);
120 bool resetBoard();
121 void initializePgn();
122 void addPgnMove(const Chess::Move& move, const QString& comment);
123 void emitLastMove();
124
125 Chess::Board* m_board;
126 ChessPlayer* m_player[2];
127 TimeControl m_timeControl[2];
128 const OpeningBook* m_book[2];
129 int m_bookDepth[2];
130 int m_startDelay;
131 bool m_finished;
132 bool m_gameInProgress;
133 bool m_paused;
134 bool m_pgnInitialized;
135 bool m_bookOwnership;
136 bool m_boardShouldBeFlipped;
137 QString m_error;
138 QString m_startingFen;
139 Chess::Result m_result;
140 QVector<Chess::Move> m_moves;
141 QMap<int,int> m_scores;
142 PgnGame* m_pgn;
143 QSemaphore m_pauseSem;
144 QSemaphore m_resumeSem;
145 GameAdjudicator m_adjudicator;
146};
147
148#endif // CHESSGAME_H
A chess player, human or AI.
Definition chessplayer.h:39
An internal chessboard class.
Definition board.h:58
A chess move independent of chess variant or opening book format.
Definition genericmove.h:35
A small and efficient chessmove class.
Definition move.h:43
The result of a chess game.
Definition result.h:35
The side or color of a chess player.
Definition side.h:36
A class for adjudicating chess games.
Definition gameadjudicator.h:33
Evaluation data for a chess move.
Definition moveevaluation.h:36
A collection of opening moves for chess.
Definition openingbook.h:44
A game of chess in PGN format.
Definition pgngame.h:52
Time controls of a chess game.
Definition timecontrol.h:36