Ejemplo n.º 1
0
        public Node startNMCTS()
        {
            taskQueue jlhParallelThread = new taskQueue(base.jlhParallel);

            Task <DeterministicNode>[] searchTree = new Task <DeterministicNode> [base.jlhParallel];

            for (int i = 0; i < base.jlhParallel; i++)
            {
                searchTree[i] = jlhParallelThread.enqueueReturn(move);
            }

            //sum winrate nondeterministic node
            for (int i = 0; i < base.jlhParallel; i++)
            {
                for (int j = 0; j < searchTree[i].Result.children.Length; j++)
                {
                    if (searchTree[i].Result.children[j] is NondeterministicNode)
                    {
                        ((NondeterministicNode)searchTree[i].Result.children[j]).sumWinRate();
                    }
                }
            }

            //sum total
            result = searchTree[0].Result;
            for (int i = 1; i < base.jlhParallel; i++)
            {
                result.nVisits += searchTree[i].Result.nVisits;
                result.winRate += searchTree[i].Result.winRate;
                for (int j = 0; j < searchTree[i].Result.children.Length; j++)
                {
                    result.children[j].nVisits += searchTree[i].Result.children[j].nVisits;
                    result.children[j].winRate += searchTree[i].Result.children[j].winRate;
                }
            }

            Node maxWinRate = result.children[0];

            for (int i = 1; i < result.children.Length; i++)
            {
                if (maxWinRate.winRate <= result.children[i].winRate)
                {
                    maxWinRate = result.children[i];
                }
            }

            jlhParallelThread.Dispose();

            return(maxWinRate);
        }
Ejemplo n.º 2
0
        public Node startNMCTS()
        {
            timer.Start();
            tree = new DeterministicNode(this.board.getBoardState(), null, Constant.NONE, Constant.NONE);
            tree.expand();
            tree.updateStatus(tree.rollOut(), tree.s);
            taskQueue jlhParallelThread = new taskQueue(base.jlhParallel);

            //Task<DeterministicNode> [] searchTree = new Task<DeterministicNode>[base.jlhParallel];

            //for (int i = 0; i < base.jlhParallel; i++)
            //{
            //    searchTree[i] = jlhParallelThread.enqueueReturn(move);
            //}


            Task <DeterministicNode> searchTree = null;

            for (int i = 0; i < base.jlhParallel; i++)
            {
                searchTree = jlhParallelThread.enqueueReturn(move);
            }
            //sum winrate nondeterministic node
            for (int j = 0; j < searchTree.Result.children.Length; j++)
            {
                if (searchTree.Result.children[j] is NondeterministicNode)
                {
                    ((NondeterministicNode)searchTree.Result.children[j]).sumWinRate();
                }
            }

            DeterministicNode result = searchTree.Result;

            Node maxWinRate = result.children[0];

            for (int i = 1; i < result.children.Length; i++)
            {
                if (maxWinRate.winRate <= result.children[i].winRate)
                {
                    maxWinRate = result.children[i];
                }
            }

            jlhParallelThread.Dispose();

            return(maxWinRate);
        }