runSimulation method
Performs a single MCTS simulation (Select -> Expand -> Evaluate -> Backup)
Implementation
void runSimulation(MCTSNode root) {
MCTSNode current = root;
List<MCTSNode> searchPath = [current];
List<int> actionPath = [];
// 1. SELECT: Follow UCB until we find a leaf or an unexplored action
while (current.children.isNotEmpty) {
int action = _selectAction(current);
if (!current.children.containsKey(action)) {
actionPath.add(action);
break;
}
actionPath.add(action);
current = current.children[action]!;
searchPath.add(current);
}
// 2. Handle first simulation or root-only expansion
if (actionPath.isEmpty) {
actionPath.add(_selectAction(current));
}
// 3. EXPAND & BACKUP: Internal call to the dynamics head and backprop
_expandAndBackpropagate(searchPath, actionPath);
}