#include <GoGame.h>
Inheritance diagram for GoGame:
A GoGame object handles the synchronization between the players and the board they're playing on, and keeps track of the time.
Definition at line 250 of file GoGame.h.
Public Member Functions | |
GoGame (GoBoard &board) | |
virtual | ~GoGame () |
virtual void | InitFromRoot (SgNode *root, bool fTakeOwnership) |
Needed to avoid hiding of inherited virtual function by the other variants of GoGame::Init. | |
void | Init (int size, const GoRules &rules) |
Needed to avoid hiding of inherited virtual function by the other variants of GoGame::Init. | |
void | Init (SgNode *root, bool fTakeOwnership, bool fDeletePlayers) |
void | Init (int size, const GoRules &rules, bool fDeletePlayers) |
void | OnGoToNode (SgNode *dest) |
Hook for subclasses. | |
void | TurnClockOn (bool turnOn) |
Turn the clock on or off. | |
bool | ClockIsRunning () const |
Return whether the clock is running (not stopped or suspended). | |
void | SetPlayer (SgBlackWhite color, GoPlayer *player) |
Set the player 'color' to the player algorithm 'player'. | |
void | DeletePlayer (SgBlackWhite color) |
Delete the player 'color' (set it to interactive input). | |
bool | CanPlayHumanMove (SgMove move, SgBlackWhite player) const |
Whether the human move at 'move' can be played at this point. | |
bool | PlayHumanMove (SgMove move, SgBlackWhite player) |
Adds a move to the game record and tells all other players to update their boards. | |
void | PlayComputerMove (const GoPlayerMove *playerMove) |
GoPlayer * | Player (SgBlackWhite player) |
GoPlayerMove | PlayOneMove (SgBlackWhite playerColor) |
Compute and play one move using the given player. | |
virtual void | OnInitBoard (int size, const GoRules &rules) |
Override to initialize other boards in derived classes. | |
virtual void | OnInitHandicap (const GoRules &rules, SgNode *root) |
const GoBoard & | Board () const |
Get the board associated with this game record. | |
SgNode & | Root () const |
Return the root of this tree. | |
SgNode * | AddMove (SgMove move, SgBlackWhite player, const SgSearchStatistics *stat=0) |
Add move to the game record. | |
SgNode * | AddResignNode (SgBlackWhite player) |
Add a node with a comment that a player resigned. | |
void | GoToNode (SgNode *dest) |
Play to the given node. | |
void | GoInDirection (SgNode::Direction dir) |
Play to the next node in the given direction. | |
bool | CanGoInDirection (SgNode::Direction dir) const |
Return whether there is a next node in the given direction. | |
void | SetToPlay (SgBlackWhite player) |
Set the current player. | |
bool | EndOfGame () const |
Return whether the game is finished. | |
virtual std::string | GetPlayerName (SgBlackWhite player) const |
Get the name of the given player. | |
virtual bool | GetScore (int *score) const |
Return the current score (black minus white). | |
SgTimeRecord & | Time () |
The time left in the game at the current position. | |
const SgTimeRecord & | Time () const |
The time left in the game at the current position. | |
SgNode * | CurrentNode () |
Return the current position in the tree. | |
const SgNode * | CurrentNode () const |
Return the current position in the tree. | |
bool | OwnsTree () const |
Whether this game record owns the game tree. | |
bool | CanDeleteCurrentNode () const |
SgMove | CurrentMove () const |
Return the move of the current node. | |
int | CurrentMoveNumber () const |
Get the number of moves since root or last node with setup properties. | |
Private Member Functions | |
GoGame (const GoGame &) | |
Not implemented. | |
GoGame & | operator= (const GoGame &) |
Not implemented. | |
void | UpdatePlayer (SgBlackWhite color) |
void | UpdatePlayers () |
Private Attributes | |
SgBWArray< GoPlayer * > | m_player |
Black and white player. |
GoGame::GoGame | ( | GoBoard & | board | ) | [explicit] |
Definition at line 396 of file GoGame.cpp.
GoGame::~GoGame | ( | ) | [virtual] |
GoGame::GoGame | ( | const GoGame & | ) | [private] |
Not implemented.
SgNode * GoGameRecord::AddMove | ( | SgMove | move, | |
SgBlackWhite | player, | |||
const SgSearchStatistics * | stat = 0 | |||
) | [inherited] |
Add move to the game record.
Add move as the next move at the current position. If a node with that move already exists, then don't add a new one. Return the node with that move. Also add any statistics from 'stat' and time left to that node.
Definition at line 81 of file GoGame.cpp.
References SgNode::AddMoveProp(), AddStatisticsToNode(), SgNode::Get(), SgNode::HasSon(), SgPropMove::IsPlayer(), SgPropMove::IsValue(), SgNode::LeftMostSon(), GoGameRecord::m_current, GoGameRecord::m_numMovesToInsert, GoGameRecord::m_time, SgNode::NewFather(), SgNode::NewRightMostSon(), SgTimeRecord::PlayedMove(), SgNode::RightBrother(), and SG_PROP_MOVE.
Referenced by GoGtpEngine::CmdGenMove(), GoGtpEngine::Play(), PlayComputerMove(), and PlayHumanMove().
SgNode * GoGameRecord::AddResignNode | ( | SgBlackWhite | player | ) | [inherited] |
Add a node with a comment that a player resigned.
For informational purposes only, the resign node will not be made the current node.
Definition at line 116 of file GoGame.cpp.
References SgNode::AddComment(), GoGameRecord::m_current, SgNode::NewRightMostSon(), and SG_BLACK.
Referenced by GoGtpEngine::CmdGenMove().
const GoBoard & GoGameRecord::Board | ( | ) | const [inherited] |
Get the board associated with this game record.
Definition at line 193 of file GoGame.h.
References GoGameRecord::m_board.
Referenced by CanPlayHumanMove(), and PlayOneMove().
bool GoGameRecord::CanDeleteCurrentNode | ( | ) | const [inherited] |
Definition at line 125 of file GoGame.cpp.
References GoGameRecord::CurrentNode(), and SgNode::HasFather().
bool GoGameRecord::CanGoInDirection | ( | SgNode::Direction | dir | ) | const [inherited] |
Return whether there is a next node in the given direction.
Definition at line 130 of file GoGame.cpp.
References GoGameRecord::m_current, and SgNode::NodeInDirection().
Referenced by GoGameUtil::GotoBeforeMove().
bool GoGame::CanPlayHumanMove | ( | SgMove | move, | |
SgBlackWhite | player | |||
) | const |
Whether the human move at 'move' can be played at this point.
The move must be legal, and either it's a human player to play or the clock is inactive.
Definition at line 408 of file GoGame.cpp.
References GoGameRecord::Board(), ClockIsRunning(), GoBoard::IsLegal(), and m_player.
Referenced by PlayHumanMove().
bool GoGame::ClockIsRunning | ( | ) | const |
Return whether the clock is running (not stopped or suspended).
Definition at line 284 of file GoGame.h.
References SgTimeRecord::ClockIsRunning(), and GoGameRecord::Time().
Referenced by CanPlayHumanMove().
SgMove GoGameRecord::CurrentMove | ( | ) | const [inherited] |
Return the move of the current node.
Return NullMove if no current move.
Definition at line 136 of file GoGame.cpp.
References GoGameRecord::CurrentNode(), SgNode::Get(), SG_NULLMOVE, and SG_PROP_MOVE.
int GoGameRecord::CurrentMoveNumber | ( | ) | const [inherited] |
Get the number of moves since root or last node with setup properties.
Definition at line 149 of file GoGame.cpp.
References SgNodeUtil::GetMoveNumber(), and GoGameRecord::m_current.
Referenced by GoGtpEngine::CheckLegal(), and GoGameUtil::GotoBeforeMove().
const SgNode * GoGameRecord::CurrentNode | ( | ) | const [inherited] |
Return the current position in the tree.
Definition at line 219 of file GoGame.h.
References GoGameRecord::m_current.
SgNode * GoGameRecord::CurrentNode | ( | ) | [inherited] |
Return the current position in the tree.
Definition at line 214 of file GoGame.h.
References GoGameRecord::m_current.
Referenced by GoGtpEngine::ApplyTimeSettings(), GoGameRecord::CanDeleteCurrentNode(), GoGtpEngine::CmdPlaySequence(), GoGtpEngine::CmdSetup(), GoGtpEngine::CmdSetupPlayer(), GoGameRecord::CurrentMove(), GoGameRecord::GetPlayerName(), GoGameRecord::GetScore(), GoGameUtil::GotoBeforeMove(), GoGtpEngine::PlaceHandicap(), GoGtpEngine::Undo(), and UpdatePlayer().
void GoGame::DeletePlayer | ( | SgBlackWhite | color | ) |
Delete the player 'color' (set it to interactive input).
Definition at line 416 of file GoGame.cpp.
References m_player, SG_ASSERT_BW, SG_BLACK, and SG_WHITE.
Referenced by Init(), SetPlayer(), and ~GoGame().
bool GoGameRecord::EndOfGame | ( | ) | const [inherited] |
Return whether the game is finished.
Definition at line 167 of file GoGame.cpp.
References GoBoardUtil::EndOfGame(), and GoGameRecord::m_board.
std::string GoGameRecord::GetPlayerName | ( | SgBlackWhite | player | ) | const [virtual, inherited] |
Get the name of the given player.
Return the blank string if unknown. Override to get information from an ongoing game rather than fron the game record.
Definition at line 172 of file GoGame.cpp.
References GoGameRecord::CurrentNode(), SgNode::Get(), SgNode::HasProp(), SgProp::PlayerProp(), SG_PROP_PLAYER_BLACK, and SgNode::TopProp().
bool GoGameRecord::GetScore | ( | int * | score | ) | const [virtual, inherited] |
Return the current score (black minus white).
Definition at line 187 of file GoGame.cpp.
References GoGameRecord::CurrentNode(), SgNode::GetIntProp(), SgNode::HasProp(), SG_ASSERT, SG_PROP_VALUE, and SgNode::TopProp().
void GoGameRecord::GoInDirection | ( | SgNode::Direction | dir | ) | [inherited] |
Play to the next node in the given direction.
Definition at line 200 of file GoGame.cpp.
References GoGameRecord::GoToNode(), GoGameRecord::m_current, and SgNode::NodeInDirection().
Referenced by GoGameUtil::GotoBeforeMove().
void GoGameRecord::GoToNode | ( | SgNode * | dest | ) | [inherited] |
Play to the given node.
dest
must be in this tree, or 0. Also updates the clock.
Definition at line 207 of file GoGame.cpp.
References SgTimeRecord::EnterNode(), GoGameRecord::m_board, GoGameRecord::m_current, GoGameRecord::m_time, GoGameRecord::m_updater, GoGameRecord::OnGoToNode(), GoBoardUtil::RemainingChineseHandicap(), SG_BLACK, GoGameRecord::Time(), GoBoardUpdater::Update(), and SgNodeUtil::UpdateTime().
Referenced by GoGtpEngine::CmdGenMove(), GoGtpEngine::CmdPlaySequence(), GoGtpEngine::CmdSetup(), GoGameRecord::GoInDirection(), GoGameRecord::Init(), GoGameRecord::InitFromRoot(), GoGtpEngine::PlaceHandicap(), GoGtpEngine::Play(), PlayComputerMove(), PlayHumanMove(), and GoGtpEngine::Undo().
void GoGame::Init | ( | int | size, | |
const GoRules & | rules, | |||
bool | fDeletePlayers | |||
) |
Definition at line 447 of file GoGame.cpp.
References DeletePlayer(), GoGameRecord::Init(), SG_BLACK, SG_WHITE, and UpdatePlayers().
void GoGame::Init | ( | SgNode * | root, | |
bool | fTakeOwnership, | |||
bool | fDeletePlayers | |||
) |
Definition at line 436 of file GoGame.cpp.
References DeletePlayer(), GoGameRecord::InitFromRoot(), SG_BLACK, SG_WHITE, and UpdatePlayers().
void GoGame::Init | ( | int | size, | |
const GoRules & | rules | |||
) | [virtual] |
Needed to avoid hiding of inherited virtual function by the other variants of GoGame::Init.
Reimplemented from GoGameRecord.
Definition at line 430 of file GoGame.cpp.
References GoGameRecord::Init(), and UpdatePlayers().
Referenced by GoGtpEngine::CmdLoadSgf(), and GoGtpEngine::Init().
virtual void GoGame::InitFromRoot | ( | SgNode * | root, | |
bool | fTakeOwnership | |||
) | [virtual] |
Needed to avoid hiding of inherited virtual function by the other variants of GoGame::Init.
Reimplemented from GoGameRecord.
Definition at line 261 of file GoGame.h.
References GoGameRecord::InitFromRoot().
void GoGame::OnGoToNode | ( | SgNode * | dest | ) | [virtual] |
Hook for subclasses.
Default implementation does nothing.
Reimplemented from GoGameRecord.
Definition at line 458 of file GoGame.cpp.
References SG_UNUSED(), and UpdatePlayers().
void GoGameRecord::OnInitBoard | ( | int | size, | |
const GoRules & | rules | |||
) | [virtual, inherited] |
Override to initialize other boards in derived classes.
Definition at line 281 of file GoGame.cpp.
References GoBoard::Init(), and GoGameRecord::m_board.
Referenced by GoGameRecord::Init(), and GoGameRecord::InitFromRoot().
Definition at line 286 of file GoGame.cpp.
References SgNode::Add(), AddHandicap(), GoRules::Handicap(), GoRules::JapaneseHandicap(), GoGameRecord::m_board, SgPointUtil::Pt(), SgVector< T >::PushBack(), SG_PROP_ADD_BLACK, SG_PROP_CHINESE, SG_PROP_HANDICAP, SG_PROP_PLAYER, SG_WHITE, and GoBoard::Size().
Referenced by GoGameRecord::Init().
bool GoGameRecord::OwnsTree | ( | ) | const [inherited] |
Whether this game record owns the game tree.
Definition at line 224 of file GoGame.h.
References GoGameRecord::m_ownsTree.
void GoGame::PlayComputerMove | ( | const GoPlayerMove * | playerMove | ) |
Definition at line 464 of file GoGame.cpp.
References GoGameRecord::AddMove(), GoPlayerMove::Color(), GoGameRecord::GoToNode(), and GoPlayerMove::Point().
GoPlayer * GoGame::Player | ( | SgBlackWhite | player | ) |
bool GoGame::PlayHumanMove | ( | SgMove | move, | |
SgBlackWhite | player | |||
) |
Adds a move to the game record and tells all other players to update their boards.
Returns whether the move was added to the game record.
Definition at line 483 of file GoGame.cpp.
References GoGameRecord::AddMove(), CanPlayHumanMove(), and GoGameRecord::GoToNode().
GoPlayerMove GoGame::PlayOneMove | ( | SgBlackWhite | playerColor | ) |
Compute and play one move using the given player.
Definition at line 472 of file GoGame.cpp.
References GoGameRecord::Board(), GoPlayer::GenMove(), m_player, GoBoard::ToPlay(), TurnClockOn(), and UpdatePlayer().
SgNode & GoGameRecord::Root | ( | ) | const [inherited] |
Return the root of this tree.
Definition at line 198 of file GoGame.h.
References GoGameRecord::m_current, SgNode::Root(), and SG_ASSERT.
Referenced by GoGtpEngine::AddPlayerProp(), GoGtpEngine::ApplyTimeSettings(), GoGtpEngine::CmdKomi(), GoGtpEngine::CmdSetInfo(), GoGameUtil::GotoBeforeMove(), and GoGtpEngine::Init().
void GoGame::SetPlayer | ( | SgBlackWhite | color, | |
GoPlayer * | player | |||
) |
Set the player 'color' to the player algorithm 'player'.
The old player of that color is stopped and deleted, and the new player is initialized to the current board state. A 0 player means user interaction.
Definition at line 496 of file GoGame.cpp.
References DeletePlayer(), m_player, SG_ASSERT_BW, SG_BLACK, SG_WHITE, and UpdatePlayers().
Referenced by GoGtpEngine::SetPlayer().
void GoGameRecord::SetToPlay | ( | SgBlackWhite | player | ) | [inherited] |
Set the current player.
Definition at line 352 of file GoGame.cpp.
References SgNode::Add(), SgTimeRecord::EnterNode(), GoGameRecord::m_board, GoGameRecord::m_current, GoGameRecord::m_time, GoBoard::SetToPlay(), SG_PROP_PLAYER, and GoBoard::ToPlay().
const SgTimeRecord & GoGameRecord::Time | ( | ) | const [inherited] |
The time left in the game at the current position.
Definition at line 209 of file GoGame.h.
References GoGameRecord::m_time.
SgTimeRecord & GoGameRecord::Time | ( | ) | [inherited] |
The time left in the game at the current position.
Definition at line 204 of file GoGame.h.
References GoGameRecord::m_time.
Referenced by GoGtpEngine::ApplyTimeSettings(), ClockIsRunning(), GoGtpEngine::CmdClock(), GoGtpEngine::CmdParam(), GoGtpEngine::CmdTimeLeft(), GoGtpEngine::GenMove(), GoGameRecord::GoToNode(), and TurnClockOn().
void GoGame::TurnClockOn | ( | bool | turnOn | ) |
Turn the clock on or off.
Call this method instead of Time().TurnClockOn so that computer player is started and stopped appropriately.
Definition at line 505 of file GoGame.cpp.
References GoGameRecord::Time(), and SgTimeRecord::TurnClockOn().
Referenced by GoGtpEngine::ApplyTimeSettings(), and PlayOneMove().
void GoGame::UpdatePlayer | ( | SgBlackWhite | color | ) | [private] |
Definition at line 510 of file GoGame.cpp.
References GoGameRecord::CurrentNode(), m_player, GoPlayer::SetCurrentNode(), and GoBoardSynchronizer::UpdateSubscriber().
Referenced by PlayOneMove(), and UpdatePlayers().
void GoGame::UpdatePlayers | ( | ) | [private] |
Definition at line 519 of file GoGame.cpp.
References m_player, SG_BLACK, SG_WHITE, and UpdatePlayer().
Referenced by Init(), OnGoToNode(), and SetPlayer().
SgBWArray<GoPlayer*> GoGame::m_player [private] |
Black and white player.
Definition at line 321 of file GoGame.h.
Referenced by CanPlayHumanMove(), DeletePlayer(), Player(), PlayOneMove(), SetPlayer(), UpdatePlayer(), and UpdatePlayers().