Expands a Book using the given player to evaluate game positions. More...
#include <GoUctBookBuilder.h>
Classes | |
class | Worker |
Copyable worker. More... | |
Public Member Functions | |
GoUctBookBuilder (const GoBoard &brd) | |
~GoUctBookBuilder () | |
void | SetPlayer (PLAYER &player) |
Sets the player to use. | |
void | SetState (GoAutoBook &book) |
Sets the state to start work from. | |
std::size_t | NumThreads () const |
Number of players to use during leaf expansion. | |
void | SetNumThreads (std::size_t num) |
See NumThreads(). | |
SgUctValue | NumGamesPerEvaluation () const |
Number of games to play when evaluation a state. | |
void | SetNumGamesPerEvaluation (SgUctValue num) |
See NumGamesPerEvaluation(). | |
SgUctValue | NumGamesPerSort () const |
Number of games to play when sorting children. | |
void | SetNumGamesPerSort (SgUctValue num) |
See NumGamesForSort(). | |
float | InverseEval (float eval) const |
bool | IsLoss (float eval) const |
float | Value (const SgBookNode &node) const |
void | Expand (int numExpansions) |
void | Cover (int requiredExpansions, bool additive, const std::vector< std::vector< SgMove > > &lines) |
void | Refresh () |
void | IncreaseWidth () |
float | Alpha () const |
void | SetAlpha (float alpha) |
bool | UseWidening () const |
void | SetUseWidening (bool flag) |
std::size_t | ExpandWidth () const |
void | SetExpandWidth (std::size_t width) |
std::size_t | ExpandThreshold () const |
void | SetExpandThreshold (std::size_t threshold) |
float | ComputePriority (const SgBookNode &parent, const float childValue, const float childPriority) const |
Protected Member Functions | |
std::string | MoveString (SgMove move) const |
void | PrintMessage (std::string msg) |
void | PlayMove (SgMove move) |
void | UndoMove (SgMove move) |
bool | GetNode (SgBookNode &node) const |
void | WriteNode (const SgBookNode &node) |
void | FlushBook () |
void | EnsureRootExists () |
Creates root node if necessary. | |
bool | GenerateMoves (std::vector< SgMove > &moves, float &value) |
Computes an ordered set of moves to consider. | |
void | GetAllLegalMoves (std::vector< SgMove > &moves) |
void | EvaluateChildren (const std::vector< SgMove > &childrenToDo, std::vector< std::pair< SgMove, float > > &scores) |
void | Init () |
void | StartIteration () |
void | EndIteration () |
void | BeforeEvaluateChildren () |
void | AfterEvaluateChildren () |
void | Fini () |
void | ClearAllVisited () |
void | MarkAsVisited () |
bool | HasBeenVisited () |
Protected Attributes | |
float | m_alpha |
bool | m_useWidening |
std::size_t | m_expandWidth |
std::size_t | m_expandThreshold |
std::size_t | m_flushIterations |
Private Member Functions | |
void | CreateWorkers () |
Copies the player and board and creates the threads. | |
void | DestroyWorkers () |
Destroys copied players, boards, and threads. | |
Private Attributes | |
GoAutoBook * | m_book |
Book this builder is expanding. | |
PLAYER * | m_origPlayer |
GoAutoBookState | m_state |
std::set< SgHashCode > | m_visited |
std::size_t | m_numThreads |
See NumberThreads(). | |
SgUctValue | m_numGamesPerEvaluation |
See NumGamesPerEvaluation. | |
SgUctValue | m_numGamesPerSort |
See NumGamesForSort(). | |
std::size_t | m_numEvals |
std::size_t | m_numWidenings |
std::size_t | m_valueUpdates |
std::size_t | m_priorityUpdates |
std::size_t | m_internalNodes |
std::size_t | m_leafNodes |
std::size_t | m_terminalNodes |
std::vector< PLAYER * > | m_players |
Players for each thread. | |
std::vector< Worker > | m_workers |
Workers for each thread. | |
SgThreadedWorker< SgMove, float, Worker > * | m_threadedWorker |
Expands a Book using the given player to evaluate game positions.
Supports multithreaded evaluation of children.
Definition at line 24 of file GoUctBookBuilder.h.
GoUctBookBuilder< PLAYER >::GoUctBookBuilder | ( | const GoBoard & | brd | ) |
Definition at line 214 of file GoUctBookBuilder.h.
References SgBookBuilder::SetAlpha(), and SgBookBuilder::SetExpandWidth().
GoUctBookBuilder< PLAYER >::~GoUctBookBuilder | ( | ) |
Definition at line 228 of file GoUctBookBuilder.h.
void GoUctBookBuilder< PLAYER >::AfterEvaluateChildren | ( | ) | [protected, virtual] |
Reimplemented from SgBookBuilder.
Definition at line 463 of file GoUctBookBuilder.h.
void GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren | ( | ) | [protected, virtual] |
Reimplemented from SgBookBuilder.
Definition at line 444 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numGamesPerEvaluation, GoUctBookBuilder< PLAYER >::m_numThreads, and GoUctBookBuilder< PLAYER >::m_players.
Referenced by GoUctBookBuilder< PLAYER >::EnsureRootExists().
void GoUctBookBuilder< PLAYER >::ClearAllVisited | ( | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 478 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_visited.
void GoUctBookBuilder< PLAYER >::CreateWorkers | ( | ) | [private] |
Copies the player and board and creates the threads.
Definition at line 236 of file GoUctBookBuilder.h.
References GoAutoBookState::Board(), GoUctBookBuilder< PLAYER >::m_numThreads, GoUctBookBuilder< PLAYER >::m_players, GoUctBookBuilder< PLAYER >::m_state, GoUctBookBuilder< PLAYER >::m_threadedWorker, GoUctBookBuilder< PLAYER >::m_workers, GoUctBookBuilder< PLAYER >::PrintMessage(), and SG_UCTMOVESELECT_ESTIMATE.
Referenced by GoUctBookBuilder< PLAYER >::Init().
void GoUctBookBuilder< PLAYER >::DestroyWorkers | ( | ) | [private] |
Destroys copied players, boards, and threads.
Definition at line 263 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numThreads, GoUctBookBuilder< PLAYER >::m_players, GoUctBookBuilder< PLAYER >::m_threadedWorker, GoUctBookBuilder< PLAYER >::m_workers, and GoUctBookBuilder< PLAYER >::PrintMessage().
Referenced by GoUctBookBuilder< PLAYER >::Fini().
void GoUctBookBuilder< PLAYER >::EndIteration | ( | ) | [protected, virtual] |
Reimplemented from SgBookBuilder.
Definition at line 473 of file GoUctBookBuilder.h.
void GoUctBookBuilder< PLAYER >::EnsureRootExists | ( | ) | [protected, virtual] |
Creates root node if necessary.
Implements SgBookBuilder.
Definition at line 395 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren(), GoUctBookBuilder< PLAYER >::GetNode(), GoUctBookBuilder< PLAYER >::m_workers, GoUctBookBuilder< PLAYER >::PrintMessage(), SG_NULLMOVE, and GoUctBookBuilder< PLAYER >::WriteNode().
void GoUctBookBuilder< PLAYER >::EvaluateChildren | ( | const std::vector< SgMove > & | childrenToDo, | |
std::vector< std::pair< SgMove, float > > & | scores | |||
) | [protected, virtual] |
void GoUctBookBuilder< PLAYER >::Fini | ( | ) | [protected, virtual] |
Reimplemented from SgBookBuilder.
Definition at line 280 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::DestroyWorkers().
void GoUctBookBuilder< PLAYER >::FlushBook | ( | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 373 of file GoUctBookBuilder.h.
References GoAutoBook::Flush(), GoUctBookBuilder< PLAYER >::m_book, and SgDebug().
bool GoUctBookBuilder< PLAYER >::GenerateMoves | ( | std::vector< SgMove > & | moves, | |
float & | value | |||
) | [protected, virtual] |
Computes an ordered set of moves to consider.
Implements SgBookBuilder.
Definition at line 409 of file GoUctBookBuilder.h.
References GoAutoBookState::Board(), SgUctTreeUtil::FindChildWithMove(), GoBoard::IsLegal(), GoUctBookBuilder< PLAYER >::m_numGamesPerSort, GoUctBookBuilder< PLAYER >::m_players, GoUctBookBuilder< PLAYER >::m_state, GoUctBookBuilder< PLAYER >::m_workers, SgUctNode::PosCount(), SgUctTree::Root(), SG_NULLMOVE, SG_UNUSED(), and SgDebug().
void GoUctBookBuilder< PLAYER >::GetAllLegalMoves | ( | std::vector< SgMove > & | moves | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 386 of file GoUctBookBuilder.h.
References GoAutoBookState::Board(), GoBoard::IsLegal(), and GoUctBookBuilder< PLAYER >::m_state.
bool GoUctBookBuilder< PLAYER >::GetNode | ( | SgBookNode & | node | ) | const [protected, virtual] |
Implements SgBookBuilder.
Definition at line 361 of file GoUctBookBuilder.h.
References GoAutoBook::Get(), GoUctBookBuilder< PLAYER >::m_book, and GoUctBookBuilder< PLAYER >::m_state.
Referenced by GoUctBookBuilder< PLAYER >::EnsureRootExists().
bool GoUctBookBuilder< PLAYER >::HasBeenVisited | ( | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 490 of file GoUctBookBuilder.h.
References GoAutoBookState::GetHashCode(), GoUctBookBuilder< PLAYER >::m_state, and GoUctBookBuilder< PLAYER >::m_visited.
void GoUctBookBuilder< PLAYER >::Init | ( | ) | [protected, virtual] |
Reimplemented from SgBookBuilder.
Definition at line 274 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::CreateWorkers().
float GoUctBookBuilder< PLAYER >::InverseEval | ( | float | eval | ) | const [virtual] |
Implements SgBookBuilder.
Definition at line 336 of file GoUctBookBuilder.h.
bool GoUctBookBuilder< PLAYER >::IsLoss | ( | float | eval | ) | const [virtual] |
Implements SgBookBuilder.
Definition at line 342 of file GoUctBookBuilder.h.
void GoUctBookBuilder< PLAYER >::MarkAsVisited | ( | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 484 of file GoUctBookBuilder.h.
References GoAutoBookState::GetHashCode(), GoUctBookBuilder< PLAYER >::m_state, and GoUctBookBuilder< PLAYER >::m_visited.
std::string GoUctBookBuilder< PLAYER >::MoveString | ( | SgMove | move | ) | const [protected, virtual] |
Implements SgBookBuilder.
Definition at line 324 of file GoUctBookBuilder.h.
References SgPointUtil::PointToString().
SgUctValue GoUctBookBuilder< PLAYER >::NumGamesPerEvaluation | ( | ) | const |
Number of games to play when evaluation a state.
Definition at line 188 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numGamesPerEvaluation.
SgUctValue GoUctBookBuilder< PLAYER >::NumGamesPerSort | ( | ) | const |
Number of games to play when sorting children.
Definition at line 200 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numGamesPerSort.
std::size_t GoUctBookBuilder< PLAYER >::NumThreads | ( | ) | const |
Number of players to use during leaf expansion.
Each player may use a multi-threaded search. Should speed up the expansion of leaf states by a factor of (very close to) NumThreads().
Definition at line 176 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numThreads.
void GoUctBookBuilder< PLAYER >::PlayMove | ( | SgMove | move | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 348 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_state, and GoAutoBookState::Play().
void GoUctBookBuilder< PLAYER >::PrintMessage | ( | std::string | msg | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 330 of file GoUctBookBuilder.h.
References SgDebug().
Referenced by GoUctBookBuilder< PLAYER >::CreateWorkers(), GoUctBookBuilder< PLAYER >::DestroyWorkers(), and GoUctBookBuilder< PLAYER >::EnsureRootExists().
void GoUctBookBuilder< PLAYER >::SetNumGamesPerEvaluation | ( | SgUctValue | num | ) |
Definition at line 194 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numGamesPerEvaluation.
void GoUctBookBuilder< PLAYER >::SetNumGamesPerSort | ( | SgUctValue | num | ) |
See NumGamesForSort().
Definition at line 206 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numGamesPerSort.
void GoUctBookBuilder< PLAYER >::SetNumThreads | ( | std::size_t | num | ) |
See NumThreads().
Definition at line 182 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numThreads.
void GoUctBookBuilder< PLAYER >::SetPlayer | ( | PLAYER & | player | ) |
Sets the player to use.
Settings are copied from this player to the players used for each thread.
Definition at line 311 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_origPlayer.
void GoUctBookBuilder< PLAYER >::SetState | ( | GoAutoBook & | book | ) |
Sets the state to start work from.
Definition at line 317 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_book, GoUctBookBuilder< PLAYER >::m_state, and GoAutoBookState::Synchronize().
void GoUctBookBuilder< PLAYER >::StartIteration | ( | ) | [protected, virtual] |
Reimplemented from SgBookBuilder.
Definition at line 468 of file GoUctBookBuilder.h.
void GoUctBookBuilder< PLAYER >::UndoMove | ( | SgMove | move | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 354 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_state, SG_UNUSED(), and GoAutoBookState::Undo().
float GoUctBookBuilder< PLAYER >::Value | ( | const SgBookNode & | node | ) | const [virtual] |
Implements SgBookBuilder.
Definition at line 380 of file GoUctBookBuilder.h.
References SgBookNode::m_value.
void GoUctBookBuilder< PLAYER >::WriteNode | ( | const SgBookNode & | node | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 367 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_book, GoUctBookBuilder< PLAYER >::m_state, and GoAutoBook::Put().
Referenced by GoUctBookBuilder< PLAYER >::EnsureRootExists().
GoAutoBook* GoUctBookBuilder< PLAYER >::m_book [private] |
Book this builder is expanding.
Definition at line 129 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::FlushBook(), GoUctBookBuilder< PLAYER >::GetNode(), GoUctBookBuilder< PLAYER >::SetState(), and GoUctBookBuilder< PLAYER >::WriteNode().
std::size_t GoUctBookBuilder< PLAYER >::m_internalNodes [private] |
Reimplemented from SgBookBuilder.
Definition at line 154 of file GoUctBookBuilder.h.
std::size_t GoUctBookBuilder< PLAYER >::m_leafNodes [private] |
Reimplemented from SgBookBuilder.
Definition at line 156 of file GoUctBookBuilder.h.
std::size_t GoUctBookBuilder< PLAYER >::m_numEvals [private] |
Reimplemented from SgBookBuilder.
Definition at line 146 of file GoUctBookBuilder.h.
SgUctValue GoUctBookBuilder< PLAYER >::m_numGamesPerEvaluation [private] |
See NumGamesPerEvaluation.
Definition at line 141 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren(), GoUctBookBuilder< PLAYER >::NumGamesPerEvaluation(), and GoUctBookBuilder< PLAYER >::SetNumGamesPerEvaluation().
SgUctValue GoUctBookBuilder< PLAYER >::m_numGamesPerSort [private] |
See NumGamesForSort().
Definition at line 144 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::GenerateMoves(), GoUctBookBuilder< PLAYER >::NumGamesPerSort(), and GoUctBookBuilder< PLAYER >::SetNumGamesPerSort().
std::size_t GoUctBookBuilder< PLAYER >::m_numThreads [private] |
See NumberThreads().
Definition at line 138 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren(), GoUctBookBuilder< PLAYER >::CreateWorkers(), GoUctBookBuilder< PLAYER >::DestroyWorkers(), GoUctBookBuilder< PLAYER >::NumThreads(), and GoUctBookBuilder< PLAYER >::SetNumThreads().
std::size_t GoUctBookBuilder< PLAYER >::m_numWidenings [private] |
Reimplemented from SgBookBuilder.
Definition at line 148 of file GoUctBookBuilder.h.
PLAYER* GoUctBookBuilder< PLAYER >::m_origPlayer [private] |
Definition at line 131 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::SetPlayer().
std::vector<PLAYER*> GoUctBookBuilder< PLAYER >::m_players [private] |
Players for each thread.
Definition at line 161 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren(), GoUctBookBuilder< PLAYER >::CreateWorkers(), GoUctBookBuilder< PLAYER >::DestroyWorkers(), and GoUctBookBuilder< PLAYER >::GenerateMoves().
std::size_t GoUctBookBuilder< PLAYER >::m_priorityUpdates [private] |
Reimplemented from SgBookBuilder.
Definition at line 152 of file GoUctBookBuilder.h.
GoAutoBookState GoUctBookBuilder< PLAYER >::m_state [private] |
Definition at line 133 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::CreateWorkers(), GoUctBookBuilder< PLAYER >::GenerateMoves(), GoUctBookBuilder< PLAYER >::GetAllLegalMoves(), GoUctBookBuilder< PLAYER >::GetNode(), GoUctBookBuilder< PLAYER >::HasBeenVisited(), GoUctBookBuilder< PLAYER >::MarkAsVisited(), GoUctBookBuilder< PLAYER >::PlayMove(), GoUctBookBuilder< PLAYER >::SetState(), GoUctBookBuilder< PLAYER >::UndoMove(), and GoUctBookBuilder< PLAYER >::WriteNode().
std::size_t GoUctBookBuilder< PLAYER >::m_terminalNodes [private] |
Reimplemented from SgBookBuilder.
Definition at line 158 of file GoUctBookBuilder.h.
SgThreadedWorker<SgMove,float,Worker>* GoUctBookBuilder< PLAYER >::m_threadedWorker [private] |
Definition at line 166 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::CreateWorkers(), and GoUctBookBuilder< PLAYER >::DestroyWorkers().
std::size_t GoUctBookBuilder< PLAYER >::m_valueUpdates [private] |
Reimplemented from SgBookBuilder.
Definition at line 150 of file GoUctBookBuilder.h.
std::set<SgHashCode> GoUctBookBuilder< PLAYER >::m_visited [private] |
Definition at line 135 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::ClearAllVisited(), GoUctBookBuilder< PLAYER >::HasBeenVisited(), and GoUctBookBuilder< PLAYER >::MarkAsVisited().
std::vector<Worker> GoUctBookBuilder< PLAYER >::m_workers [private] |
Workers for each thread.
Definition at line 164 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::CreateWorkers(), GoUctBookBuilder< PLAYER >::DestroyWorkers(), GoUctBookBuilder< PLAYER >::EnsureRootExists(), and GoUctBookBuilder< PLAYER >::GenerateMoves().