Cute Chess  0.1
Classes | Public Types | Public Member Functions | List of all members
PgnGame Class Reference

A game of chess in PGN format. More...

#include <pgngame.h>

Classes

struct  MoveData
 A struct for storing the game's move history. More...
 

Public Types

enum  PgnMode { Minimal, Verbose }
 

Public Member Functions

void addMove (const MoveData &data, bool addEco=true)
 
void clear ()
 
Chess::BoardcreateBoard () const
 
QDate date () const
 
QString event () const
 
QMap< int, int > extractScores () const
 
bool isNull () const
 
bool isStandard () const
 
const QVector< MoveData > & moves () const
 
 PgnGame ()
 
QString playerName (Chess::Side side) const
 
bool read (PgnStream &in, int maxMoves=INT_MAX-1, bool addEco=true)
 
Chess::Result result () const
 
int round () const
 
void setDate (const QDate &date)
 
void setEvent (const QString &event)
 
void setGameEndTime (const QDateTime &dateTime)
 
void setGameStartTime (const QDateTime &dateTime)
 
void setMove (int ply, const MoveData &data)
 
void setPlayerName (Chess::Side side, const QString &name)
 
void setResult (const Chess::Result &result)
 
void setResultDescription (const QString &description)
 
void setRound (int round)
 
void setSite (const QString &site)
 
void setStartingFenString (Chess::Side side, const QString &fen)
 
void setStartingSide (Chess::Side side)
 
void setTag (const QString &tag, const QString &value)
 
void setTagReceiver (QObject *receiver)
 
void setVariant (const QString &variant)
 
QString site () const
 
QString startingFenString () const
 
Chess::Side startingSide () const
 
QList< QPair< QString, QString > > tags () const
 
QString tagValue (const QString &tag) const
 
QString variant () const
 
bool write (QTextStream &out, PgnMode mode=Verbose) const
 
bool write (const QString &filename, PgnMode mode=Verbose) const
 

Detailed Description

A game of chess in PGN format.

PGN (Portable game notation) is a text format for chess games. Specification: http://www.very-best.de/pgn-spec.htm

PgnGame is a middle format between text-based PGN games and games played by Cute Chess. PgnGame objects are used for converting played games to PGN format, importing PGN data to opening books, analyzing previous games on a graphical board, etc.

See also
PgnStream
ChessGame

Member Enumeration Documentation

The mode for writing PGN games.

Enumerator
Minimal 

Only use data which is required by the PGN standard.

Verbose 

Use additional data like extra tags and comments.

Constructor & Destructor Documentation

PgnGame::PgnGame ( )

Creates a new PgnGame object.

Member Function Documentation

void PgnGame::addMove ( const MoveData data,
bool  addEco = true 
)

Adds a new move to the game.

Parameters
dataThe move to add.
addEcoAdds opening information if true.
void PgnGame::clear ( )

Deletes all tags and moves.

Chess::Board * PgnGame::createBoard ( ) const

Creates a board object for viewing or analyzing the game.

The board is set to the game's starting position. Returns 0 on error.

QDate PgnGame::date ( ) const

Returns the starting date of the game.

QString PgnGame::event ( ) const

Returns the name of the tournament or match event.

QMap< int, int > PgnGame::extractScores ( ) const

Returns QMap of scores extracted from PGN comments

bool PgnGame::isNull ( ) const

Returns true if the game doesn't contain any tags or moves.

bool PgnGame::isStandard ( ) const

Returns true if the game's variant is "standard" and it's played from the default starting position; otherwise returns false.

const QVector< PgnGame::MoveData > & PgnGame::moves ( ) const

Returns the moves that were played in the game.

QString PgnGame::playerName ( Chess::Side  side) const

Returns the player's name who plays side.

bool PgnGame::read ( PgnStream in,
int  maxMoves = INT_MAX - 1,
bool  addEco = true 
)

Reads a game from a PGN text stream.

Parameters
inThe PGN stream to read from.
maxMovesThe maximum number of halfmoves to read.
addEcoAdds opening information if true.
Note
Even if the stream contains multiple games, only one will be read.

Returns true if any tags and/or moves were read.

Chess::Result PgnGame::result ( ) const

Returns the result of the game.

int PgnGame::round ( ) const

Returns the the playing round ordinal of the game.

void PgnGame::setDate ( const QDate &  date)

Sets the starting date of the game.

void PgnGame::setEvent ( const QString event)

Sets the name of the tournament or match event.

void PgnGame::setGameEndTime ( const QDateTime dateTime)

Sets the end time and the duration of the game

void PgnGame::setGameStartTime ( const QDateTime dateTime)

Sets the starting time of the game

void PgnGame::setPlayerName ( Chess::Side  side,
const QString name 
)

Sets the player's name who plays side.

void PgnGame::setResult ( const Chess::Result result)

Sets the result of the game.

void PgnGame::setResultDescription ( const QString description)

Sets a description for the result.

The description is appended to the last move's comment/annotation.

Note
This is not the same as the "Termination" tag which can only hold one of the standardized values.
void PgnGame::setRound ( int  round)

Sets the playing round ordinal of the game.

void PgnGame::setSite ( const QString site)

Sets the location of the event.

void PgnGame::setStartingFenString ( Chess::Side  side,
const QString fen 
)

Sets the starting position's FEN string.

void PgnGame::setStartingSide ( Chess::Side  side)

Sets the side that starts the game.

void PgnGame::setTag ( const QString tag,
const QString value 
)

Sets tag's value to value. If tag doesn't exist, a new tag is created.

void PgnGame::setTagReceiver ( QObject receiver)

Sets a receiver for PGN tags

receiver is an object whose "setTag(QString tag, QString value)" slot is called when a PGN tag changes.

void PgnGame::setVariant ( const QString variant)

Sets the chess variant of the game.

QString PgnGame::site ( ) const

Returns the location of the event.

QString PgnGame::startingFenString ( ) const

Returns the starting position's FEN string.

Chess::Side PgnGame::startingSide ( ) const

Returns the side that starts the game.

QList< QPair< QString, QString > > PgnGame::tags ( ) const

Returns the tags that are used to describe the game.

QString PgnGame::tagValue ( const QString tag) const

Returns the value of tag tag. If tag doesn't exist, an empty string is returned.

QString PgnGame::variant ( ) const

Returns the chess variant of the game.

bool PgnGame::write ( QTextStream out,
PgnMode  mode = Verbose 
) const

Writes the game to a text stream.

Returns true if successful; otherwise returns false.

bool PgnGame::write ( const QString filename,
PgnMode  mode = Verbose 
) const

Writes the game to a file. If the file already exists, the game will be appended to the end of the file.

Returns true if successful; otherwise returns false.


The documentation for this class was generated from the following files: