Cute Chess  0.1
pgngame.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 PGNGAME_H
19 #define PGNGAME_H
20 
21 #include <QMap>
22 #include <QString>
23 #include <QVector>
24 #include <QList>
25 #include <QPair>
26 #include <QDate>
27 #include <climits>
28 #include "board/genericmove.h"
29 #include "board/result.h"
30 class QTextStream;
31 class PgnStream;
32 class EcoNode;
33 class QObject;
34 namespace Chess { class Board; }
35 
36 
51 class LIB_EXPORT PgnGame
52 {
53  public:
55  enum PgnMode
56  {
60  Verbose
61  };
62 
64  struct MoveData
65  {
67  quint64 key;
74  };
75 
77  PgnGame();
79  bool isNull() const;
81  void clear();
82 
84  QList< QPair<QString, QString> > tags() const;
86  const QVector<MoveData>& moves() const;
88  void addMove(const MoveData& data);
89  void setMove(int ply, const MoveData& data);
90 
97  Chess::Board* createBoard() const;
98 
110  bool read(PgnStream& in, int maxMoves = INT_MAX - 1);
116  bool write(QTextStream& out, PgnMode mode = Verbose) const;
124  bool write(const QString& filename, PgnMode mode = Verbose) const;
125 
131  bool isStandard() const;
136  QString tagValue(const QString& tag) const;
138  QString event() const;
140  QString site() const;
142  QDate date() const;
144  int round() const;
146  QString playerName(Chess::Side side) const;
148  Chess::Result result() const;
150  QString variant() const;
152  Chess::Side startingSide() const;
154  QString startingFenString() const;
155 
160  void setTag(const QString& tag, const QString& value);
162  void setEvent(const QString& event);
164  void setSite(const QString& site);
166  void setDate(const QDate& date);
168  void setRound(int round);
170  void setPlayerName(Chess::Side side, const QString& name);
172  void setResult(const Chess::Result& result);
174  void setVariant(const QString& variant);
176  void setStartingSide(Chess::Side side);
178  void setStartingFenString(Chess::Side side, const QString& fen);
186  void setResultDescription(const QString& description);
187 
194  void setTagReceiver(QObject* receiver);
195 
196  private:
197  bool parseMove(PgnStream& in);
198 
199  Chess::Side m_startingSide;
200  const EcoNode* m_eco;
201  QMap<QString, QString> m_tags;
202  QVector<MoveData> m_moves;
203  QObject* m_tagReceiver;
204  QString m_initialComment;
205 };
206 
208 extern LIB_EXPORT PgnStream& operator>>(PgnStream& in, PgnGame& game);
209 
211 extern LIB_EXPORT QTextStream& operator<<(QTextStream& out, const PgnGame& game);
212 
213 #endif // PGNGAME_H
A struct for storing the game&#39;s move history.
Definition: pgngame.h:64
A class for reading games in PGN format from a text stream.
Definition: pgnstream.h:41
Chess::GenericMove move
Definition: pgngame.h:69
QString comment
Definition: pgngame.h:73
An internal chessboard class.
Definition: board.h:56
A game of chess in PGN format.
Definition: pgngame.h:51
A chess move independent of chess variant or opening book format.
Definition: genericmove.h:33
A node in the ECO tree (Encyclopaedia of Chess Openings)
Definition: econode.h:42
Definition: boardscene.h:28
The side or color of a chess player.
Definition: side.h:34
Only use data which is required by the PGN standard.
Definition: pgngame.h:58
quint64 key
Definition: pgngame.h:67
PgnMode
Definition: pgngame.h:55
The result of a chess game.
Definition: result.h:33
QString moveString
Definition: pgngame.h:71
QDebug operator<<(QDebug d, const QCPVector2D &vec)
Definition: qcustomplot.h:441