예제 #1
0
        public static void run(String[] args)
        {
            Logger log = new Logger();
            Stopwatch s = new Stopwatch();

            log.addToLog("Map initializing...");
            AStarMap map = new AStarMap(mapData.getMapWidth(), mapData.getMapHeight(), mapData.getObstacleMap());

            s.Start();

            PathFinder pathfinder = new PathFinder(map);
            Point start = new Point(startX, startY);
            Point goal = new Point(goalX, goalY);
            List<Point> optimizedWaypoints = pathfinder.findStraightPath(start, goal);

            s.Stop();
            log.addToLog("Total pathfinding took: " + s.ElapsedMilliseconds + " ms");

            log.addToLog("Printing map of optimized path...");
            new PrintMap(map, optimizedWaypoints);
        }
예제 #2
0
        public static void run(String[] args)
        {
            Logger log = new Logger();
            Stopwatch s = new Stopwatch();

            log.addToLog("Map initializing...");
            AStarMap map = new AStarMap(mapData.getMapWidth(), mapData.getMapHeight(), mapData.getObstacleMap());

            log.addToLog("Heuristic initializing...");
            //AStarHeuristic heuristic = new ClosestHeuristic();
            AStarHeuristic heuristic = new DiagonalHeuristic();

            log.addToLog("AStar initializing...");
            AStar aStar = new AStar(map, heuristic);

            log.addToLog("Calculating shortest path...");
            s.Start();
            List<Point> shortestPath = aStar.calcShortestPath(startX, startY, goalX, goalY);
            s.Stop();

            log.addToLog("Time to calculate path in milliseconds: " + s.ElapsedMilliseconds);

            log.addToLog("Printing map of shortest path...");
            new PrintMap(map, shortestPath);
        }
        public static void run(String[] args)
        {
            Point a = new Point(49, 49);
            Point b = new Point(0, 0);

            Logger log = new Logger();
            Stopwatch s = new Stopwatch();

            log.addToLog("Initializing "+mapWidth+"x"+mapHeight+" map...");
            initMap();
            AStarMap map = new AStarMap(mapWidth, mapHeight, obstacleMap);

            log.addToLog("Generating Bresenham's Line from "+a.x+","+a.y+" to "+b.x+","+b.y+"...");
            s.Start();
            List<Point> line = Bresenham.getCellsOnLine(a, b);
            s.Stop();
            log.addToLog("Generation took " + s.ElapsedMilliseconds + " ms");

            String str = "";
            foreach(Point point in line)
            {
                str = str+"("+point.x+","+point.y+") ";
            }
            log.addToLog("Line is:" + str);

            log.addToLog("Writing line to map...");
            log.addToLog("Printing map...");
            new PrintMap(map, line);
        }