Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgUctThreadState Class Reference
[Monte Carlo tree search]

#include <SgUctSearch.h>

List of all members.


Detailed Description

Base class for the thread state.

Subclasses must be thread-safe, it must be possible to use different instances of this class in different threads (after construction, the constructor does not need to be thread safe). Beware not to use classes that are not thread-safe, because they use global variables (e.g. SgRandom::Global())

Note:
Technically it is possible to use a non-thread safe implementation of subclasses, as long as the search is run with only one thread.

Definition at line 290 of file SgUctSearch.h.

Public Member Functions

 SgUctThreadState (size_t threadId, int moveRange=0)
virtual ~SgUctThreadState ()
Pure virtual functions
virtual float Evaluate ()=0
 Evaluate end-of-game position.
virtual void Execute (SgMove move)=0
 Execute a move.
virtual void ExecutePlayout (SgMove move)=0
 Execute a move in the playout phase.
virtual bool GenerateAllMoves (std::size_t count, std::vector< SgMoveInfo > &moves, SgProvenNodeType &provenType)=0
 Generate moves.
virtual SgMove GeneratePlayoutMove (bool &skipRaveUpdate)=0
 Generate random move.
virtual void StartSearch ()=0
 Start search.
virtual void TakeBackInTree (std::size_t nuMoves)=0
 Take back moves played in the in-tree phase.
virtual void TakeBackPlayout (std::size_t nuMoves)=0
 Take back moves played in the playout phase.
Virtual functions
virtual void GameStart ()
 Function that will be called by PlayGame() before the game.
virtual void StartPlayouts ()
 Function that will be called at the beginning of the playout phase.
virtual void StartPlayout ()
 Function that will be called at the beginning of each playout.
virtual void EndPlayout ()
 Function that will be called after each playout.

Public Attributes

const std::size_t m_threadId
 Number of the thread between 0 and SgUctSearch::NumberThreads() - 1.
bool m_isSearchInitialized
bool m_isTreeOutOfMem
 Flag indicating the a node could not be expanded, because the maximum tree size was reached.
SgUctGameInfo m_gameInfo
boost::scoped_array< std::size_t > m_firstPlay
 Local variable for SgUctSearch::UpdateRaveValues().
boost::scoped_array< std::size_t > m_firstPlayOpp
 Local variable for SgUctSearch::UpdateRaveValues().
std::vector< SgMoveInfom_moves
 Local variable for SgUctSearch::PlayInTree().
std::vector< SgMovem_excludeMoves
 Local variable for SgUctSearch::CheckCountAbort().
int m_randomizeCounter
 Thread's counter for Randomized Rave in SgUctSearch::SelectChild().


Constructor & Destructor Documentation

SgUctThreadState::SgUctThreadState ( size_t  threadId,
int  moveRange = 0 
)

Definition at line 67 of file SgUctSearch.cpp.

References m_firstPlay, and m_firstPlayOpp.

SgUctThreadState::~SgUctThreadState (  )  [virtual]

Definition at line 80 of file SgUctSearch.cpp.


Member Function Documentation

void SgUctThreadState::EndPlayout (  )  [virtual]

Function that will be called after each playout.

Default implementation does nothing.

Definition at line 84 of file SgUctSearch.cpp.

Referenced by SgUctSearch::PlayGame(), and SgUctSearch::SearchOnePly().

virtual float SgUctThreadState::Evaluate (  )  [pure virtual]

Evaluate end-of-game position.

Will only be called if GenerateAllMoves() or GeneratePlayoutMove() returns no moves. Should return larger values if position is better for the player to move.

Referenced by SgUctSearch::PlayGame(), and SgUctSearch::SearchOnePly().

virtual void SgUctThreadState::Execute ( SgMove  move  )  [pure virtual]

Execute a move.

Parameters:
move The move

Referenced by SgUctSearch::PlayInTree(), and SgUctSearch::SearchOnePly().

virtual void SgUctThreadState::ExecutePlayout ( SgMove  move  )  [pure virtual]

Execute a move in the playout phase.

For optimization if the subclass uses uses a different game state representation in the playout phase. Otherwise the function can be implemented in the subclass by simply calling Execute().

Parameters:
move The move

Referenced by SgUctSearch::PlayoutGame().

void SgUctThreadState::GameStart (  )  [virtual]

Function that will be called by PlayGame() before the game.

Default implementation does nothing.

Definition at line 89 of file SgUctSearch.cpp.

Referenced by SgUctSearch::PlayGame(), and SgUctSearch::SearchOnePly().

virtual bool SgUctThreadState::GenerateAllMoves ( std::size_t  count,
std::vector< SgMoveInfo > &  moves,
SgProvenNodeType provenType 
) [pure virtual]

Generate moves.

Moves will be explored in the order of the returned list. If return is true, trees under children will be deleted.

Parameters:
count Number of times node has been visited. For knowledge- based computations.
[out] moves The generated moves or empty list at end of game

Referenced by SgUctSearch::GenerateAllMoves(), SgUctSearch::PlayInTree(), and SgUctSearch::SearchOnePly().

virtual SgMove SgUctThreadState::GeneratePlayoutMove ( bool &  skipRaveUpdate  )  [pure virtual]

Generate random move.

Generate a random move in the play-out phase (outside the UCT tree).

Parameters:
[out] skipRaveUpdate This value should be set to true, if the move should be excluded from RAVE updates. Otherwise it can be ignored.
Returns:
The move or SG_NULLMOVE at the end of the game.

Referenced by SgUctSearch::PlayoutGame().

void SgUctThreadState::StartPlayout (  )  [virtual]

Function that will be called at the beginning of each playout.

Default implementation does nothing.

Definition at line 94 of file SgUctSearch.cpp.

Referenced by SgUctSearch::PlayGame(), and SgUctSearch::SearchOnePly().

void SgUctThreadState::StartPlayouts (  )  [virtual]

Function that will be called at the beginning of the playout phase.

Will be called only once (not once per playout!). Can be used for example to save some state of the current position for more efficient implementation of TakeBackPlayout(). Default implementation does nothing.

Definition at line 99 of file SgUctSearch.cpp.

Referenced by SgUctSearch::PlayGame(), and SgUctSearch::SearchOnePly().

virtual void SgUctThreadState::StartSearch (  )  [pure virtual]

Start search.

This function should do any necessary preparations for playing games in the thread, like initializing the thread's copy of the game state from the global game state. The function does not have to be thread-safe.

Referenced by SgUctSearch::GenerateAllMoves(), SgUctSearch::SearchOnePly(), and SgUctSearch::StartSearch().

virtual void SgUctThreadState::TakeBackInTree ( std::size_t  nuMoves  )  [pure virtual]

Take back moves played in the in-tree phase.

Referenced by SgUctSearch::PlayGame(), and SgUctSearch::SearchOnePly().

virtual void SgUctThreadState::TakeBackPlayout ( std::size_t  nuMoves  )  [pure virtual]

Take back moves played in the playout phase.

The search engine does not assume that the moves are really taken back after this function is called. If the subclass implements the playout in s separate state, which is initialized in StartPlayout() and does not support undo, the implementation of this function can be left empty in the subclass.

Referenced by SgUctSearch::PlayGame(), and SgUctSearch::SearchOnePly().


Member Data Documentation

std::vector<SgMove> SgUctThreadState::m_excludeMoves

Local variable for SgUctSearch::CheckCountAbort().

Reused for efficiency.

Definition at line 326 of file SgUctSearch.h.

Referenced by SgUctSearch::CheckCountAbort().

boost::scoped_array<std::size_t> SgUctThreadState::m_firstPlay

Local variable for SgUctSearch::UpdateRaveValues().

Reused for efficiency. Stores the first time a move was played by the color to play at the root position (move is used as an index, do m_moveRange must be > 0); numeric_limits<size_t>::max(), if the move was not played.

Definition at line 311 of file SgUctSearch.h.

Referenced by SgUctThreadState(), and SgUctSearch::UpdateRaveValues().

boost::scoped_array<std::size_t> SgUctThreadState::m_firstPlayOpp

Local variable for SgUctSearch::UpdateRaveValues().

Like m_firstPlayToPlay, but for opponent color.

Definition at line 316 of file SgUctSearch.h.

Referenced by SgUctThreadState(), and SgUctSearch::UpdateRaveValues().

SgUctGameInfo SgUctThreadState::m_gameInfo

Definition at line 303 of file SgUctSearch.h.

Referenced by SgUctSearch::LastGameInfo(), SgUctSearch::PlayGame(), SgUctSearch::PlayInTree(), SgUctSearch::PlayoutGame(), SgUctSearch::SearchLoop(), SgUctSearch::SearchOnePly(), and SgUctSearch::UpdateRaveValues().

bool SgUctThreadState::m_isSearchInitialized

Definition at line 296 of file SgUctSearch.h.

Referenced by SgUctSearch::SearchLoop().

bool SgUctThreadState::m_isTreeOutOfMem

Flag indicating the a node could not be expanded, because the maximum tree size was reached.

Definition at line 301 of file SgUctSearch.h.

Referenced by SgUctSearch::CreateChildren(), SgUctSearch::ExpandNode(), SgUctSearch::PlayGame(), SgUctSearch::PlayInTree(), and SgUctSearch::SearchLoop().

std::vector<SgMoveInfo> SgUctThreadState::m_moves

Local variable for SgUctSearch::PlayInTree().

Reused for efficiency.

Definition at line 321 of file SgUctSearch.h.

Referenced by SgUctSearch::CreateChildren(), SgUctSearch::ExpandNode(), and SgUctSearch::PlayInTree().

int SgUctThreadState::m_randomizeCounter

Thread's counter for Randomized Rave in SgUctSearch::SelectChild().

Definition at line 330 of file SgUctSearch.h.

Referenced by SgUctSearch::PlayInTree().

const std::size_t SgUctThreadState::m_threadId

Number of the thread between 0 and SgUctSearch::NumberThreads() - 1.

Definition at line 294 of file SgUctSearch.h.

Referenced by SgUctSearch::CreateChildren(), SgUctSearch::Debug(), SgUctSearch::ExpandNode(), and SgUctSearch::SearchLoop().


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


17 Jun 2010 Doxygen 1.4.7