Cute Chess  0.1
tournament.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 
19 #ifndef TOURNAMENT_H
20 #define TOURNAMENT_H
21 
22 #include <QObject>
23 #include <QList>
24 #include <QVector>
25 #include <QMap>
26 #include <QFile>
27 #include <QTextStream>
28 #include "board/move.h"
29 #include "timecontrol.h"
30 #include "pgngame.h"
31 #include "gameadjudicator.h"
32 #include "tournamentplayer.h"
33 #include "tournamentpair.h"
34 class GameManager;
35 class PlayerBuilder;
36 class ChessGame;
37 class OpeningBook;
38 class OpeningSuite;
39 class Sprt;
40 
44 class LIB_EXPORT Tournament : public QObject
45 {
46  Q_OBJECT
47 
48  public:
53  Tournament(GameManager* gameManager, QObject *parent);
61  virtual ~Tournament();
62 
64  virtual QString type() const = 0;
66  GameManager* gameManager() const;
68  bool isFinished() const;
70  QString errorString() const;
77  QString name() const;
79  QString site() const;
81  QString variant() const;
83  int currentRound() const;
93  int gamesPerEncounter() const;
99  int roundMultiplier() const;
101  int finishedGameCount() const;
103  int finalGameCount() const;
105  const TournamentPlayer& playerAt(int index) const;
107  int playerCount() const;
112  int seedCount() const;
119  Sprt* sprt() const;
120 
122  void setName(const QString& name);
124  void setSite(const QString& site);
126  void setVariant(const QString& variant);
132  void setGamesPerEncounter(int count);
137  virtual bool canSetRoundMultiplier() const;
143  void setRoundMultiplier(int factor);
145  void setStartDelay(int delay);
153  void setRecoveryMode(bool recover);
159  void setAdjudicator(const GameAdjudicator& adjudicator);
166  void setOpeningSuite(OpeningSuite* suite);
171  void setOpeningDepth(int plies);
179  void setPgnOutput(const QString& fileName,
181 
188  void setPgnWriteUnfinishedGames(bool enabled);
189 
196  void setPgnCleanupEnabled(bool enabled);
197 
204  void setEpdOutput(const QString& fileName);
205 
212  void setOpeningRepetitions(int count);
219  void setSwapSides(bool enabled);
226  void setOpeningBookOwnership(bool enabled);
231  void setSeedCount(int seedCount);
241  void addPlayer(PlayerBuilder* builder,
242  const TimeControl& timeControl,
243  const OpeningBook* book = nullptr,
244  int bookDepth = 256);
249  virtual QString results() const;
250 
251  public slots:
253  void start();
261  void stop();
262 
263  signals:
272  void gameStarted(ChessGame* game,
273  int number,
274  int whiteIndex,
275  int blackIndex);
289  void gameFinished(ChessGame* game,
290  int number,
291  int whiteIndex,
292  int blackIndex);
300  void finished();
301 
302  protected:
304  void setCurrentRound(int round);
306  int gamesInProgress() const;
308  TournamentPair* currentPair() const;
315  TournamentPair* pair(int player1, int player2);
322  void startGame(TournamentPair* pair);
329  virtual void onGameAboutToStart(ChessGame* game,
330  const PlayerBuilder* white,
331  const PlayerBuilder* black);
337  int playerIndex(ChessGame* game, Chess::Side side) const;
345  virtual void initializePairing() = 0;
352  virtual int gamesPerCycle() const = 0;
367  virtual TournamentPair* nextPair(int gameNumber) = 0;
374  virtual void onFinished();
382  virtual void addScore(int player, int score);
387  virtual bool areAllGamesFinished() const;
395  virtual bool hasGauntletRatingsOrder() const;
396 
397  private slots:
398  void startNextGame();
399  bool writePgn(PgnGame* pgn, int gameNumber);
400  bool writeEpd(ChessGame* game);
401  void onGameStarted(ChessGame* game);
402  void onGameFinished(ChessGame* game);
403  void onGameDestroyed(ChessGame* game);
404  void onGameStartFailed(ChessGame* game);
405 
406  private:
407  struct GameData
408  {
409  int number;
410  int whiteIndex;
411  int blackIndex;
412  };
413  struct RankingData
414  {
415  QString name;
416  int games;
417  qreal score;
418  qreal draws;
419  qreal errorMargin;
420  qreal eloDiff;
421  };
422 
423  GameManager* m_gameManager;
424  ChessGame* m_lastGame;
425  QString m_error;
426  QString m_name;
427  QString m_site;
428  QString m_variant;
429  int m_round;
430  int m_nextGameNumber;
431  int m_finishedGameCount;
432  int m_savedGameCount;
433  int m_finalGameCount;
434  int m_gamesPerEncounter;
435  int m_roundMultiplier;
436  int m_startDelay;
437  int m_openingDepth;
438  int m_seedCount;
439  bool m_stopping;
440  int m_openingRepetitions;
441  bool m_recover;
442  bool m_pgnCleanup;
443  bool m_pgnWriteUnfinishedGames;
444  bool m_finished;
445  bool m_bookOwnership;
446  GameAdjudicator m_adjudicator;
447  OpeningSuite* m_openingSuite;
448  Sprt* m_sprt;
449  QFile m_pgnFile;
450  QTextStream m_pgnOut;
451  QFile m_epdFile;
452  QTextStream m_epdOut;
453  QString m_startFen;
454  int m_repetitionCounter;
455  int m_swapSides;
456  PgnGame::PgnMode m_pgnOutMode;
457  TournamentPair* m_pair;
459  QList<TournamentPlayer> m_players;
460  QMap<int, PgnGame> m_pgnGames;
461  QMap<ChessGame*, GameData*> m_gameData;
462  QVector<Chess::Move> m_openingMoves;
463 };
464 
465 #endif // TOURNAMENT_H
Use additional data like extra tags and comments.
Definition: pgngame.h:60
A class for constructing new chess players.
Definition: playerbuilder.h:38
Time controls of a chess game.
Definition: timecontrol.h:35
A class for storing a player&#39;s tournament-specific details.
Definition: tournamentplayer.h:28
A game of chess in PGN format.
Definition: pgngame.h:51
Definition: chessgame.h:38
The side or color of a chess player.
Definition: side.h:35
PgnMode
Definition: pgngame.h:55
A class for adjudicating chess games.
Definition: gameadjudicator.h:32
A class for managing chess games and players.
Definition: gamemanager.h:40
Base class for chess tournaments.
Definition: tournament.h:44
A collection of opening moves for chess.
Definition: openingbook.h:43
A single encounter in a tournament.
Definition: tournamentpair.h:31
A Sequential Probability Ratio Test.
Definition: sprt.h:32
A suite of chess openings.
Definition: openingsuite.h:40