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:
51  {
54  RoundPolicy
55  };
56 
61  Tournament(GameManager* gameManager, QObject *parent);
69  virtual ~Tournament();
70 
72  virtual QString type() const = 0;
74  GameManager* gameManager() const;
76  bool isFinished() const;
78  QString errorString() const;
85  QString name() const;
87  QString site() const;
89  QString variant() const;
91  int currentRound() const;
101  int gamesPerEncounter() const;
107  int roundMultiplier() const;
109  int finishedGameCount() const;
111  int finalGameCount() const;
113  const TournamentPlayer& playerAt(int index) const;
115  int playerCount() const;
120  int seedCount() const;
127  Sprt* sprt() const;
128 
130  void setName(const QString& name);
132  void setSite(const QString& site);
134  void setVariant(const QString& variant);
140  void setGamesPerEncounter(int count);
145  virtual bool canSetRoundMultiplier() const;
151  void setRoundMultiplier(int factor);
153  void setStartDelay(int delay);
161  void setRecoveryMode(bool recover);
167  void setAdjudicator(const GameAdjudicator& adjudicator);
174  void setOpeningSuite(OpeningSuite* suite);
179  void setOpeningDepth(int plies);
187  void setPgnOutput(const QString& fileName,
189 
196  void setPgnWriteUnfinishedGames(bool enabled);
197 
204  void setPgnCleanupEnabled(bool enabled);
205 
212  void setEpdOutput(const QString& fileName);
213 
220  void setOpeningRepetitions(int count);
233  void setOpeningPolicy(OpeningPolicy policy = DefaultPolicy);
240  void setSwapSides(bool enabled);
247  void setOpeningBookOwnership(bool enabled);
252  void setSeedCount(int seedCount);
262  void addPlayer(PlayerBuilder* builder,
263  const TimeControl& timeControl,
264  const OpeningBook* book = nullptr,
265  int bookDepth = 256);
270  virtual QString results() const;
271 
272  public slots:
274  void start();
282  void stop();
283 
284  signals:
293  void gameStarted(ChessGame* game,
294  int number,
295  int whiteIndex,
296  int blackIndex);
310  void gameFinished(ChessGame* game,
311  int number,
312  int whiteIndex,
313  int blackIndex);
321  void finished();
322 
323  protected:
325  void setCurrentRound(int round);
327  int gamesInProgress() const;
329  TournamentPair* currentPair() const;
336  TournamentPair* pair(int player1, int player2);
343  void startGame(TournamentPair* pair);
350  virtual void onGameAboutToStart(ChessGame* game,
351  const PlayerBuilder* white,
352  const PlayerBuilder* black);
358  int playerIndex(ChessGame* game, Chess::Side side) const;
366  virtual void initializePairing() = 0;
373  virtual int gamesPerCycle() const = 0;
388  virtual TournamentPair* nextPair(int gameNumber) = 0;
395  virtual void onFinished();
403  virtual void addScore(int player, int score);
408  virtual bool areAllGamesFinished() const;
416  virtual bool hasGauntletRatingsOrder() const;
417 
418  private slots:
419  void startNextGame();
420  bool writePgn(PgnGame* pgn, int gameNumber);
421  bool writeEpd(ChessGame* game);
422  void onGameStarted(ChessGame* game);
423  void onGameFinished(ChessGame* game);
424  void onGameDestroyed(ChessGame* game);
425  void onGameStartFailed(ChessGame* game);
426 
427  private:
428  struct GameData
429  {
430  int number;
431  int whiteIndex;
432  int blackIndex;
433  };
434  struct RankingData
435  {
436  QString name;
437  int games;
438  qreal score;
439  qreal draws;
440  qreal errorMargin;
441  qreal eloDiff;
442  };
443 
444  GameManager* m_gameManager;
445  ChessGame* m_lastGame;
446  QString m_error;
447  QString m_name;
448  QString m_site;
449  QString m_variant;
450  int m_round;
451  int m_oldRound;
452  int m_nextGameNumber;
453  int m_finishedGameCount;
454  int m_savedGameCount;
455  int m_finalGameCount;
456  int m_gamesPerEncounter;
457  int m_roundMultiplier;
458  int m_startDelay;
459  int m_openingDepth;
460  int m_seedCount;
461  bool m_stopping;
462  int m_openingRepetitions;
463  OpeningPolicy m_openingPolicy;
464  bool m_recover;
465  bool m_pgnCleanup;
466  bool m_pgnWriteUnfinishedGames;
467  bool m_finished;
468  bool m_bookOwnership;
469  GameAdjudicator m_adjudicator;
470  OpeningSuite* m_openingSuite;
471  Sprt* m_sprt;
472  QFile m_pgnFile;
473  QTextStream m_pgnOut;
474  QFile m_epdFile;
475  QTextStream m_epdOut;
476  QString m_startFen;
477  int m_repetitionCounter;
478  int m_swapSides;
479  PgnGame::PgnMode m_pgnOutMode;
480  TournamentPair* m_pair;
482  QList<TournamentPlayer> m_players;
483  QMap<int, PgnGame> m_pgnGames;
484  QMap<ChessGame*, GameData*> m_gameData;
485  QVector<Chess::Move> m_openingMoves;
486 };
487 
488 #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
Shift on new encounter.
Definition: tournament.h:53
Shift on repetition count and on new encounter.
Definition: tournament.h:52
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
OpeningPolicy
Definition: tournament.h:50
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