Global UCT-Search for Go. More...
#include <GoUctGlobalSearch.h>
Public Member Functions | |
GoUctGlobalSearchState (unsigned int threadId, const GoBoard &bd, POLICY *policy, const GoUctGlobalSearchStateParam ¶m, const GoUctPlayoutPolicyParam &policyParam, const SgBWSet &safe, const SgPointArray< bool > &allSafe) | |
Constructor. | |
~GoUctGlobalSearchState () | |
SgUctValue | Evaluate () |
bool | GenerateAllMoves (SgUctValue count, std::vector< SgUctMoveInfo > &moves, SgUctProvenType &provenType) |
SgMove | GeneratePlayoutMove (bool &skipRaveUpdate) |
void | ExecutePlayout (SgMove move) |
Implementation of SgUctSearch::ExecutePlayout. | |
void | GameStart () |
void | EndPlayout () |
void | StartPlayout () |
void | StartPlayouts () |
void | StartSearch () |
POLICY * | Policy () |
void | SetPolicy (POLICY *policy) |
Set random policy. | |
void | ClearTerritoryStatistics () |
const GoBoard & | Board () const |
Board used during in-tree phase. | |
const GoUctBoard & | UctBoard () const |
Board used during playout phase. | |
bool | IsInPlayout () const |
std::size_t | GameLength () const |
Length of the current game from the root position of the search. | |
void | Dump (std::ostream &out) const |
Pure virtual functions of SgUctThreadState | |
void | Execute (SgMove move) |
Implementation of SgUctSearch::Execute. | |
void | TakeBackInTree (std::size_t nuMoves) |
void | TakeBackPlayout (std::size_t nuMoves) |
Public Attributes | |
const SgBWSet & | m_safe |
const SgPointArray< bool > & | m_allSafe |
SgPointArray< SgUctStatistics > | m_territoryStatistics |
Probabilities that a point belongs to Black in a terminal position. | |
const unsigned int | m_threadId |
bool | m_isSearchInitialized |
bool | m_isTreeOutOfMem |
SgUctGameInfo | m_gameInfo |
boost::scoped_array< std::size_t > | m_firstPlay |
boost::scoped_array< std::size_t > | m_firstPlayOpp |
std::vector< SgUctMoveInfo > | m_moves |
std::vector< SgMove > | m_excludeMoves |
int | m_randomizeCounter |
Private Member Functions | |
GoUctGlobalSearchState (const GoUctGlobalSearchState &search) | |
Not implemented. | |
GoUctGlobalSearchState & | operator= (const GoUctGlobalSearchState &search) |
Not implemented. | |
bool | CheckMercyRule () |
See SetMercyRule(). | |
template<class BOARD > | |
SgUctValue | EvaluateBoard (const BOARD &bd, float komi) |
void | GenerateLegalMoves (std::vector< SgUctMoveInfo > &moves) |
Generates all legal moves with no knowledge values. | |
float | GetKomi () const |
Get komi including extra handicap komi points, if used by the rules. | |
Private Attributes | |
const GoUctGlobalSearchStateParam & | m_param |
const GoUctPlayoutPolicyParam & | m_policyParam |
bool | m_mercyRuleTriggered |
See SetMercyRule(). | |
int | m_passMovesPlayoutPhase |
Number of pass moves played in a row in the playout phase. | |
int | m_mercyRuleThreshold |
See SetMercyRule(). | |
int | m_stoneDiff |
Difference of stones on board. | |
int | m_initialMoveNumber |
Board move number at root node of search. | |
GoPointList | m_area |
The area in which moves should be generated. | |
SgUctValue | m_mercyRuleResult |
See SetMercyRule(). | |
SgUctValue | m_invMaxScore |
Inverse of maximum score one can reach on a board of the current size. | |
SgRandom | m_random |
GoUctDefaultPriorKnowledge | m_priorKnowledge |
boost::scoped_ptr< POLICY > | m_policy |
Global UCT-Search for Go.
POLICY | The playout policy |
Definition at line 103 of file GoUctGlobalSearch.h.
GoUctGlobalSearchState< POLICY >::GoUctGlobalSearchState | ( | unsigned int | threadId, | |
const GoBoard & | bd, | |||
POLICY * | policy, | |||
const GoUctGlobalSearchStateParam & | param, | |||
const GoUctPlayoutPolicyParam & | policyParam, | |||
const SgBWSet & | safe, | |||
const SgPointArray< bool > & | allSafe | |||
) |
Constructor.
threadId | The number of the thread. Needed for passing to constructor of SgUctThreadState. | |
bd | The board | |
policy | The random policy (takes ownership). It is possible to set the policy to null at construction time to allowed a multi-step construction; but then a policy has to be set with SetPolicy(), before the search is used. | |
param | Parameters. Stores a reference to the argument. | |
policyParam | Stores a reference to the argument. | |
safe | Safety information. Stores a reference to the argument. | |
allSafe | Safety information. Stores a reference to the argument. |
Definition at line 218 of file GoUctGlobalSearch.h.
References GoUctGlobalSearchState< POLICY >::ClearTerritoryStatistics().
GoUctGlobalSearchState< POLICY >::~GoUctGlobalSearchState | ( | ) |
Definition at line 235 of file GoUctGlobalSearch.h.
GoUctGlobalSearchState< POLICY >::GoUctGlobalSearchState | ( | const GoUctGlobalSearchState< POLICY > & | search | ) | [private] |
Not implemented.
const GoBoard & GoUctState::Board | ( | ) | const [inherited] |
Board used during in-tree phase.
Definition at line 106 of file GoUctSearch.h.
References GoUctState::m_bd.
Referenced by GoUctGlobalSearchState< POLICY >::Evaluate(), GoUctGlobalSearchState< POLICY >::GenerateLegalMoves(), GoUctGlobalSearchState< POLICY >::GetKomi(), GoUctGlobalSearchState< POLICY >::StartPlayout(), and GoUctGlobalSearchState< POLICY >::StartSearch().
bool GoUctGlobalSearchState< POLICY >::CheckMercyRule | ( | ) | [private] |
See SetMercyRule().
Definition at line 241 of file GoUctGlobalSearch.h.
References GoUctState::IsInPlayout(), GoUctGlobalSearchStateParam::m_mercyRule, GoUctGlobalSearchState< POLICY >::m_mercyRuleResult, GoUctGlobalSearchState< POLICY >::m_mercyRuleThreshold, GoUctGlobalSearchState< POLICY >::m_mercyRuleTriggered, GoUctGlobalSearchState< POLICY >::m_param, GoUctGlobalSearchState< POLICY >::m_stoneDiff, SG_ASSERT, SG_BLACK, SG_WHITE, GoUctBoard::ToPlay(), and GoUctState::UctBoard().
Referenced by GoUctGlobalSearchState< POLICY >::GeneratePlayoutMove().
void GoUctGlobalSearchState< POLICY >::ClearTerritoryStatistics | ( | ) |
Definition at line 262 of file GoUctGlobalSearch.h.
References GoUctGlobalSearchState< POLICY >::m_territoryStatistics.
Referenced by GoUctGlobalSearchState< POLICY >::GoUctGlobalSearchState(), and GoUctGlobalSearchState< POLICY >::StartSearch().
void GoUctState::Dump | ( | std::ostream & | out | ) | const [inherited] |
Definition at line 108 of file GoUctSearch.cpp.
References GoUctState::m_bd, GoUctState::m_isInPlayout, SgUctThreadState::m_threadId, and GoUctState::m_uctBd.
Referenced by GoUctState::AssertionHandler::Run().
void GoUctGlobalSearchState< POLICY >::EndPlayout | ( | ) | [virtual] |
Reimplemented from SgUctThreadState.
Definition at line 270 of file GoUctGlobalSearch.h.
References GoUctGlobalSearchState< POLICY >::m_policy.
SgUctValue GoUctGlobalSearchState< POLICY >::Evaluate | ( | ) | [virtual] |
Implements SgUctThreadState.
Definition at line 277 of file GoUctGlobalSearch.h.
References GoUctState::Board(), GoUctGlobalSearchState< POLICY >::EvaluateBoard(), GoUctGlobalSearchState< POLICY >::GetKomi(), GoUctState::IsInPlayout(), and GoUctState::UctBoard().
SgUctValue GoUctGlobalSearchState< POLICY >::EvaluateBoard | ( | const BOARD & | bd, | |
float | komi | |||
) | [private] |
Definition at line 288 of file GoUctGlobalSearch.h.
References GoUctState::GameLength(), GoUctGlobalSearchState< POLICY >::m_invMaxScore, GoUctGlobalSearchStateParam::m_lengthModification, GoUctGlobalSearchStateParam::m_mercyRule, GoUctGlobalSearchState< POLICY >::m_mercyRuleResult, GoUctGlobalSearchState< POLICY >::m_mercyRuleTriggered, GoUctGlobalSearchState< POLICY >::m_param, GoUctGlobalSearchState< POLICY >::m_passMovesPlayoutPhase, GoUctGlobalSearchState< POLICY >::m_safe, GoUctGlobalSearchStateParam::m_scoreModification, GoUctGlobalSearchState< POLICY >::m_territoryStatistics, GoUctGlobalSearchStateParam::m_territoryStatistics, GoBoardUtil::ScoreSimpleEndPosition(), SG_BLACK, SG_EMPTY, SG_WHITE, and GoBoardUtil::TrompTaylorScore().
Referenced by GoUctGlobalSearchState< POLICY >::Evaluate().
void GoUctState::Execute | ( | SgMove | move | ) | [virtual, inherited] |
Implementation of SgUctSearch::Execute.
Implements SgUctThreadState.
Definition at line 117 of file GoUctSearch.cpp.
References GO_MOVEFLAG_ILLEGAL, GoBoard::LastMoveInfo(), GoUctState::m_bd, GoUctState::m_gameLength, GoUctState::m_isInPlayout, GoBoard::Occupied(), GoBoard::Play(), GoBoard::Rules(), GoRules::SetKoRule(), SG_ASSERT, SG_PASS, and GoRules::SIMPLEKO.
void GoUctGlobalSearchState< POLICY >::ExecutePlayout | ( | SgMove | move | ) | [virtual] |
Implementation of SgUctSearch::ExecutePlayout.
Reimplemented from GoUctState.
Definition at line 346 of file GoUctGlobalSearch.h.
References GoUctGlobalSearchState< POLICY >::m_policy, GoUctGlobalSearchState< POLICY >::m_stoneDiff, GoUctBoard::NuCapturedStones(), SG_BLACK, GoUctBoard::ToPlay(), and GoUctState::UctBoard().
std::size_t GoUctState::GameLength | ( | ) | const [inherited] |
Length of the current game from the root position of the search.
Definition at line 111 of file GoUctSearch.h.
References GoUctState::m_gameLength.
Referenced by GoUctGlobalSearchState< POLICY >::EvaluateBoard().
void GoUctGlobalSearchState< POLICY >::GameStart | ( | ) | [virtual] |
Reimplemented from GoUctState.
Definition at line 358 of file GoUctGlobalSearch.h.
References GoUctGlobalSearchState< POLICY >::m_mercyRuleTriggered, and GoUctGlobalSearchState< POLICY >::m_passMovesPlayoutPhase.
bool GoUctGlobalSearchState< POLICY >::GenerateAllMoves | ( | SgUctValue | count, | |
std::vector< SgUctMoveInfo > & | moves, | |||
SgUctProvenType & | provenType | |||
) | [virtual] |
Implements SgUctThreadState.
Definition at line 409 of file GoUctGlobalSearch.h.
References GoUctGlobalSearchState< POLICY >::GenerateLegalMoves(), GoUctGlobalSearchState< POLICY >::m_priorKnowledge, GoUctDefaultPriorKnowledge::ProcessPosition(), and SG_NOT_PROVEN.
Referenced by GoUctCommands::CmdPriorKnowledge().
void GoUctGlobalSearchState< POLICY >::GenerateLegalMoves | ( | std::vector< SgUctMoveInfo > & | moves | ) | [private] |
Generates all legal moves with no knowledge values.
Definition at line 366 of file GoUctGlobalSearch.h.
References GoRules::AllowSuicide(), GoUctState::Board(), GoRules::CaptureDead(), GoBoard::IsEmpty(), GoBoard::IsLegal(), GoEyeUtil::IsSimpleEye(), GoUctGlobalSearchState< POLICY >::m_allSafe, GoUctGlobalSearchState< POLICY >::m_initialMoveNumber, GoUctGlobalSearchState< POLICY >::m_random, GoBoard::MoveNumber(), GoBoard::Rules(), SG_ASSERT, SG_PASS, SgRandom::SmallInt(), GoBoard::ToPlay(), and GoBoardUtil::TwoPasses().
Referenced by GoUctGlobalSearchState< POLICY >::GenerateAllMoves().
SgMove GoUctGlobalSearchState< POLICY >::GeneratePlayoutMove | ( | bool & | skipRaveUpdate | ) | [virtual] |
Implements SgUctThreadState.
Definition at line 425 of file GoUctGlobalSearch.h.
References GoUctGlobalSearchState< POLICY >::CheckMercyRule(), GoUctUtil::GeneratePoint(), GoUctState::IsInPlayout(), GoUctGlobalSearchStateParam::m_mercyRule, GoUctGlobalSearchState< POLICY >::m_param, GoUctGlobalSearchState< POLICY >::m_passMovesPlayoutPhase, GoUctGlobalSearchState< POLICY >::m_policy, GoUctGlobalSearchState< POLICY >::m_safe, GoUctBoard::Occupied(), SgBWSet::OneContains(), GoBoardUtil::SelfAtari(), SG_ASSERT, SG_NULLMOVE, SG_PASS, GoUctBoard::ToPlay(), and GoUctState::UctBoard().
float GoUctGlobalSearchState< POLICY >::GetKomi | ( | ) | const [private] |
Get komi including extra handicap komi points, if used by the rules.
Definition at line 470 of file GoUctGlobalSearch.h.
References GoUctState::Board(), GoRules::ExtraHandicapKomi(), GoRules::Handicap(), GoRules::Komi(), GoBoard::Rules(), and GoKomi::ToFloat().
Referenced by GoUctGlobalSearchState< POLICY >::Evaluate(), and GoUctGlobalSearchState< POLICY >::StartSearch().
bool GoUctState::IsInPlayout | ( | ) | const [inherited] |
Definition at line 116 of file GoUctSearch.h.
References GoUctState::m_isInPlayout.
Referenced by GoUctGlobalSearchState< POLICY >::CheckMercyRule(), GoUctGlobalSearchState< POLICY >::Evaluate(), and GoUctGlobalSearchState< POLICY >::GeneratePlayoutMove().
GoUctGlobalSearchState& GoUctGlobalSearchState< POLICY >::operator= | ( | const GoUctGlobalSearchState< POLICY > & | search | ) | [private] |
Not implemented.
POLICY * GoUctGlobalSearchState< POLICY >::Policy | ( | ) |
Definition at line 480 of file GoUctGlobalSearch.h.
References GoUctGlobalSearchState< POLICY >::m_policy.
void GoUctGlobalSearchState< POLICY >::SetPolicy | ( | POLICY * | policy | ) |
Set random policy.
Sets a new random policy and deletes the old one, if it existed.
Definition at line 486 of file GoUctGlobalSearch.h.
References GoUctGlobalSearchState< POLICY >::m_policy.
void GoUctGlobalSearchState< POLICY >::StartPlayout | ( | ) | [virtual] |
Reimplemented from GoUctState.
Definition at line 492 of file GoUctGlobalSearch.h.
References GoBoard::All(), GoUctState::Board(), GoUctGlobalSearchState< POLICY >::m_mercyRuleTriggered, GoUctGlobalSearchState< POLICY >::m_passMovesPlayoutPhase, GoUctGlobalSearchState< POLICY >::m_policy, GoUctGlobalSearchState< POLICY >::m_stoneDiff, SG_BLACK, SG_WHITE, and SgPointSet::Size().
void GoUctGlobalSearchState< POLICY >::StartPlayouts | ( | ) | [virtual] |
Reimplemented from GoUctState.
Definition at line 503 of file GoUctGlobalSearch.h.
void GoUctGlobalSearchState< POLICY >::StartSearch | ( | ) | [virtual] |
Reimplemented from GoUctState.
Definition at line 509 of file GoUctGlobalSearch.h.
References GoUctState::Board(), GoUctGlobalSearchState< POLICY >::ClearTerritoryStatistics(), GoUctGlobalSearchState< POLICY >::GetKomi(), GoUctGlobalSearchState< POLICY >::m_initialMoveNumber, GoUctGlobalSearchState< POLICY >::m_invMaxScore, GoUctGlobalSearchState< POLICY >::m_mercyRuleThreshold, GoBoard::MoveNumber(), and GoBoard::Size().
Referenced by GoUctCommands::CmdPriorKnowledge().
void GoUctState::TakeBackInTree | ( | std::size_t | nuMoves | ) | [virtual, inherited] |
Implements SgUctThreadState.
Definition at line 159 of file GoUctSearch.cpp.
References GoUctState::m_bd, and GoBoard::Undo().
void GoUctState::TakeBackPlayout | ( | std::size_t | nuMoves | ) | [virtual, inherited] |
Implements SgUctThreadState.
Definition at line 165 of file GoUctSearch.cpp.
References GoUctState::m_gameLength.
const GoUctBoard & GoUctState::UctBoard | ( | ) | const [inherited] |
Board used during playout phase.
Definition at line 121 of file GoUctSearch.h.
References GoUctState::m_uctBd.
Referenced by GoUctGlobalSearchState< POLICY >::CheckMercyRule(), GoUctGlobalSearchState< POLICY >::Evaluate(), GoUctGlobalSearchState< POLICY >::ExecutePlayout(), and GoUctGlobalSearchState< POLICY >::GeneratePlayoutMove().
const SgPointArray<bool>& GoUctGlobalSearchState< POLICY >::m_allSafe |
Definition at line 109 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::GenerateLegalMoves().
GoPointList GoUctGlobalSearchState< POLICY >::m_area [private] |
The area in which moves should be generated.
Definition at line 185 of file GoUctGlobalSearch.h.
int GoUctGlobalSearchState< POLICY >::m_initialMoveNumber [private] |
Board move number at root node of search.
Definition at line 182 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::GenerateLegalMoves(), and GoUctGlobalSearchState< POLICY >::StartSearch().
SgUctValue GoUctGlobalSearchState< POLICY >::m_invMaxScore [private] |
Inverse of maximum score one can reach on a board of the current size.
Definition at line 192 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::EvaluateBoard(), and GoUctGlobalSearchState< POLICY >::StartSearch().
SgUctValue GoUctGlobalSearchState< POLICY >::m_mercyRuleResult [private] |
See SetMercyRule().
Definition at line 188 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::CheckMercyRule(), and GoUctGlobalSearchState< POLICY >::EvaluateBoard().
int GoUctGlobalSearchState< POLICY >::m_mercyRuleThreshold [private] |
See SetMercyRule().
Definition at line 175 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::CheckMercyRule(), and GoUctGlobalSearchState< POLICY >::StartSearch().
bool GoUctGlobalSearchState< POLICY >::m_mercyRuleTriggered [private] |
See SetMercyRule().
Definition at line 169 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::CheckMercyRule(), GoUctGlobalSearchState< POLICY >::EvaluateBoard(), GoUctGlobalSearchState< POLICY >::GameStart(), and GoUctGlobalSearchState< POLICY >::StartPlayout().
const GoUctGlobalSearchStateParam& GoUctGlobalSearchState< POLICY >::m_param [private] |
Definition at line 164 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::CheckMercyRule(), GoUctGlobalSearchState< POLICY >::EvaluateBoard(), and GoUctGlobalSearchState< POLICY >::GeneratePlayoutMove().
int GoUctGlobalSearchState< POLICY >::m_passMovesPlayoutPhase [private] |
Number of pass moves played in a row in the playout phase.
Definition at line 172 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::EvaluateBoard(), GoUctGlobalSearchState< POLICY >::GameStart(), GoUctGlobalSearchState< POLICY >::GeneratePlayoutMove(), and GoUctGlobalSearchState< POLICY >::StartPlayout().
boost::scoped_ptr<POLICY> GoUctGlobalSearchState< POLICY >::m_policy [private] |
Definition at line 198 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::EndPlayout(), GoUctGlobalSearchState< POLICY >::ExecutePlayout(), GoUctGlobalSearchState< POLICY >::GeneratePlayoutMove(), GoUctGlobalSearchState< POLICY >::Policy(), GoUctGlobalSearchState< POLICY >::SetPolicy(), and GoUctGlobalSearchState< POLICY >::StartPlayout().
const GoUctPlayoutPolicyParam& GoUctGlobalSearchState< POLICY >::m_policyParam [private] |
Definition at line 166 of file GoUctGlobalSearch.h.
GoUctDefaultPriorKnowledge GoUctGlobalSearchState< POLICY >::m_priorKnowledge [private] |
Definition at line 196 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::GenerateAllMoves().
SgRandom GoUctGlobalSearchState< POLICY >::m_random [private] |
Definition at line 194 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::GenerateLegalMoves().
const SgBWSet& GoUctGlobalSearchState< POLICY >::m_safe |
Definition at line 107 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::EvaluateBoard(), and GoUctGlobalSearchState< POLICY >::GeneratePlayoutMove().
int GoUctGlobalSearchState< POLICY >::m_stoneDiff [private] |
Difference of stones on board.
Black counts positive.
Definition at line 179 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::CheckMercyRule(), GoUctGlobalSearchState< POLICY >::ExecutePlayout(), and GoUctGlobalSearchState< POLICY >::StartPlayout().
SgPointArray<SgUctStatistics> GoUctGlobalSearchState< POLICY >::m_territoryStatistics |
Probabilities that a point belongs to Black in a terminal position.
Only computed if GoUctGlobalSearchStateParam::m_territoryStatistics.
Definition at line 113 of file GoUctGlobalSearch.h.
Referenced by GoUctGlobalSearchState< POLICY >::ClearTerritoryStatistics(), GoUctGlobalSearch< POLICY, FACTORY >::DisplayGfx(), and GoUctGlobalSearchState< POLICY >::EvaluateBoard().