• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kigo

  • sources
  • kde-4.14
  • kdegames
  • kigo
  • src
  • game
game.h
Go to the documentation of this file.
1 /*
2  Copyright 2008 Sascha Peilicke <sasch.pe@gmx.de>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License as
6  published by the Free Software Foundation; either version 2 of
7  the License or (at your option) version 3 or any later version
8  accepted by the membership of KDE e.V. (or its successor approved
9  by the membership of KDE e.V.), which shall act as a proxy
10  defined in Section 14 of version 3 of the license.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef KIGO_GAME_H
22 #define KIGO_GAME_H
23 
24 #include "move.h"
25 #include "player.h"
26 #include "stone.h"
27 
28 #include <QList>
29 #include <QProcess>
30 #include <QString>
31 #include <QUndoStack>
32 
33 namespace Kigo {
34 
35 class Score;
36 
60 class Game : public QObject
61 {
62  Q_OBJECT
63 
64 public:
68  enum FinalState {
69  FinalAlive = 1,
70  FinalDead,
71  FinalSeki,
72  FinalWhiteTerritory,
73  FinalBlackTerritory,
74  FinalDame,
75  FinalStateInvalid
76  };
77 
78  explicit Game(QObject *parent = 0);
79  ~Game();
80 
88  bool start(const QString &command = "gnugo --mode gtp");
89 
93  void stop();
94 
99  bool isRunning() const { return m_process.state() == QProcess::Running; }
100  QString engineName() const { return m_engineName; }
101  QString engineVersion() const { return m_engineVersion; }
102  QString engineCommand() const { return m_engineCommand; }
103  QUndoStack *undoStack() { return &m_undoStack; }
104 
108  bool init();
109 
117  bool init(const QString &fileName, int moveNumber = 0);
118 
124  bool save(const QString &fileName);
125 
131  bool setBoardSize(int size);
132  int boardSize() const { return m_boardSize; }
133 
139  bool setKomi(float komi);
140  float komi() const { return m_komi; }
141 
147  bool setFixedHandicap(int handicap);
148  int fixedHandicap() const { return m_fixedHandicap; }
149 
156  int fixedHandicapUpperBound();
157 
158  Player &currentPlayer() { return *m_currentPlayer; }
159  const Player &currentPlayer() const { return *m_currentPlayer; }
160  Player &whitePlayer() { return m_whitePlayer; }
161  const Player &whitePlayer() const { return m_whitePlayer; }
162  Player &blackPlayer() { return m_blackPlayer; }
163  const Player &blackPlayer() const { return m_blackPlayer; }
164 
165  bool playMove(const Move &move, bool undoable = true);
166  bool playMove(const Player &player, const Stone &stone = Stone(), bool undoable = true);
167  bool generateMove(const Player &player, bool undoable = true);
168  bool undoMove();
169  bool redoMove();
170 
171  int currentMoveNumber() const { return m_currentMove; }
172 
177  Move lastMove() const;
178 
183  int moveCount();
184 
188  QList<Stone> stones(const Player &player);
189 
193  QList<Move> moves(const Player &player);
194  QList<Move> moves() { return m_movesList; }
195 
201  QList<Stone> liberties(const Stone &field);
202 
206  QList<Stone> bestMoves(const Player &player);
207 
211  QList<Stone> legalMoves(const Player &player);
212 
216  int captures(const Player &player);
217 
224  FinalState finalState(const Stone &field);
225 
232  QList<Stone> finalStates(FinalState state);
233 
240  Score finalScore();
241 
246  Score estimatedScore();
247 
248  bool canRedo() const { return m_undoStack.canRedo(); }
249  bool canUndo() const { return m_undoStack.canUndo(); }
250 
251  bool isFinished() const { return m_gameFinished; }
252 
253 signals:
258  void boardInitialized();
259 
264  void boardChanged();
265 
267  void boardSizeChanged(int);
268 
270  void resigned(const Player &);
271 
272  void passMovePlayed(const Player &);
277  void consecutivePassMovesPlayed(int);
278 
280  void currentPlayerChanged(const Player &);
281 
287  void waiting(bool);
288 
290  void canRedoChanged(bool);
291 
293  void canUndoChanged(bool);
294 
295 public slots:
296  void gameSetup();
297 
298 private slots:
306  bool waitResponse(bool nonBlocking = false);
307 
311  void readyRead();
312 
313  void undoIndexChanged(int index);
314 
315 private:
316  void setCurrentPlayer(Player &player);
317 
318  QProcess m_process;
319 
320  QString m_engineName;
321  QString m_engineVersion;
322  QString m_engineCommand;
323  QString m_response;
324 
325  QList<Move> m_movesList;
326  int m_currentMove;
327  QUndoStack m_undoStack;
328  int m_lastUndoIndex;
329 
330  Player *m_currentPlayer;
331  Player m_blackPlayer;
332  Player m_whitePlayer;
333 
334  float m_komi;
335  int m_boardSize;
336  int m_fixedHandicap;
337  int m_consecutivePassMoveNumber;
338  bool m_waitAndProcessEvents;
339  bool m_gameFinished;
340 };
341 
342 } // End of namespace Kigo
343 
344 #endif
Kigo::Score
This class represents a Go score for either player.
Definition: score.h:38
Kigo::Game::canRedoChanged
void canRedoChanged(bool)
This signal is emitted when availability of redo moves changes.
Kigo::Game::finalStates
QList< Stone > finalStates(FinalState state)
Report fields with a specified final status in a finished game.
Definition: game.cpp:669
Kigo::Game::setKomi
bool setKomi(float komi)
Set the komi.
Definition: game.cpp:214
Kigo::Game::fixedHandicap
int fixedHandicap() const
Definition: game.h:148
Kigo::Game::Game
Game(QObject *parent=0)
Definition: game.cpp:51
Kigo::Game::finalState
FinalState finalState(const Stone &field)
Report the final status of a field in a finished game.
Definition: game.cpp:650
Kigo::Game::estimatedScore
Score estimatedScore()
Returns an estimate of the final score based on the current game situation.
Definition: game.cpp:706
Kigo::Game::FinalStateInvalid
The state is invalid, shows error.
Definition: game.h:75
Kigo::Game::moves
QList< Move > moves()
Definition: game.h:194
Kigo::Game::boardSizeChanged
void boardSizeChanged(int)
This signal is emitted when the board size was changed.
Kigo::Game::start
bool start(const QString &command="gnugo --mode gtp")
Connect to the given Go game game in GTP mode.
Definition: game.cpp:69
Kigo::Game::engineCommand
QString engineCommand() const
Definition: game.h:102
Kigo::Game::FinalBlackTerritory
The field belongs to the black player.
Definition: game.h:73
Kigo::Game::legalMoves
QList< Stone > legalMoves(const Player &player)
List all legal moves for either player.
Definition: game.cpp:616
Kigo::Game::isFinished
bool isFinished() const
Definition: game.h:251
Kigo::Game::gameSetup
void gameSetup()
Definition: game.cpp:769
Kigo::Game::canRedo
bool canRedo() const
Definition: game.h:248
Kigo::Game::canUndo
bool canUndo() const
Definition: game.h:249
Kigo::Game::consecutivePassMovesPlayed
void consecutivePassMovesPlayed(int)
This signal is emitted when both players played a pass move after another.
player.h
Kigo::Game::waiting
void waiting(bool)
This signal is emitted when the game starts or ends a non-blocking wait.
Kigo::Game::FinalAlive
The stone on the field is alive.
Definition: game.h:69
Kigo::Game::whitePlayer
Player & whitePlayer()
Definition: game.h:160
Kigo::Game::currentPlayer
const Player & currentPlayer() const
Definition: game.h:159
Kigo::Game::redoMove
bool redoMove()
Definition: game.cpp:481
Kigo::Game::whitePlayer
const Player & whitePlayer() const
Definition: game.h:161
QProcess
Kigo::Game::currentPlayerChanged
void currentPlayerChanged(const Player &)
This signal is emitted when the current player changes.
QObject
Kigo::Game::bestMoves
QList< Stone > bestMoves(const Player &player)
Generate a list of the best moves for a player with weights.
Definition: game.cpp:593
Kigo::Stone
This class represents a stone on a field of the game board.
Definition: stone.h:31
Kigo::Game::moveCount
int moveCount()
Returns the number of moves in the game so far.
Definition: game.cpp:518
Kigo::Game::blackPlayer
const Player & blackPlayer() const
Definition: game.h:163
Kigo::Game::finalScore
Score finalScore()
Compute the score of a finished game.
Definition: game.cpp:696
Kigo::Game::stones
QList< Stone > stones(const Player &player)
Returns a list of all stones of that player on the board.
Definition: game.cpp:531
Kigo::Game::lastMove
Move lastMove() const
Returns the last move made by either player.
Definition: game.cpp:509
QString
QList
Kigo::Game::boardInitialized
void boardInitialized()
This signal is emitted when the board is first started and can be used to trigger an update to a visu...
Kigo::Game::setBoardSize
bool setBoardSize(int size)
Set the board size to NxN.
Definition: game.cpp:189
Kigo::Game::komi
float komi() const
Definition: game.h:140
Kigo::Game::isRunning
bool isRunning() const
Check whether the Game object is connected to a Go game, running and waiting for commands to be fed w...
Definition: game.h:99
Kigo::Game::captures
int captures(const Player &player)
List the number of captures taken by either player.
Definition: game.cpp:636
Kigo::Player
The Player class holds all basic attributes of a Go player.
Definition: player.h:36
QUndoStack::canUndo
bool canUndo() const
Kigo::Game::engineVersion
QString engineVersion() const
Definition: game.h:101
Kigo::Game::currentMoveNumber
int currentMoveNumber() const
Definition: game.h:171
Kigo::Game::fixedHandicapUpperBound
int fixedHandicapUpperBound()
Returns the maximum amount fixed handicap stones placeable at the current Go board size...
Definition: game.cpp:255
Kigo::Game::engineName
QString engineName() const
Definition: game.h:100
Kigo::Game::FinalWhiteTerritory
The field belongs to the white player.
Definition: game.h:72
Kigo::Game::FinalDame
The field belongs to no player.
Definition: game.h:74
Kigo::Game::blackPlayer
Player & blackPlayer()
Definition: game.h:162
Kigo::Game::liberties
QList< Stone > liberties(const Stone &field)
Returns the positions of the liberties for the stone at 'field'.
Definition: game.cpp:577
Kigo::Game::init
bool init()
Initialize a new game.
Definition: game.cpp:110
move.h
Kigo::Game::currentPlayer
Player & currentPlayer()
Definition: game.h:158
QUndoStack::canRedo
bool canRedo() const
Kigo::Game::FinalDead
The stone on the field is dead.
Definition: game.h:70
QUndoStack
Kigo::Move
The Move class is a light-weight representation of a Go move (to be) made by a Go player...
Definition: move.h:36
Kigo::Game::resigned
void resigned(const Player &)
This signal is emitted when a player resigns.
Kigo::Game::boardSize
int boardSize() const
Definition: game.h:132
Kigo::Game::stop
void stop()
Gracefully stop and exit the Go game game.
Definition: game.cpp:102
Kigo::Game::setFixedHandicap
bool setFixedHandicap(int handicap)
Set up fixed placement handicap stones.
Definition: game.cpp:230
Kigo::Game
The Game class implements the Go game and acts as a wrapper around a remote Go Game game implementing...
Definition: game.h:60
Kigo::Game::passMovePlayed
void passMovePlayed(const Player &)
Kigo::Game::FinalState
FinalState
Enumeration of all possible final states of a field when a game is over.
Definition: game.h:68
stone.h
QObject::parent
QObject * parent() const
Kigo::Game::save
bool save(const QString &fileName)
Save the current game as a SGF file.
Definition: game.cpp:179
Kigo::Game::playMove
bool playMove(const Move &move, bool undoable=true)
Definition: game.cpp:275
Kigo::Game::undoStack
QUndoStack * undoStack()
Definition: game.h:103
Kigo::Game::undoMove
bool undoMove()
Definition: game.cpp:444
QProcess::state
QProcess::ProcessState state() const
Kigo::Game::boardChanged
void boardChanged()
This signal is emitted when the board situation changed and can be used to trigger an update to a vis...
Kigo::Game::canUndoChanged
void canUndoChanged(bool)
This signal is emitted when availability of undo moves changes.
Kigo::Game::generateMove
bool generateMove(const Player &player, bool undoable=true)
Definition: game.cpp:359
Kigo::Game::~Game
~Game()
Definition: game.cpp:64
Kigo::Game::FinalSeki
Definition: game.h:71
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:29 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kigo

Skip menu "kigo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal