Esempio n. 1
0
            /**
             *
             * @param from
             *            unit's current location
             * @param to
             *            the destination
             * @param isHillPassable
             *            true if unit can fly, otherwise false
             * @return a valid plan for the unit to follow (barring movement barriers),
             *         or an empty list of coords if no valid plan is found
             */
            public List<Coords> calculateMovementPlan(Graph g, Coords from, Coords to)
            {
                // run A*
                //Console.WriteLine("Calculating path from " + from + " to " + to);
                AStar astar = new AStar ();
                MapLocation start = new MapLocation (from);
                /*
                List<Connection> conns = g.getConnections(start);
                foreach (Connection conn in conns) {
                    Console.WriteLine("conn from start: " + conn);
                    List<Connection> nextConns = g.getConnections(conn.getToNode());
                    foreach(Connection c2 in nextConns) {
                        Console.WriteLine("second level connections " + c2);
                    }
                }
                */
                MapLocation goal = new MapLocation (to);
                ManhattanHeuristic heuristic = new ManhattanHeuristic (goal);
                List<Connection> path = astar.pathfindAStar (g, start, goal, heuristic);
                // localize plan
                List<Coords> coords = new List<Coords> ();
                if (path != null) {
                    coords = localization (path);
                    /*
                    Console.Write ("Found path: ");
                    foreach(Coords coord in coords) {
                        Console.Write (coord);
                    }
                    Console.WriteLine();
                    */
                } else {
                    Console.WriteLine("no path found");
                }

                return coords;
            }