Cute Chess  0.1
Classes | Public Types | Public Slots | Signals | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Tournament Class Referenceabstract

Base class for chess tournaments. More...

#include <tournament.h>

Inheritance diagram for Tournament:
QObject GauntletTournament KnockoutTournament PyramidTournament RoundRobinTournament

Public Types

enum  OpeningPolicy { DefaultPolicy, EncounterPolicy, RoundPolicy }
 

Public Slots

void start ()
 
void stop ()
 

Signals

void finished ()
 
void gameFinished (ChessGame *game, int number, int whiteIndex, int blackIndex)
 
void gameStarted (ChessGame *game, int number, int whiteIndex, int blackIndex)
 

Public Member Functions

void addPlayer (PlayerBuilder *builder, const TimeControl &timeControl, const OpeningBook *book=nullptr, int bookDepth=256)
 
virtual bool canSetRoundMultiplier () const
 
int currentRound () const
 
QString errorString () const
 
int finalGameCount () const
 
int finishedGameCount () const
 
GameManagergameManager () const
 
int gamesPerEncounter () const
 
bool isFinished () const
 
QString name () const
 
const QMap< QString, QString > & namedResultFormats () const
 
const TournamentPlayerplayerAt (int index) const
 
int playerCount () const
 
const QList< QStringresultFieldTokens () const
 
QString resultFormat () const
 
virtual QString results () const
 
int roundMultiplier () const
 
int seedCount () const
 
void setAdjudicator (const GameAdjudicator &adjudicator)
 
void setEpdOutput (const QString &fileName)
 
void setGamesPerEncounter (int count)
 
void setName (const QString &name)
 
void setOpeningBookOwnership (bool enabled)
 
void setOpeningDepth (int plies)
 
void setOpeningPolicy (OpeningPolicy policy=DefaultPolicy)
 
void setOpeningRepetitions (int count)
 
void setOpeningSuite (OpeningSuite *suite)
 
void setPgnCleanupEnabled (bool enabled)
 
void setPgnOutput (const QString &fileName, PgnGame::PgnMode mode=PgnGame::Verbose)
 
void setPgnWriteUnfinishedGames (bool enabled)
 
void setRecoveryMode (bool recover)
 
void setResultFormat (const QString &format)
 
void setReverseSides (bool enabled)
 
void setRoundMultiplier (int factor)
 
void setSeedCount (int seedCount)
 
void setSite (const QString &site)
 
void setStartDelay (int delay)
 
void setSwapSides (bool enabled)
 
void setVariant (const QString &variant)
 
QString site () const
 
Sprtsprt () const
 
 Tournament (GameManager *gameManager, QObject *parent)
 
virtual QString type () const =0
 
QString variant () const
 
virtual ~Tournament ()
 

Static Public Attributes

static constexpr auto c_defaultFormat = "Rank,Name,Elo,Error,Games,Score,DScore"
 

Protected Member Functions

virtual void addScore (int player, Chess::Side side, int score)
 
virtual bool areAllGamesFinished () const
 
TournamentPaircurrentPair () const
 
int gamesInProgress () const
 
virtual int gamesPerCycle () const =0
 
virtual bool hasGauntletRatingsOrder () const
 
virtual void initializePairing ()=0
 
virtual TournamentPairnextPair (int gameNumber)=0
 
virtual void onFinished ()
 
virtual void onGameAboutToStart (ChessGame *game, const PlayerBuilder *white, const PlayerBuilder *black)
 
TournamentPairpair (int player1, int player2)
 
int playerIndex (ChessGame *game, Chess::Side side) const
 
void setCurrentRound (int round)
 
void startGame (TournamentPair *pair)
 

Detailed Description

Base class for chess tournaments.

Member Enumeration Documentation

◆ OpeningPolicy

The policy for using a fresh opening.

Enumerator
DefaultPolicy 

Shift on repetition count and on new encounter.

EncounterPolicy 

Shift on new encounter.

RoundPolicy 

Shift on new round.

Constructor & Destructor Documentation

◆ Tournament()

Tournament::Tournament ( GameManager gameManager,
QObject parent 
)

Creates a new tournament that uses gameManager to manage the games.

◆ ~Tournament()

Tournament::~Tournament ( )
virtual

Destroys the tournament.

The destructor doesn't end any active games or cleanup their resources. The tournament can be safely destroyed only after the finished() signal is emitted.

Member Function Documentation

◆ addPlayer()

void Tournament::addPlayer ( PlayerBuilder builder,
const TimeControl timeControl,
const OpeningBook book = nullptr,
int  bookDepth = 256 
)

Adds player builder to the tournament.

The player's time control will be timeControl, which may differ from the other players' time controls.

The Tournament object takes ownership of builder and will take care of deleting it.

◆ addScore()

void Tournament::addScore ( int  player,
Chess::Side  side,
int  score 
)
protectedvirtual

Adds score points to player at index player.

This member function is called when a game ends with a 1-0, 0-1 or 1/2-1/2 result. Subclasses can reimplement this to do their own score tracking.

Reimplemented in KnockoutTournament.

◆ areAllGamesFinished()

bool Tournament::areAllGamesFinished ( ) const
protectedvirtual

Returns true if all games in the tournament have finished; otherwise returns false.

Reimplemented in KnockoutTournament.

◆ canSetRoundMultiplier()

bool Tournament::canSetRoundMultiplier ( ) const
virtual

Returns true (default) if the tournament supports user-defined round multiplier; otherwise returns false.

Reimplemented in KnockoutTournament.

◆ currentPair()

TournamentPair * Tournament::currentPair ( ) const
protected

Returns the pair that started the last game.

◆ currentRound()

int Tournament::currentRound ( ) const

Returns the currently executing round of the tournament.

◆ errorString()

QString Tournament::errorString ( ) const

Returns a detailed description of the error.

◆ finalGameCount()

int Tournament::finalGameCount ( ) const

Returns the total number of games that will be played.

◆ finished

void Tournament::finished ( )
signal

This signal is emitted when all of the tournament's games have been played or after the tournament was stopped.

The tournament can be safely destroyed after this signal is sent.

◆ finishedGameCount()

int Tournament::finishedGameCount ( ) const

Returns the number of games finished so far.

◆ gameFinished

void Tournament::gameFinished ( ChessGame game,
int  number,
int  whiteIndex,
int  blackIndex 
)
signal

This signal is emitted when game game with ordering number number is finished.

The Tournament object deletes the game right after emitting this signal.

whiteIndex is the index to the white player's data blackIndex is the index to the black player's data

Note
The game numbers start at 1.
The games may not finish in the same order they are started.

◆ gameManager()

GameManager * Tournament::gameManager ( ) const

Returns the GameManager that manages the tournament's games.

◆ gamesInProgress()

int Tournament::gamesInProgress ( ) const
protected

Returns the number of games in progress.

◆ gamesPerCycle()

virtual int Tournament::gamesPerCycle ( ) const
protectedpure virtual

Returns the number of games in one tournament cycle.

The gamesPerEncounter() and roundMultiplier() values must not affect the number of games per cycle.

Implemented in KnockoutTournament, GauntletTournament, PyramidTournament, and RoundRobinTournament.

◆ gamesPerEncounter()

int Tournament::gamesPerEncounter ( ) const

Returns the number of games to play per encounter.

If the number of games is even then each player is guaranteed to play an equal number of games with white and black pieces.

The default value is 1.

◆ gameStarted

void Tournament::gameStarted ( ChessGame game,
int  number,
int  whiteIndex,
int  blackIndex 
)
signal

This signal is emitted when game game with ordering number number is started.

whiteIndex is the index to the white player's data blackIndex is the index to the black player's data

Note
The game numbers start at 1.

◆ hasGauntletRatingsOrder()

bool Tournament::hasGauntletRatingsOrder ( ) const
protectedvirtual

Returns true if Gauntlet ordering is used for the ratings table (ie. first engine always at the top and the rest ordered by Elo); otherwise returns false.

The default implementation always returns false.

Reimplemented in GauntletTournament.

◆ initializePairing()

virtual void Tournament::initializePairing ( )
protectedpure virtual

Initializes the pairings for the tournament.

Subclasses that implement this member function should prepare their data so that the nextPair() function can be called immediately afterwards.

Implemented in KnockoutTournament, GauntletTournament, PyramidTournament, and RoundRobinTournament.

◆ isFinished()

bool Tournament::isFinished ( ) const

Returns true if the tournament is finished; otherwise returns false.

◆ name()

QString Tournament::name ( ) const

Returns the name of the tournament.

The tournament name will be used as the "Event" tag's value in the resulting PGN data.

◆ namedResultFormats()

const QMap< QString, QString > & Tournament::namedResultFormats ( ) const

Lists the result formats associated with a name.

◆ nextPair()

virtual TournamentPair* Tournament::nextPair ( int  gameNumber)
protectedpure virtual

Returns the pair of players for the next game.

The pair's first element is the white player's index number and the second element is the black player's index number.

Subclasses that implement this member function should call setCurrentRound() to increase the round when needed. Subclasses should also alternate the colors when needed, to make the tournament as fair as possible.

Sublasses can return (-1, -1) if the next game should not be started yet.

Implemented in KnockoutTournament, GauntletTournament, PyramidTournament, and RoundRobinTournament.

◆ onFinished()

void Tournament::onFinished ( )
protectedvirtual

Emits the finished() signal.

Subclasses can reimplement this method to add their own cleanup and finalization routines when the tournament ends.

◆ onGameAboutToStart()

void Tournament::onGameAboutToStart ( ChessGame game,
const PlayerBuilder white,
const PlayerBuilder black 
)
protectedvirtual

This member function is called by startGame() right before the game is actually started.

The default implementation does nothing.

Reimplemented in GauntletTournament.

◆ pair()

TournamentPair * Tournament::pair ( int  player1,
int  player2 
)
protected

Returns a tournament pair of player1 and player2.

If a pair with the given players doesn't already exist, one is created.

◆ playerAt()

const TournamentPlayer & Tournament::playerAt ( int  index) const

Returns player data for the player at index.

◆ playerCount()

int Tournament::playerCount ( ) const

Returns the number of participants in the tournament.

◆ playerIndex()

int Tournament::playerIndex ( ChessGame game,
Chess::Side  side 
) const
protected

Returns the index of player side in game.

Note
game must belong to this tournament.

◆ resultFieldTokens()

const QList< QString > Tournament::resultFieldTokens ( ) const

Lists the format tokens for results

◆ resultFormat()

QString Tournament::resultFormat ( ) const

Returns the format of the result table. The format uses tokens given by fieldMap.

◆ results()

QString Tournament::results ( ) const
virtual

Returns tournament results as a string. The default implementation works for most tournament types.

Reimplemented in KnockoutTournament.

◆ roundMultiplier()

int Tournament::roundMultiplier ( ) const

Returns the multiplier for the number of rounds to play.

The default value is 1.

◆ seedCount()

int Tournament::seedCount ( ) const

Returns the maximum number of players that can be seeded in the tournament.

◆ setAdjudicator()

void Tournament::setAdjudicator ( const GameAdjudicator adjudicator)

Sets the game adjudicator to adjudicator.

The default adjudicator does nothing.

◆ setCurrentRound()

void Tournament::setCurrentRound ( int  round)
protected

Sets the currently executing tournament round to round.

◆ setEpdOutput()

void Tournament::setEpdOutput ( const QString fileName)

Sets the EPD output file for the end positions to fileName.

If no EPD output file is set (default) then the positions will not be saved.

◆ setGamesPerEncounter()

void Tournament::setGamesPerEncounter ( int  count)

Sets the game count per encounter to counter.

counter must be at least 1.

◆ setName()

void Tournament::setName ( const QString name)

Sets the tournament's name to name.

◆ setOpeningBookOwnership()

void Tournament::setOpeningBookOwnership ( bool  enabled)

Sets opening book ownership to enabled.

By default the Tournament object doesn't take ownership of its opening books.

◆ setOpeningDepth()

void Tournament::setOpeningDepth ( int  plies)

Sets the maximum depth of an opening from the opening suite to plies (halfmoves).

◆ setOpeningPolicy()

void Tournament::setOpeningPolicy ( Tournament::OpeningPolicy  policy = DefaultPolicy)

The value of policy rules when to switch to the next opening.

Given the default value DefaultPolicy a new opening is selected when the number of opening repetitions played reaches the specified number of repetitions (setOpeningRepetitions) or a new encounter is started.

If EncounterPolicy is used then a new opening will be selected only for any new encounter. RoundPolicy shifts to a new opening only when a new round starts.

◆ setOpeningRepetitions()

void Tournament::setOpeningRepetitions ( int  count)

Sets the number of opening repetitions to count.

Each opening is played count times before going to the next opening. The default is 1.

◆ setOpeningSuite()

void Tournament::setOpeningSuite ( OpeningSuite suite)

Uses suite as the opening suite (a collection of openings) for the games.

The tournament takes ownership of suite.

◆ setPgnCleanupEnabled()

void Tournament::setPgnCleanupEnabled ( bool  enabled)

Sets PgnGame cleanup mode to enabled.

If enabled is true (the default) then the generated PgnGame objects are destroyed automatically once the games are finished.

◆ setPgnOutput()

void Tournament::setPgnOutput ( const QString fileName,
PgnGame::PgnMode  mode = PgnGame::Verbose 
)

Sets the PGN output file for the games to fileName.

The games are saved to the file in mode mode. If no PGN output file is set (default) then the games won't be saved.

◆ setPgnWriteUnfinishedGames()

void Tournament::setPgnWriteUnfinishedGames ( bool  enabled)

Sets the PgnGame mode to write unfinished games to enabled.

If enabled is true (the default) then the generated PGN games are saved even if they have no result.

◆ setRecoveryMode()

void Tournament::setRecoveryMode ( bool  recover)

Sets the recovery mode to recover.

If recover is true then crashed players will will be restarted for the next game; otherwise the whole tournament stops when a player crashes.

◆ setResultFormat()

void Tournament::setResultFormat ( const QString format)

The format specifies which information are listed in the table of tournament results. Available tokens are given by fieldMap.

◆ setReverseSides()

void Tournament::setReverseSides ( bool  enabled)

Sets the reverse colors flag to enabled.

If enabled is true then the players will play reverse sides /wrt to the normal schedule. The default is false.

◆ setRoundMultiplier()

void Tournament::setRoundMultiplier ( int  factor)

Sets the multiplier for the number of rounds to factor.

factor must be at least 1.

◆ setSeedCount()

void Tournament::setSeedCount ( int  seedCount)

Sets the maximum number of players that should be seeded in the tournament.

◆ setSite()

void Tournament::setSite ( const QString site)

Sets the tournament's site to site.

◆ setStartDelay()

void Tournament::setStartDelay ( int  delay)

Sets the starting delay for each game to delay msec.

◆ setSwapSides()

void Tournament::setSwapSides ( bool  enabled)

Sets the side swap flag to enabled.

If enabled is true then paired engines will swap sides for the following game.

◆ setVariant()

void Tournament::setVariant ( const QString variant)

Sets the games' chess variant to variant.

◆ site()

QString Tournament::site ( ) const

Returns the tournament site, ie. the "Site" tag's value.

◆ sprt()

Sprt * Tournament::sprt ( ) const

Returns the SPRT object of this tournament.

Initializing sprt makes this tournament to use it as a stopping criterion.

◆ start

void Tournament::start ( )
slot

Starts the tournament.

◆ startGame()

void Tournament::startGame ( TournamentPair pair)
protected

This member function is called by startNextGame() to start a new tournament game between pair.

Reimplementations should call the base implementation.

◆ stop

void Tournament::stop ( )
slot

Stops the tournament.

Any running games will have an unterminated result. The finished() signal is emitted when the tournament is fully stopped.

◆ type()

virtual QString Tournament::type ( ) const
pure virtual

Returns the tournament type (eg. "round-robin" or "gauntlet").

Implemented in KnockoutTournament, PyramidTournament, RoundRobinTournament, and GauntletTournament.

◆ variant()

QString Tournament::variant ( ) const

Returns the games' chess variant.


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