Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoGameRecord Class Reference

#include <GoGame.h>

Inheritance diagram for GoGameRecord:

Inheritance graph
[legend]
List of all members.

Detailed Description

Game stored as a tree of moves.

Note:
What is wrong with this class? It exposes non-const access to its data members and therefore cannot guarantee the integrity of its state. In the future, this class should only provide read access to the board, tree, and current node pointer. All modifications to and navigation in the tree should only be possible through member functions of this class, such that it can guarantee that its invariants are met (i.e. the board position always belongs to the current node and the current node always points to a valid node in the tree).

Definition at line 39 of file GoGame.h.

Public Member Functions

 GoGameRecord (GoBoard &board)
 Create a game record for replaying games on the given board.
virtual ~GoGameRecord ()
virtual void InitFromRoot (SgNode *root, bool fTakeOwnership)
 Delete the old game record and start with a fresh one.
virtual void Init (int size, const GoRules &rules)
 Delete the old game record and start with a fresh one.
virtual void OnGoToNode (SgNode *dest)
 Hook for subclasses.
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 GoBoardBoard () const
 Get the board associated with this game record.
SgNodeRoot () const
 Return the root of this tree.
SgNodeAddMove (SgMove move, SgBlackWhite player, const SgSearchStatistics *stat=0)
 Add move to the game record.
SgNodeAddResignNode (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).
SgTimeRecordTime ()
 The time left in the game at the current position.
const SgTimeRecordTime () const
 The time left in the game at the current position.
SgNodeCurrentNode ()
 Return the current position in the tree.
const SgNodeCurrentNode () 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

 GoGameRecord (const GoGameRecord &)
 Not implemented.
GoGameRecordoperator= (const GoGameRecord &)
 Not implemented.
void DeleteTreeAndInitState ()
 Delete the tree and initialize the state associated with the position in the tree.

Private Attributes

SgNodem_current
 The position in the current tree.
GoBoardm_board
GoBoardUpdater m_updater
SgTimeRecord m_time
 A record of the clock settings and time left.
bool m_ownsTree
 Whether this game record owns the game tree.
SgNodem_oldCommentNode
 Comment display.
int m_numMovesToInsert
 Moves inserted into a line of play instead of added at the end.


Constructor & Destructor Documentation

GoGameRecord::GoGameRecord ( GoBoard board  )  [explicit]

Create a game record for replaying games on the given board.

Definition at line 59 of file GoGame.cpp.

References GoInitCheck(), and InitFromRoot().

GoGameRecord::~GoGameRecord (  )  [virtual]

Definition at line 73 of file GoGame.cpp.

References SgNode::DeleteTree(), m_current, and m_ownsTree.

GoGameRecord::GoGameRecord ( const GoGameRecord  )  [private]

Not implemented.


Member Function Documentation

SgNode * GoGameRecord::AddMove ( SgMove  move,
SgBlackWhite  player,
const SgSearchStatistics stat = 0 
)

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(), m_current, m_numMovesToInsert, m_time, SgNode::NewFather(), SgNode::NewRightMostSon(), SgTimeRecord::PlayedMove(), SgNode::RightBrother(), and SG_PROP_MOVE.

Referenced by GoGtpEngine::CmdGenMove(), GoGtpEngine::Play(), GoGame::PlayComputerMove(), and GoGame::PlayHumanMove().

SgNode * GoGameRecord::AddResignNode ( SgBlackWhite  player  ) 

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(), m_current, SgNode::NewRightMostSon(), and SG_BLACK.

Referenced by GoGtpEngine::CmdGenMove().

const GoBoard & GoGameRecord::Board (  )  const

Get the board associated with this game record.

Definition at line 193 of file GoGame.h.

References m_board.

Referenced by GoGame::CanPlayHumanMove(), and GoGame::PlayOneMove().

bool GoGameRecord::CanDeleteCurrentNode (  )  const

Definition at line 125 of file GoGame.cpp.

References CurrentNode(), and SgNode::HasFather().

bool GoGameRecord::CanGoInDirection ( SgNode::Direction  dir  )  const

Return whether there is a next node in the given direction.

Definition at line 130 of file GoGame.cpp.

References m_current, and SgNode::NodeInDirection().

Referenced by GoGameUtil::GotoBeforeMove().

SgMove GoGameRecord::CurrentMove (  )  const

Return the move of the current node.

Return NullMove if no current move.

Definition at line 136 of file GoGame.cpp.

References CurrentNode(), SgNode::Get(), SG_NULLMOVE, and SG_PROP_MOVE.

int GoGameRecord::CurrentMoveNumber (  )  const

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 m_current.

Referenced by GoGtpEngine::CheckLegal(), and GoGameUtil::GotoBeforeMove().

const SgNode * GoGameRecord::CurrentNode (  )  const

Return the current position in the tree.

Todo:
changed from protected to public because of getting the current time left.

Definition at line 219 of file GoGame.h.

References m_current.

SgNode * GoGameRecord::CurrentNode (  ) 

Return the current position in the tree.

Todo:
changed from protected to public because of getting the current time left.

Definition at line 214 of file GoGame.h.

References m_current.

Referenced by GoGtpEngine::ApplyTimeSettings(), CanDeleteCurrentNode(), GoGtpEngine::CmdPlaySequence(), GoGtpEngine::CmdSetup(), GoGtpEngine::CmdSetupPlayer(), CurrentMove(), GetPlayerName(), GetScore(), GoGameUtil::GotoBeforeMove(), GoGtpEngine::PlaceHandicap(), GoGtpEngine::Undo(), and GoGame::UpdatePlayer().

void GoGameRecord::DeleteTreeAndInitState (  )  [private]

Delete the tree and initialize the state associated with the position in the tree.

Definition at line 157 of file GoGame.cpp.

References SgNode::DeleteTree(), m_current, m_oldCommentNode, and m_ownsTree.

Referenced by Init(), and InitFromRoot().

bool GoGameRecord::EndOfGame (  )  const

Return whether the game is finished.

Definition at line 167 of file GoGame.cpp.

References GoBoardUtil::EndOfGame(), and m_board.

std::string GoGameRecord::GetPlayerName ( SgBlackWhite  player  )  const [virtual]

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 CurrentNode(), SgNode::Get(), SgNode::HasProp(), SgProp::PlayerProp(), SG_PROP_PLAYER_BLACK, and SgNode::TopProp().

bool GoGameRecord::GetScore ( int *  score  )  const [virtual]

Return the current score (black minus white).

Todo:
: in what units? Return true if there's a score recorded in the tree, otherwise false. Override to return information about the score from a player.

Definition at line 187 of file GoGame.cpp.

References CurrentNode(), SgNode::GetIntProp(), SgNode::HasProp(), SG_ASSERT, SG_PROP_VALUE, and SgNode::TopProp().

void GoGameRecord::GoInDirection ( SgNode::Direction  dir  ) 

Play to the next node in the given direction.

Definition at line 200 of file GoGame.cpp.

References GoToNode(), m_current, and SgNode::NodeInDirection().

Referenced by GoGameUtil::GotoBeforeMove().

void GoGameRecord::GoToNode ( SgNode dest  ) 

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(), m_board, m_current, m_time, m_updater, OnGoToNode(), GoBoardUtil::RemainingChineseHandicap(), SG_BLACK, Time(), GoBoardUpdater::Update(), and SgNodeUtil::UpdateTime().

Referenced by GoGtpEngine::CmdGenMove(), GoGtpEngine::CmdPlaySequence(), GoGtpEngine::CmdSetup(), GoInDirection(), Init(), InitFromRoot(), GoGtpEngine::PlaceHandicap(), GoGtpEngine::Play(), GoGame::PlayComputerMove(), GoGame::PlayHumanMove(), and GoGtpEngine::Undo().

void GoGameRecord::Init ( int  size,
const GoRules rules 
) [virtual]

Delete the old game record and start with a fresh one.

Init the board with the given parameters, and create a root node to start with.

Reimplemented in GoGame.

Definition at line 218 of file GoGame.cpp.

References SgNode::Add(), DeleteTreeAndInitState(), GoToNode(), m_board, m_ownsTree, OnInitBoard(), OnInitHandicap(), SG_PROP_SIZE, and GoBoard::Size().

Referenced by GoGame::Init().

void GoGameRecord::InitFromRoot ( SgNode root,
bool  fTakeOwnership 
) [virtual]

Delete the old game record and start with a fresh one.

If 'root' is 0, create a root node to start with, otherwise use the game tree passed in 'root'. If 'fTakeOwnership', the game record will delete this tree when it's destroyed, otherwise the client is reponsible for deleting the tree.

Todo:
AR: change comment

Reimplemented in GoGame.

Definition at line 238 of file GoGame.cpp.

References SgNode::Add(), DeleteTreeAndInitState(), ForceInRange(), SgNode::Get(), GO_DEFAULT_SIZE, GoToNode(), GoRules::Handicap(), GoRules::Komi(), m_board, m_ownsTree, OnInitBoard(), GoBoard::Rules(), SG_MAX_SIZE, SG_MIN_SIZE, SG_PROP_GAME, SG_PROP_SIZE, and GoBoard::Size().

Referenced by GoGameRecord(), GoGame::Init(), and GoGame::InitFromRoot().

void GoGameRecord::OnGoToNode ( SgNode dest  )  [virtual]

Hook for subclasses.

Default implementation does nothing.

Reimplemented in GoGame.

Definition at line 276 of file GoGame.cpp.

References SG_UNUSED().

Referenced by GoToNode().

void GoGameRecord::OnInitBoard ( int  size,
const GoRules rules 
) [virtual]

Override to initialize other boards in derived classes.

See also:
GoBoard

Definition at line 281 of file GoGame.cpp.

References GoBoard::Init(), and m_board.

Referenced by Init(), and InitFromRoot().

void GoGameRecord::OnInitHandicap ( const GoRules rules,
SgNode root 
) [virtual]

Definition at line 286 of file GoGame.cpp.

References SgNode::Add(), AddHandicap(), GoRules::Handicap(), GoRules::JapaneseHandicap(), 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 Init().

GoGameRecord& GoGameRecord::operator= ( const GoGameRecord  )  [private]

Not implemented.

bool GoGameRecord::OwnsTree (  )  const

Whether this game record owns the game tree.

Definition at line 224 of file GoGame.h.

References m_ownsTree.

SgNode & GoGameRecord::Root (  )  const

Return the root of this tree.

Definition at line 198 of file GoGame.h.

References m_current, SgNode::Root(), and SG_ASSERT.

Referenced by GoGtpEngine::AddPlayerProp(), GoGtpEngine::ApplyTimeSettings(), GoGtpEngine::CmdKomi(), GoGtpEngine::CmdSetInfo(), GoGameUtil::GotoBeforeMove(), and GoGtpEngine::Init().

void GoGameRecord::SetToPlay ( SgBlackWhite  player  ) 

Set the current player.

Definition at line 352 of file GoGame.cpp.

References SgNode::Add(), SgTimeRecord::EnterNode(), m_board, m_current, m_time, GoBoard::SetToPlay(), SG_PROP_PLAYER, and GoBoard::ToPlay().

const SgTimeRecord & GoGameRecord::Time (  )  const

The time left in the game at the current position.

Definition at line 209 of file GoGame.h.

References m_time.

SgTimeRecord & GoGameRecord::Time (  ) 

The time left in the game at the current position.

Definition at line 204 of file GoGame.h.

References m_time.

Referenced by GoGtpEngine::ApplyTimeSettings(), GoGame::ClockIsRunning(), GoGtpEngine::CmdClock(), GoGtpEngine::CmdParam(), GoGtpEngine::CmdTimeLeft(), GoGtpEngine::GenMove(), GoToNode(), and GoGame::TurnClockOn().


Member Data Documentation

GoBoard& GoGameRecord::m_board [private]

Definition at line 165 of file GoGame.h.

Referenced by Board(), EndOfGame(), GoToNode(), Init(), InitFromRoot(), OnInitBoard(), OnInitHandicap(), and SetToPlay().

SgNode* GoGameRecord::m_current [private]

The position in the current tree.

Definition at line 163 of file GoGame.h.

Referenced by AddMove(), AddResignNode(), CanGoInDirection(), CurrentMoveNumber(), CurrentNode(), DeleteTreeAndInitState(), GoInDirection(), GoToNode(), Root(), SetToPlay(), and ~GoGameRecord().

int GoGameRecord::m_numMovesToInsert [private]

Moves inserted into a line of play instead of added at the end.

Definition at line 179 of file GoGame.h.

Referenced by AddMove().

SgNode* GoGameRecord::m_oldCommentNode [private]

Comment display.

Definition at line 176 of file GoGame.h.

Referenced by DeleteTreeAndInitState().

bool GoGameRecord::m_ownsTree [private]

Whether this game record owns the game tree.

Definition at line 173 of file GoGame.h.

Referenced by DeleteTreeAndInitState(), Init(), InitFromRoot(), OwnsTree(), and ~GoGameRecord().

SgTimeRecord GoGameRecord::m_time [private]

A record of the clock settings and time left.

Definition at line 170 of file GoGame.h.

Referenced by AddMove(), GoToNode(), SetToPlay(), and Time().

GoBoardUpdater GoGameRecord::m_updater [private]

Definition at line 167 of file GoGame.h.

Referenced by GoToNode().


The documentation for this class was generated from the following files:


17 Jun 2010 Doxygen 1.4.7