Beispiel #1
0
        public int UseMCTS(int x, int centerY)
        {
            Log.LogInformation("Driver MCTS - MCTS start");

            int s = 1;

            while (!RectangleAgent.obstacleOpenSpace[centerY + s, x])
            {
                s++;
            }
            Node square = new Node(x, centerY + s - 1, false);

            this.nodes[0] = square;
            int y = square.getY();

            deleteCollectedDiamonds();

            RectangleAgent.nodes = this.nodes;
            RectangleAgent.CreateEdgesAndAdjacencyMatrix();
            this.adjacencyMatrix = RectangleAgent.adjacencyMatrix;
            this.directionMap    = RectangleAgent.directionMap;

            MCTS         driverMCTS = new MCTS(this.nodes, this.adjacencyMatrix, RectangleAgent.nCollectiblesLeft, 2000);
            Queue <Node> newRoute   = driverMCTS.Run();

            this.route = RectangleAgent.ClearRoute(newRoute.ToArray(), driverMCTS.outputNodeIndex);

            return(recalcNextNodes("MCTS", x, y));
        }
Beispiel #2
0
        public int UseMCTSWithAStar(int x, int centerY)
        {
            Log.LogInformation("Driver MCTS ASTAR - MCTS ASTAR start");

            int s = 1;

            while (!RectangleAgent.obstacleOpenSpace[centerY + s, x])
            {
                s++;
            }
            Node square = new Node(x, centerY + s - 1, false);

            this.nodes[0] = square;
            int y = square.getY();

            deleteCollectedDiamonds();

            RectangleAgent.nodes = this.nodes;
            RectangleAgent.CreateEdgesAndAdjacencyMatrix();
            this.adjacencyMatrix = RectangleAgent.adjacencyMatrix;
            this.directionMap    = RectangleAgent.directionMap;

            MCTS         driverMCTS = new MCTS(this.nodes, this.adjacencyMatrix, RectangleAgent.nCollectiblesLeft, 2000);
            Queue <Node> newRoute   = driverMCTS.Run();

            this.route = RectangleAgent.ClearRoute(newRoute.ToArray(), driverMCTS.outputNodeIndex);

            //AStar
            Node[]      routeAsArray = this.route.ToArray();
            List <Node> diamondNodes = new List <Node>();

            for (int n = 0; n < routeAsArray.Length; n++)
            {
                if (routeAsArray[n].getDiamond() && !diamondNodes.Contains(routeAsArray[n]))
                {
                    diamondNodes.Add(routeAsArray[n]);
                }
            }

            this.route = RectangleAgent.calcShortestRouteWithDiamondOrderAStar(diamondNodes);
            //AStar end

            return(recalcNextNodes("MCTS ASTAR", x, y));
        }