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;
91  void addMove(const MoveData& data, bool addEco = true);
92  void setMove(int ply, const MoveData& data);
93 
100  Chess::Board* createBoard() const;
101 
114  bool read(PgnStream& in, int maxMoves = INT_MAX - 1,
115  bool addEco = true);
121  bool write(QTextStream& out, PgnMode mode = Verbose) const;
129  bool write(const QString& filename, PgnMode mode = Verbose) const;
130 
136  bool isStandard() const;
141  QString tagValue(const QString& tag) const;
143  QString event() const;
145  QString site() const;
147  QDate date() const;
149  int round() const;
151  QString playerName(Chess::Side side) const;
153  Chess::Result result() const;
155  QString variant() const;
157  Chess::Side startingSide() const;
159  QString startingFenString() const;
160 
165  void setTag(const QString& tag, const QString& value);
167  void setEvent(const QString& event);
169  void setSite(const QString& site);
171  void setDate(const QDate& date);
173  void setRound(int round);
175  void setPlayerName(Chess::Side side, const QString& name);
177  void setResult(const Chess::Result& result);
179  void setVariant(const QString& variant);
181  void setStartingSide(Chess::Side side);
183  void setStartingFenString(Chess::Side side, const QString& fen);
191  void setResultDescription(const QString& description);
192 
199  void setTagReceiver(QObject* receiver);
201  void setGameStartTime(const QDateTime& dateTime);
203  void setGameEndTime(const QDateTime& dateTime);
204 
206  QMap<int, int> extractScores() const;
207 
208  private:
209  bool parseMove(PgnStream& in, bool addEco);
210 
211  Chess::Side m_startingSide;
212  const EcoNode* m_eco;
213  QMap<QString, QString> m_tags;
214  QVector<MoveData> m_moves;
215  QObject* m_tagReceiver;
216  QString m_initialComment;
217  static QString timeStamp(const QDateTime& dateTime);
218  QDateTime m_gameStartTime;
219 };
220 
222 extern LIB_EXPORT PgnStream& operator>>(PgnStream& in, PgnGame& game);
223 
225 extern LIB_EXPORT QTextStream& operator<<(QTextStream& out, const PgnGame& game);
226 
227 #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:42
Chess::GenericMove move
Definition: pgngame.h:69
QString comment
Definition: pgngame.h:73
An internal chessboard class.
Definition: board.h:57
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:34
A node in the ECO tree (Encyclopaedia of Chess Openings)
Definition: econode.h:43
Definition: boardscene.h:29
The side or color of a chess player.
Definition: side.h:35
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:34
QString moveString
Definition: pgngame.h:71