Node used in SgUctTree. More...
#include <SgUctTree.h>
Public Member Functions | |
SgUctNode (const SgUctMoveInfo &info) | |
Initializes node with given move, value and count. | |
void | AddGameResult (SgUctValue eval) |
Add game result. | |
void | AddGameResults (SgUctValue eval, SgUctValue count) |
Adds a game result count times. | |
void | MergeResults (const SgUctNode &node) |
Add other nodes results to this node's. | |
void | RemoveGameResult (SgUctValue eval) |
Removes a game result. | |
void | RemoveGameResults (SgUctValue eval, SgUctValue count) |
Removes a game result count times. | |
SgUctValue | PosCount () const |
Number of times this node was visited. | |
SgUctValue | MoveCount () const |
Number of times the move leading to this position was chosen. | |
const SgUctNode * | FirstChild () const |
Get first child. | |
bool | HasChildren () const |
Does the node have at least one child? | |
SgUctValue | Mean () const |
Average game result. | |
bool | HasMean () const |
True, if mean value is defined (move count not zero). | |
int | NuChildren () const |
Get number of children. | |
void | SetFirstChild (const SgUctNode *child) |
See FirstChild(). | |
void | SetNuChildren (int nuChildren) |
See NuChildren(). | |
void | IncPosCount () |
Increment the position count. | |
void | IncPosCount (SgUctValue count) |
Increment the position count. | |
void | DecPosCount () |
Decrement the position count. | |
void | DecPosCount (SgUctValue count) |
Decrement the position count. | |
void | SetPosCount (SgUctValue value) |
void | InitializeValue (SgUctValue value, SgUctValue count) |
Initialize value with prior knowledge. | |
void | CopyDataFrom (const SgUctNode &node) |
Copy data from other node. | |
SgMove | Move () const |
Get move. | |
SgUctValue | RaveCount () const |
Get RAVE count. | |
SgUctValue | RaveValue () const |
Get RAVE mean value. | |
bool | HasRaveValue () const |
void | AddRaveValue (SgUctValue value, SgUctValue weight) |
Add a game result value to the RAVE value. | |
void | RemoveRaveValue (SgUctValue value) |
Removes a rave result. | |
void | RemoveRaveValue (SgUctValue value, SgUctValue weight) |
void | InitializeRaveValue (SgUctValue value, SgUctValue count) |
Initialize RAVE value with prior knowledge. | |
int | VirtualLossCount () const |
void | AddVirtualLoss () |
void | RemoveVirtualLoss () |
SgUctValue | KnowledgeCount () const |
Returns the last time knowledge was computed. | |
void | SetKnowledgeCount (SgUctValue count) |
Set that knowledge has been computed at count. | |
bool | IsProven () const |
Returns true if node is a proven node. | |
bool | IsProvenWin () const |
bool | IsProvenLoss () const |
SgUctProvenType | ProvenType () const |
void | SetProvenType (SgUctProvenType type) |
Private Attributes | |
SgUctStatisticsVolatile | m_statistics |
const SgUctNode *volatile | m_firstChild |
volatile int | m_nuChildren |
volatile SgMove | m_move |
SgUctStatisticsVolatile | m_raveValue |
RAVE statistics. | |
volatile SgUctValue | m_posCount |
volatile SgUctValue | m_knowledgeCount |
volatile SgUctProvenType | m_provenType |
volatile int | m_virtualLossCount |
Node used in SgUctTree.
All data members are declared as volatile to avoid that the compiler re-orders writes, which can break assumptions made by SgUctSearch in lock-free mode (see Lock-free mode in SgUctSearch). For example, the search relies on the fact that m_firstChild is valid, if m_nuChildren is greater zero or that the mean value of the move and RAVE value statistics is valid if the corresponding count is greater zero.
Definition at line 111 of file SgUctTree.h.
SgUctNode::SgUctNode | ( | const SgUctMoveInfo & | info | ) |
Initializes node with given move, value and count.
Definition at line 270 of file SgUctTree.h.
void SgUctNode::AddGameResult | ( | SgUctValue | eval | ) |
Add game result.
eval | The game result (e.g. score or 0/1 for win loss) |
Definition at line 283 of file SgUctTree.h.
References SgStatisticsVltBase< VALUE, COUNT >::Add(), and m_statistics.
void SgUctNode::AddGameResults | ( | SgUctValue | eval, | |
SgUctValue | count | |||
) |
Adds a game result count times.
Definition at line 288 of file SgUctTree.h.
References SgStatisticsVltBase< VALUE, COUNT >::Add(), and m_statistics.
void SgUctNode::AddRaveValue | ( | SgUctValue | value, | |
SgUctValue | weight | |||
) |
Add a game result value to the RAVE value.
Definition at line 311 of file SgUctTree.h.
References SgStatisticsVltBase< VALUE, COUNT >::Add(), and m_raveValue.
void SgUctNode::AddVirtualLoss | ( | ) |
Definition at line 363 of file SgUctTree.h.
References m_virtualLossCount.
void SgUctNode::CopyDataFrom | ( | const SgUctNode & | node | ) |
Copy data from other node.
Copies all data, apart from the children information (first child and number of children).
Definition at line 326 of file SgUctTree.h.
References m_knowledgeCount, m_move, m_posCount, m_provenType, m_raveValue, m_statistics, and m_virtualLossCount.
Referenced by SgUctTree::ApplyFilter(), SgUctTree::CopySubtree(), and SgUctTree::SetChildren().
void SgUctNode::DecPosCount | ( | ) |
Decrement the position count.
See PosCount()
Definition at line 386 of file SgUctTree.h.
References m_posCount.
void SgUctNode::DecPosCount | ( | SgUctValue | count | ) |
Decrement the position count.
See PosCount()
Definition at line 395 of file SgUctTree.h.
References m_posCount.
const SgUctNode * SgUctNode::FirstChild | ( | ) | const |
Get first child.
Definition at line 337 of file SgUctTree.h.
References HasChildren(), m_firstChild, and SG_ASSERT.
Referenced by SgUctTree::MergeChildren(), SgUctSearch::SelectChild(), and SgUctChildIterator::SgUctChildIterator().
bool SgUctNode::HasChildren | ( | ) | const |
Does the node have at least one child?
Definition at line 343 of file SgUctTree.h.
References m_nuChildren.
Referenced by SgUctTree::ApplyFilter(), SgUctTreeStatistics::Compute(), SgUctTree::CopySubtree(), SgUctTree::CreateChildren(), SgUctSearch::FindBestChild(), SgUctSearch::FindBestSequence(), SgUctTreeUtil::FindChildWithMove(), FirstChild(), SgUctTree::MergeChildren(), SgUctTreeIterator::operator++(), SgUctSearch::PlayInTree(), SgUctSearch::PrintSearchProgress(), SgUctSearch::SelectChild(), SgUctTree::SetChildren(), and SgUctChildIterator::SgUctChildIterator().
bool SgUctNode::HasMean | ( | ) | const |
True, if mean value is defined (move count not zero).
Definition at line 348 of file SgUctTree.h.
References SgStatisticsVltBase< VALUE, COUNT >::IsDefined(), and m_statistics.
Referenced by SgUctSearch::CheckEarlyAbort(), SgUctTreeStatistics::Compute(), SgUctSearch::FindBestChild(), SgUctSearch::GetValueEstimate(), and SgUctSearch::GetValueEstimateRave().
bool SgUctNode::HasRaveValue | ( | ) | const |
Definition at line 353 of file SgUctTree.h.
References SgStatisticsVltBase< VALUE, COUNT >::IsDefined(), and m_raveValue.
Referenced by SgUctTreeStatistics::Compute(), SgUctSearch::FindBestChild(), SgUctSearch::GetValueEstimate(), and SgUctSearch::GetValueEstimateRave().
void SgUctNode::IncPosCount | ( | SgUctValue | count | ) |
Increment the position count.
See PosCount()
Definition at line 381 of file SgUctTree.h.
References m_posCount.
void SgUctNode::IncPosCount | ( | ) |
Increment the position count.
See PosCount()
Definition at line 376 of file SgUctTree.h.
References m_posCount.
void SgUctNode::InitializeRaveValue | ( | SgUctValue | value, | |
SgUctValue | count | |||
) |
Initialize RAVE value with prior knowledge.
Definition at line 409 of file SgUctTree.h.
References SgStatisticsVltBase< VALUE, COUNT >::Initialize(), and m_raveValue.
void SgUctNode::InitializeValue | ( | SgUctValue | value, | |
SgUctValue | count | |||
) |
Initialize value with prior knowledge.
Definition at line 404 of file SgUctTree.h.
References SgStatisticsVltBase< VALUE, COUNT >::Initialize(), and m_statistics.
bool SgUctNode::IsProven | ( | ) | const |
Returns true if node is a proven node.
Definition at line 476 of file SgUctTree.h.
References m_provenType.
Referenced by SgUctSearch::CheckAbortSearch(), SgUctTree::CopySubtree(), SgUctSearch::PlayInTree(), and SgUctSearch::PropagateProvenStatus().
bool SgUctNode::IsProvenLoss | ( | ) | const |
Definition at line 486 of file SgUctTree.h.
References m_provenType.
Referenced by SgUctSearch::FindBestChild(), and SgUctSearch::PropagateProvenStatus().
bool SgUctNode::IsProvenWin | ( | ) | const |
Definition at line 481 of file SgUctTree.h.
References m_provenType.
Referenced by SgUctSearch::CheckAbortSearch(), and SgUctSearch::SelectChild().
SgUctValue SgUctNode::KnowledgeCount | ( | ) | const |
Returns the last time knowledge was computed.
Definition at line 466 of file SgUctTree.h.
References m_knowledgeCount.
Referenced by SgUctTree::MergeChildren(), SgUctSearch::NeedToComputeKnowledge(), and SgUctSearch::PlayInTree().
SgUctValue SgUctNode::Mean | ( | ) | const |
Average game result.
Requires: HasMean()
Definition at line 414 of file SgUctTree.h.
References m_statistics, and SgStatisticsVltBase< VALUE, COUNT >::Mean().
Referenced by SgUctSearch::CheckEarlyAbort(), SgUctTreeStatistics::Compute(), SgUctSearch::FindBestChild(), SgUctSearch::GetValueEstimate(), SgUctSearch::GetValueEstimateRave(), SgUctSearch::PrintSearchProgress(), SgUctSearch::Search(), and SgUctSearch::SummaryLine().
void SgUctNode::MergeResults | ( | const SgUctNode & | node | ) |
Add other nodes results to this node's.
Definition at line 293 of file SgUctTree.h.
References SgStatisticsVltBase< VALUE, COUNT >::Add(), SgStatisticsVltBase< VALUE, COUNT >::Count(), SgStatisticsVltBase< VALUE, COUNT >::IsDefined(), m_raveValue, m_statistics, and SgStatisticsVltBase< VALUE, COUNT >::Mean().
Referenced by SgUctTree::MergeChildren().
SgMove SgUctNode::Move | ( | ) | const |
Get move.
Requires: Node has a move (is not root node)
Definition at line 419 of file SgUctTree.h.
References m_move, SG_ASSERT, and SG_NULLMOVE.
Referenced by SgUctTree::ApplyFilter(), SgUctSearch::CheckCountAbort(), SgUctSearch::FindBestChild(), SgUctSearch::FindBestSequence(), SgUctTreeUtil::FindChildWithMove(), SgUctTree::MergeChildren(), SgUctSearch::PlayInTree(), SgUctSearch::PrintSearchProgress(), SgUctSearch::SummaryLine(), and SgUctSearch::UpdateRaveValues().
SgUctValue SgUctNode::MoveCount | ( | ) | const |
Number of times the move leading to this position was chosen.
This count will be different from PosCount(), if prior knowledge initialization is used.
Definition at line 425 of file SgUctTree.h.
References SgStatisticsVltBase< VALUE, COUNT >::Count(), and m_statistics.
Referenced by SgUctSearch::CheckAbortSearch(), SgUctSearch::CheckCountAbort(), SgUctSearch::CheckEarlyAbort(), SgUctTreeStatistics::Compute(), SgUctTree::CopySubtree(), SgUctSearch::FindBestChild(), SgUctSearch::GamesPlayed(), SgUctSearch::GetBound(), SgUctSearch::GetValueEstimate(), SgUctSearch::GetValueEstimateRave(), SgUctTree::MergeChildren(), SgUctSearch::NeedToComputeKnowledge(), SgUctSearch::PlayInTree(), SgUctSearch::PrintSearchProgress(), SgUctSearch::Search(), SgUctSearch::StartSearch(), SgUctSearch::SummaryLine(), and SgUctSearch::WriteStatistics().
int SgUctNode::NuChildren | ( | ) | const |
Get number of children.
Definition at line 430 of file SgUctTree.h.
References m_nuChildren.
Referenced by SgUctTree::ApplyFilter(), SgUctTree::CopySubtree(), SgUctTree::MergeChildren(), SgUctChildIterator::SgUctChildIterator(), and SgUctSearch::StartSearch().
SgUctValue SgUctNode::PosCount | ( | ) | const |
Number of times this node was visited.
This corresponds to the sum of MoveCount() of all children. It can be different from MoveCount() of this position, if prior knowledge initialization of the children is used.
Definition at line 435 of file SgUctTree.h.
References m_posCount.
Referenced by SgUctSearch::GetBound(), SgUctTree::MergeChildren(), and SgUctSearch::SelectChild().
SgUctProvenType SgUctNode::ProvenType | ( | ) | const |
Definition at line 491 of file SgUctTree.h.
References m_provenType.
SgUctValue SgUctNode::RaveCount | ( | ) | const |
Get RAVE count.
Definition at line 440 of file SgUctTree.h.
References SgStatisticsVltBase< VALUE, COUNT >::Count(), and m_raveValue.
Referenced by SgUctSearch::GetValueEstimate(), and SgUctSearch::GetValueEstimateRave().
SgUctValue SgUctNode::RaveValue | ( | ) | const |
Get RAVE mean value.
Requires: HasRaveValue()
Definition at line 445 of file SgUctTree.h.
References m_raveValue, and SgStatisticsVltBase< VALUE, COUNT >::Mean().
Referenced by SgUctTreeStatistics::Compute(), SgUctSearch::GetValueEstimate(), and SgUctSearch::GetValueEstimateRave().
void SgUctNode::RemoveGameResult | ( | SgUctValue | eval | ) |
Removes a game result.
eval | The game result (e.g. score or 0/1 for win loss) |
Definition at line 301 of file SgUctTree.h.
References m_statistics, and SgStatisticsVltBase< VALUE, COUNT >::Remove().
void SgUctNode::RemoveGameResults | ( | SgUctValue | eval, | |
SgUctValue | count | |||
) |
Removes a game result count times.
Definition at line 306 of file SgUctTree.h.
References m_statistics, and SgStatisticsVltBase< VALUE, COUNT >::Remove().
void SgUctNode::RemoveRaveValue | ( | SgUctValue | value, | |
SgUctValue | weight | |||
) |
Definition at line 321 of file SgUctTree.h.
References m_raveValue, and SgStatisticsVltBase< VALUE, COUNT >::Remove().
void SgUctNode::RemoveRaveValue | ( | SgUctValue | value | ) |
Removes a rave result.
Definition at line 316 of file SgUctTree.h.
References m_raveValue, and SgStatisticsVltBase< VALUE, COUNT >::Remove().
void SgUctNode::RemoveVirtualLoss | ( | ) |
Definition at line 368 of file SgUctTree.h.
References m_virtualLossCount.
void SgUctNode::SetFirstChild | ( | const SgUctNode * | child | ) |
See FirstChild().
Definition at line 450 of file SgUctTree.h.
References m_firstChild.
Referenced by SgUctTree::ApplyFilter(), SgUctTree::CopySubtree(), SgUctTree::CreateChildren(), SgUctTree::MergeChildren(), and SgUctTree::SetChildren().
void SgUctNode::SetKnowledgeCount | ( | SgUctValue | count | ) |
Set that knowledge has been computed at count.
Definition at line 471 of file SgUctTree.h.
References m_knowledgeCount.
Referenced by SgUctTree::MergeChildren().
void SgUctNode::SetNuChildren | ( | int | nuChildren | ) |
See NuChildren().
Definition at line 455 of file SgUctTree.h.
References m_nuChildren, and SG_ASSERT.
Referenced by SgUctTree::ApplyFilter(), SgUctTree::CopySubtree(), SgUctTree::CreateChildren(), SgUctTree::MergeChildren(), and SgUctTree::SetChildren().
void SgUctNode::SetPosCount | ( | SgUctValue | value | ) |
Definition at line 461 of file SgUctTree.h.
References m_posCount.
Referenced by SgUctTree::CopySubtree(), SgUctTree::CreateChildren(), and SgUctTree::MergeChildren().
void SgUctNode::SetProvenType | ( | SgUctProvenType | type | ) |
Definition at line 496 of file SgUctTree.h.
References m_provenType.
Referenced by SgUctTree::CopySubtree().
int SgUctNode::VirtualLossCount | ( | ) | const |
Definition at line 358 of file SgUctTree.h.
References m_virtualLossCount.
Referenced by SgUctSearch::GetBound(), SgUctSearch::GetValueEstimate(), SgUctSearch::GetValueEstimateRave(), and SgUctSearch::SelectChild().
const SgUctNode* volatile SgUctNode::m_firstChild [private] |
Definition at line 250 of file SgUctTree.h.
Referenced by FirstChild(), and SetFirstChild().
volatile SgUctValue SgUctNode::m_knowledgeCount [private] |
Definition at line 263 of file SgUctTree.h.
Referenced by CopyDataFrom(), KnowledgeCount(), and SetKnowledgeCount().
volatile SgMove SgUctNode::m_move [private] |
Definition at line 254 of file SgUctTree.h.
Referenced by CopyDataFrom(), and Move().
volatile int SgUctNode::m_nuChildren [private] |
Definition at line 252 of file SgUctTree.h.
Referenced by HasChildren(), NuChildren(), and SetNuChildren().
volatile SgUctValue SgUctNode::m_posCount [private] |
Definition at line 261 of file SgUctTree.h.
Referenced by CopyDataFrom(), DecPosCount(), IncPosCount(), PosCount(), and SetPosCount().
volatile SgUctProvenType SgUctNode::m_provenType [private] |
Definition at line 265 of file SgUctTree.h.
Referenced by CopyDataFrom(), IsProven(), IsProvenLoss(), IsProvenWin(), ProvenType(), and SetProvenType().
RAVE statistics.
Uses double for count to allow adding fractional values if RAVE updates are weighted.
Definition at line 259 of file SgUctTree.h.
Referenced by AddRaveValue(), CopyDataFrom(), HasRaveValue(), InitializeRaveValue(), MergeResults(), RaveCount(), RaveValue(), and RemoveRaveValue().
Definition at line 248 of file SgUctTree.h.
Referenced by AddGameResult(), AddGameResults(), CopyDataFrom(), HasMean(), InitializeValue(), Mean(), MergeResults(), MoveCount(), RemoveGameResult(), and RemoveGameResults().
volatile int SgUctNode::m_virtualLossCount [private] |
Definition at line 267 of file SgUctTree.h.
Referenced by AddVirtualLoss(), CopyDataFrom(), RemoveVirtualLoss(), and VirtualLossCount().