Base class for the thread state. More...
#include <SgUctSearch.h>
Public Member Functions | |
SgUctThreadState (unsigned int threadId, int moveRange=0) | |
virtual | ~SgUctThreadState () |
Pure virtual functions | |
virtual SgUctValue | 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 (SgUctValue count, std::vector< SgUctMoveInfo > &moves, SgUctProvenType &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 unsigned int | 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< SgUctMoveInfo > | m_moves |
Local variable for SgUctSearch::PlayInTree(). | |
std::vector< SgMove > | m_excludeMoves |
Local variable for SgUctSearch::CheckCountAbort(). | |
int | m_randomizeCounter |
Thread's counter for Randomized Rave in SgUctSearch::SelectChild(). |
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())
Definition at line 271 of file SgUctSearch.h.
SgUctThreadState::SgUctThreadState | ( | unsigned int | threadId, | |
int | moveRange = 0 | |||
) |
Definition at line 111 of file SgUctSearch.cpp.
References m_firstPlay, and m_firstPlayOpp.
SgUctThreadState::~SgUctThreadState | ( | ) | [virtual] |
Definition at line 123 of file SgUctSearch.cpp.
void SgUctThreadState::EndPlayout | ( | ) | [virtual] |
Function that will be called after each playout.
Default implementation does nothing.
Definition at line 127 of file SgUctSearch.cpp.
Referenced by SgUctSearch::PlayGame(), and SgUctSearch::SearchOnePly().
virtual SgUctValue 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.
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().
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 132 of file SgUctSearch.cpp.
Referenced by SgUctSearch::PlayGame(), and SgUctSearch::SearchOnePly().
virtual bool SgUctThreadState::GenerateAllMoves | ( | SgUctValue | count, | |
std::vector< SgUctMoveInfo > & | moves, | |||
SgUctProvenType & | 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.
count | Number of times node has been visited. For knowledge- based computations. | |
[out] | moves | The generated moves or empty list at end of game |
[out] | provenType |
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).
[out] | skipRaveUpdate | This value should be set to true, if the move should be excluded from RAVE updates. Otherwise it can be ignored. |
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 137 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 142 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().
std::vector<SgMove> SgUctThreadState::m_excludeMoves |
Local variable for SgUctSearch::CheckCountAbort().
Reused for efficiency.
Definition at line 302 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 290 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 294 of file SgUctSearch.h.
Referenced by SgUctThreadState(), and SgUctSearch::UpdateRaveValues().
Definition at line 283 of file SgUctSearch.h.
Referenced by SgUctSearch::LastGameInfo(), SgUctSearch::PlayGame(), SgUctSearch::PlayInTree(), SgUctSearch::PlayoutGame(), SgUctSearch::SearchLoop(), SgUctSearch::SearchOnePly(), and SgUctSearch::UpdateRaveValues().
Definition at line 277 of file SgUctSearch.h.
Referenced by SgUctSearch::SearchLoop().
Flag indicating the a node could not be expanded, because the maximum tree size was reached.
Definition at line 281 of file SgUctSearch.h.
Referenced by SgUctSearch::CreateChildren(), SgUctSearch::ExpandNode(), SgUctSearch::PlayGame(), SgUctSearch::PlayInTree(), and SgUctSearch::SearchLoop().
std::vector<SgUctMoveInfo> SgUctThreadState::m_moves |
Local variable for SgUctSearch::PlayInTree().
Reused for efficiency.
Definition at line 298 of file SgUctSearch.h.
Referenced by SgUctSearch::CreateChildren(), SgUctSearch::ExpandNode(), and SgUctSearch::PlayInTree().
Thread's counter for Randomized Rave in SgUctSearch::SelectChild().
Definition at line 305 of file SgUctSearch.h.
Referenced by SgUctSearch::PlayInTree(), and SgUctSearch::StartSearch().
const unsigned int SgUctThreadState::m_threadId |
Number of the thread between 0 and SgUctSearch::NumberThreads() - 1.
Definition at line 275 of file SgUctSearch.h.
Referenced by SgUctSearch::CreateChildren(), SgUctSearch::Debug(), SgUctSearch::ExpandNode(), and SgUctSearch::SearchLoop().