Player. More...
#include <GoPlayer.h>
Public Member Functions | |
GoPlayer (const GoBoard &bd) | |
Constructor. | |
virtual | ~GoPlayer () |
GoBoard & | Board () |
Deprecated. | |
const GoBoard & | Board () const |
The player's own Go board. | |
virtual SgPoint | GenMove (const SgTimeRecord &time, SgBlackWhite toPlay)=0 |
Generate a move. | |
virtual std::string | Name () const |
Get the name of this player. | |
SgNode * | CurrentNode () const |
Get node for appending search traces. | |
void | ClearSearchTraces () |
SgNode * | TransferSearchTraces () |
Get node with search traces and transfer ownership to the caller. | |
virtual int | MoveValue (SgPoint p) |
Return value for a move. | |
virtual void | OnGameFinished () |
Inform the player that the game was finished. | |
virtual void | OnNewGame () |
Inform the player that a new game was started. | |
virtual void | Ponder () |
Think during opponent's time. | |
int | Variant () const |
See m_variant. | |
void | SetVariant (int variant) |
See m_variant. | |
void | SetSubscriber (GoBoard &subscriber) |
Set the board that will subscribe to all the changes of the publisher. | |
void | UpdateSubscriber () |
Update the subscriber board. | |
Protected Member Functions | |
Hook functions for incremental update events | |
virtual void | OnBoardChange () |
Board was initialized with new size. | |
virtual void | PrePlay (GoPlayerMove move) |
Move about to be executed. | |
virtual void | OnPlay (GoPlayerMove move) |
Move was executed. | |
virtual void | PreUndo () |
Move about to be undone. | |
virtual void | OnUndo () |
Move was undone. | |
Protected Attributes | |
SgNode * | m_currentNode |
Node in game tree. | |
Private Member Functions | |
GoPlayer (const GoPlayer &) | |
Not implemented. | |
GoPlayer & | operator= (const GoPlayer &) |
Not implemented. | |
Private Attributes | |
GoBoard | m_bd |
See Board(). | |
int | m_variant |
Player variant. |
Player.
The player owns an internal Go board for computations during move generation. However, the player is linked to an external game board and needs to synchronize its internal board to the game board by calling UpdateSubscriber() inherited from its parent class GoBoardSynchronizer before calling GoPlayer::GenMove()
Definition at line 34 of file GoPlayer.h.
GoPlayer::GoPlayer | ( | const GoBoard & | bd | ) |
Constructor.
bd | The external game board. |
Definition at line 17 of file GoPlayer.cpp.
References ClearSearchTraces(), m_bd, and GoBoardSynchronizer::SetSubscriber().
GoPlayer::~GoPlayer | ( | ) | [virtual] |
Definition at line 27 of file GoPlayer.cpp.
References SgNode::DeleteTree(), and m_currentNode.
GoPlayer::GoPlayer | ( | const GoPlayer & | ) | [private] |
Not implemented.
GoBoard & GoPlayer::Board | ( | ) |
Deprecated.
Non-const access to player board will be removed in the future.
Definition at line 141 of file GoPlayer.h.
References m_bd.
Referenced by GoGtpEngine::CmdPlaceFreeHandicap(), and GoGtpEngine::DumpState().
const GoBoard & GoPlayer::Board | ( | ) | const |
void GoPlayer::ClearSearchTraces | ( | ) |
Definition at line 33 of file GoPlayer.cpp.
References SgNode::AddComment(), SgNode::DeleteTree(), and m_currentNode.
Referenced by GoGtpEngine::GenMove(), GoPlayer(), and TransferSearchTraces().
SgNode * GoPlayer::CurrentNode | ( | ) | const |
Get node for appending search traces.
Definition at line 151 of file GoPlayer.h.
References m_currentNode.
virtual SgPoint GoPlayer::GenMove | ( | const SgTimeRecord & | time, | |
SgBlackWhite | toPlay | |||
) | [pure virtual] |
Generate a move.
Referenced by GoGtpEngine::GenMove().
int GoPlayer::MoveValue | ( | SgPoint | p | ) | [virtual] |
Return value for a move.
Not all players assign values to moves. If a player cannot score moves in general, or cannot score this move in particular, it should return numeric_limits<int>::min() (which is what the default implementation does). Values can be positive or negative; better moves should have higher values; the units of the values are not specified.
Definition at line 41 of file GoPlayer.cpp.
References SG_UNUSED().
Referenced by GoGtpEngine::CmdAllMoveValues().
std::string GoPlayer::Name | ( | ) | const [virtual] |
Get the name of this player.
Default implementation returns "Unknown"
Definition at line 47 of file GoPlayer.cpp.
Referenced by GoGtpEngine::CmdName(), and GoGtpEngine::GenMove().
void GoBoardSynchronizer::OnBoardChange | ( | ) | [protected, virtual, inherited] |
Board was initialized with new size.
Default implementation does nothing.
Definition at line 48 of file GoBoardSynchronizer.cpp.
Referenced by GoBoardSynchronizer::UpdateFromInit().
void GoPlayer::OnGameFinished | ( | ) | [virtual] |
Inform the player that the game was finished.
This function gives the player the opportunity to do some work at the end of a game, for example perform some learning. However it is not guaranteed that this function will be called at all, the player should not rely on it. The reason is that a game start and end is not always well-defined (setup, undo, etc.) For example, it will be called in the GTP interface if after a change on the board GoBoardUtil::EndOfGame() is true. The default implementation does nothing.
Definition at line 52 of file GoPlayer.cpp.
Referenced by GoGtpEngine::GameFinished().
void GoPlayer::OnNewGame | ( | ) | [virtual] |
Inform the player that a new game was started.
This function gives the player the opportunity to clear some cached data, that is useful only within the same game. However it is not guaranteed that this function will be called at all, the player should not rely on it. The reason is that a game start and end is not always well-defined (setup, undo, etc.) For example, it will be called in the GTP interface in GoGtpEngine::Init(), or on the clear_board and loadsgf commands. The default implementation does nothing.
Definition at line 56 of file GoPlayer.cpp.
Referenced by GoGtpEngine::CmdClearBoard(), GoGtpEngine::CmdLoadSgf(), and GoGtpEngine::SetPlayer().
void GoBoardSynchronizer::OnPlay | ( | GoPlayerMove | move | ) | [protected, virtual, inherited] |
Move was executed.
Default implementation does nothing.
Definition at line 57 of file GoBoardSynchronizer.cpp.
References SG_UNUSED().
Referenced by GoBoardSynchronizer::ExecuteSubscriber().
void GoBoardSynchronizer::OnUndo | ( | ) | [protected, virtual, inherited] |
Move was undone.
Default implementation does nothing.
Definition at line 66 of file GoBoardSynchronizer.cpp.
Referenced by GoBoardSynchronizer::UpdateIncremental().
void GoPlayer::Ponder | ( | ) | [virtual] |
Think during opponent's time.
This function should poll SgUserAbort() and return immediately if it returns true. It is good style to enable pondering in the player with a parameter and return immediately if it is not enabled. If it is enabled, it should stop after some resource limit is reached to avoid that a program is hogging the CPU if it is just waiting for commands. The function Ponder() is typically called from a different thread but without overlap with other uses of the player, so the player does not have to care about thread-safety. Default implementation does nothing and returns immediately.
Definition at line 60 of file GoPlayer.cpp.
void GoBoardSynchronizer::PrePlay | ( | GoPlayerMove | move | ) | [protected, virtual, inherited] |
Move about to be executed.
Default implementation does nothing.
Definition at line 52 of file GoBoardSynchronizer.cpp.
References SG_UNUSED().
Referenced by GoBoardSynchronizer::ExecuteSubscriber().
void GoBoardSynchronizer::PreUndo | ( | ) | [protected, virtual, inherited] |
Move about to be undone.
Default implementation does nothing.
Definition at line 62 of file GoBoardSynchronizer.cpp.
Referenced by GoBoardSynchronizer::UpdateIncremental().
void GoBoardSynchronizer::SetSubscriber | ( | GoBoard & | subscriber | ) | [inherited] |
Set the board that will subscribe to all the changes of the publisher.
Can only be called once.
Definition at line 24 of file GoBoardSynchronizer.cpp.
References GoBoardSynchronizer::m_subscriber, and SG_ASSERT.
Referenced by GoAutoBookState::GoAutoBookState(), and GoPlayer().
void GoPlayer::SetVariant | ( | int | variant | ) |
SgNode * GoPlayer::TransferSearchTraces | ( | ) |
Get node with search traces and transfer ownership to the caller.
Definition at line 64 of file GoPlayer.cpp.
References ClearSearchTraces(), m_currentNode, and SgNode::NumSons().
Referenced by GoGtpEngine::GenMove().
void GoBoardSynchronizer::UpdateSubscriber | ( | ) | [inherited] |
Update the subscriber board.
Calls Init, Play, Undo and/or SetToPlay to update the subscriber to the current state of the publisher. If no subscriber was set with SetSubscriber, this function does nothing.
Definition at line 96 of file GoBoardSynchronizer.cpp.
References GoBoard::GetHashCode(), GoBoardSynchronizer::m_publisher, GoBoardSynchronizer::m_subscriber, GoBoard::Rules(), GoBoard::Setup(), SG_ASSERT, GoBoard::Size(), GoBoardSynchronizer::UpdateFromInit(), GoBoardSynchronizer::UpdateIncremental(), and GoBoardSynchronizer::UpdateToPlay().
Referenced by GoGtpEngine::BoardChanged(), GoGtpEngine::RulesChanged(), GoGtpEngine::SetPlayer(), and GoAutoBookState::Synchronize().
int GoPlayer::Variant | ( | ) | const |
GoBoard GoPlayer::m_bd [private] |
SgNode* GoPlayer::m_currentNode [protected] |
Node in game tree.
Used for appending search traces
Definition at line 122 of file GoPlayer.h.
Referenced by ClearSearchTraces(), CurrentNode(), TransferSearchTraces(), and ~GoPlayer().
int GoPlayer::m_variant [private] |
Player variant.
Used for short-term testing of small modifications. The default variant is 0. Do not use to create significantly different players - implement a new player instead.
Definition at line 132 of file GoPlayer.h.
Referenced by SetVariant(), and Variant().