bool RamAi::GameMonteCarloTree::PartialExpansion(const TreeNode &parent) const { //From http://julian.togelius.com/Jacobsen2014Monte.pdf if (!parent.IsLeaf()) { const double numberOfChildren = static_cast<double>(parent.GetNumberOfChildren()); const double numberOfVisits = static_cast<double>(parent.GetScore().GetVisits()); const double expansionWeighting = sqrt((2.0 * log(numberOfVisits)) / (1.0 + numberOfChildren)); const double expansionWeightingWithBias = GetBias() * expansionWeighting; const double unexpandedNodesValue = AiSettings::GetData().partialExpansionBase; const double expansionUrgencyScore = unexpandedNodesValue + expansionWeightingWithBias; //Check the expansion urgency score of the parent node with each of its children. //If the expansion urgency is greater than the confidence of any of its children, then the node is expanded (returns true). for (auto it = parent.GetIteratorBegin(); it != parent.GetIteratorEnd(); ++it) { const double uctScore = CalculateUcbScore(parent, it->second); if (expansionUrgencyScore > uctScore) { return true; } } return false; } else { return true; } }
bool RamAi::GameMonteCarloTree::NodeNeedsExpanding(const TreeNode &node) const { return (node.GetNumberOfChildren() < ConsoleSettings::GetSpecs().GetNumberOfInputCombinations()) && PartialExpansion(node); }