private MCTSTreeNode(MCTSTreeNode parrent) { this.parrent = parrent; this.scoreSum = 0; this.nVisited = 1; succesors = new List <MCTSTreeNode>(); }
public MCTSTreeNode selectSuccesor() { if (this.isLeaf) { return(this); } double max = -10; MCTSTreeNode bestSuccesor = null; foreach (var item in succesors) { if (item.isFinished) { continue; } double val = item.eval(); if (val > max) { max = val; bestSuccesor = item; } } if (bestSuccesor == null) { this.isFinished = true; bestSuccesor = succesors[0]; } return(bestSuccesor.selectSuccesor()); }
public void expand() { if (isFinished) { return; } if (position.hasFinished) { isFinished = true; return; } this.isLeaf = false; List <Action> possibleActions = position.generatePossibleActions(); if (possibleActions.Count == 0) { throw new Exception(); } foreach (var item in possibleActions) { MCTSTreeNode succesor = createLeaf(this, item); succesor.position = this.position.clone(); succesor.position.playMove(item.player, item.number); succesors.Add(succesor); if (succesor.position == null) { throw new Exception(); } } this.position = null; this.updateSubtreeSize(possibleActions.Count); this.updateSubtreeDepth(1); }
public static MCTSTreeNode createLeaf(MCTSTreeNode parrent, Action move) { MCTSTreeNode node = new MCTSTreeNode(parrent); node.isLeaf = true; node.action = move; return(node); }
public static MCTSTreeNode createRoot(Game position) { MCTSTreeNode node = new MCTSTreeNode(); node.succesors = new List <MCTSTreeNode>(); node.parrent = null; node.scoreSum = 0; node.nVisited = 1; node.isLeaf = true; node.position = position; return(node); }