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 setPgnCleanupEnabled(bool enabled);
189 
196  void setOpeningRepetition(bool repeat);
203  void setOpeningBookOwnership(bool enabled);
208  void setSeedCount(int seedCount);
218  void addPlayer(PlayerBuilder* builder,
219  const TimeControl& timeControl,
220  const OpeningBook* book = nullptr,
221  int bookDepth = 256);
226  virtual QString results() const;
227 
228  public slots:
230  void start();
238  void stop();
239 
240  signals:
249  void gameStarted(ChessGame* game,
250  int number,
251  int whiteIndex,
252  int blackIndex);
266  void gameFinished(ChessGame* game,
267  int number,
268  int whiteIndex,
269  int blackIndex);
277  void finished();
278 
279  protected:
281  void setCurrentRound(int round);
283  int gamesInProgress() const;
285  TournamentPair* currentPair() const;
292  TournamentPair* pair(int player1, int player2);
299  void startGame(TournamentPair* pair);
306  virtual void onGameAboutToStart(ChessGame* game,
307  const PlayerBuilder* white,
308  const PlayerBuilder* black);
314  int playerIndex(ChessGame* game, Chess::Side side) const;
322  virtual void initializePairing() = 0;
329  virtual int gamesPerCycle() const = 0;
344  virtual TournamentPair* nextPair(int gameNumber) = 0;
351  virtual void onFinished();
359  virtual void addScore(int player, int score);
364  virtual bool areAllGamesFinished() const;
372  virtual bool hasGauntletRatingsOrder() const;
373 
374  private slots:
375  void startNextGame();
376  bool writePgn(PgnGame* pgn, int gameNumber);
377  void onGameStarted(ChessGame* game);
378  void onGameFinished(ChessGame* game);
379  void onGameDestroyed(ChessGame* game);
380  void onGameStartFailed(ChessGame* game);
381 
382  private:
383  struct GameData
384  {
385  int number;
386  int whiteIndex;
387  int blackIndex;
388  };
389  struct RankingData
390  {
391  QString name;
392  int games;
393  qreal score;
394  qreal draws;
395  qreal errorMargin;
396  qreal eloDiff;
397  };
398 
399  GameManager* m_gameManager;
400  ChessGame* m_lastGame;
401  QString m_error;
402  QString m_name;
403  QString m_site;
404  QString m_variant;
405  int m_round;
406  int m_nextGameNumber;
407  int m_finishedGameCount;
408  int m_savedGameCount;
409  int m_finalGameCount;
410  int m_gamesPerEncounter;
411  int m_roundMultiplier;
412  int m_startDelay;
413  int m_openingDepth;
414  int m_seedCount;
415  bool m_stopping;
416  bool m_repeatOpening;
417  bool m_recover;
418  bool m_pgnCleanup;
419  bool m_finished;
420  bool m_bookOwnership;
421  GameAdjudicator m_adjudicator;
422  OpeningSuite* m_openingSuite;
423  Sprt* m_sprt;
424  QFile m_pgnFile;
425  QTextStream m_pgnOut;
426  QString m_startFen;
427  PgnGame::PgnMode m_pgnOutMode;
428  TournamentPair* m_pair;
430  QList<TournamentPlayer> m_players;
431  QMap<int, PgnGame> m_pgnGames;
432  QMap<ChessGame*, GameData*> m_gameData;
433  QVector<Chess::Move> m_openingMoves;
434 };
435 
436 #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:37
Time controls of a chess game.
Definition: timecontrol.h:34
A class for storing a player&#39;s tournament-specific details.
Definition: tournamentplayer.h:27
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:34
PgnMode
Definition: pgngame.h:55
A class for adjudicating chess games.
Definition: gameadjudicator.h:31
A class for managing chess games and players.
Definition: gamemanager.h:39
Base class for chess tournaments.
Definition: tournament.h:44
A collection of opening moves for chess.
Definition: openingbook.h:42
A single encounter in a tournament.
Definition: tournamentpair.h:30
A Sequential Probability Ratio Test.
Definition: sprt.h:31
A suite of chess openings.
Definition: openingsuite.h:39