예제 #1
0
 private MCTSTreeNode(MCTSTreeNode parrent)
 {
     this.parrent  = parrent;
     this.scoreSum = 0;
     this.nVisited = 1;
     succesors     = new List <MCTSTreeNode>();
 }
예제 #2
0
        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());
        }
예제 #3
0
        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);
        }
예제 #4
0
        public static MCTSTreeNode createLeaf(MCTSTreeNode parrent, Action move)
        {
            MCTSTreeNode node = new MCTSTreeNode(parrent);

            node.isLeaf = true;
            node.action = move;
            return(node);
        }
예제 #5
0
        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);
        }