SgNode* SgNode::TopProp(SgPropID id) const { SgNode* node = const_cast<SgNode*>(this); while (node->HasFather() && ! node->Get(id)) node = node->Father(); // Return either root node or node with property. return node; }
void GoGame::AddMove(SgMove move, SgBlackWhite player, const SgSearchStatistics* stat, bool makeMainVariation) { // Check whether a node with that move already exists. SgNode* node = m_current->LeftMostSon(); while (node) { SgPropMove* prop = static_cast<SgPropMove*>(node->Get(SG_PROP_MOVE)); if (prop && prop->IsValue(move) && prop->IsPlayer(player)) break; node = node->RightBrother(); } // If no such node exists, create a new node with the given move. if (! node) { if (m_current->HasSon() && 0 < m_numMovesToInsert) { node = m_current->LeftMostSon()->NewFather(); --m_numMovesToInsert; } else { node = m_current->NewRightMostSon(); m_numMovesToInsert = 0; } node->AddMoveProp(move, player); } // Add statistics and time left to the node. if (stat) AddStatisticsToNode(stat, node); m_time.PlayedMove(*node, player); if (makeMainVariation) node->PromoteNode(); GoToNode(node); }