Ejemplo n.º 1
0
        public List <Tuple <int, int> > GetPath(int x1, int y1, int x2, int y2, CancellationTokenSource cancel)
        {
            List <Tuple <int, int> > result = new List <Tuple <int, int> >();

            // Save the destination on which the path was planned. This is useful if the planning gets cancelled
            // and we later want to re-run the plan (or substitute it with an alternative).
            destX = x2;
            destY = y2;

            Games.Pathfinding.AStar astar = new Games.Pathfinding.AStar();

            AStarNodeBC GoalNode  = new AStarNodeBC(null, null, 0, x2 - 2, y2 - 2, this);
            AStarNodeBC StartNode = new AStarNodeBC(null, GoalNode, 0, x1 - 2, y1 - 2, this);

            StartNode.GoalNode = GoalNode;
            astar.FindPath(StartNode, GoalNode, cancel);

            foreach (AStarNodeBC n in astar.Solution)
            {
                result.Add(new Tuple <int, int>(n.X, n.Y));
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static List<Vector2f> CalcPath(Vector2f start, Vector2f end)
        {
            var astar = new AStar();

            var goalNode = new AStarNode2D(null,null,0, (int)end.X, (int)end.Y);
            var startNode = new AStarNode2D(null,goalNode, 0, (int)start.X, (int)start.Y) {GoalNode = goalNode};
            astar.FindPath(startNode, goalNode);

            return astar.Solution.ToArray().ToList().Select(i => new Vector2f(((AStarNode2D) i).X, ((AStarNode2D) i).Y)).ToList();
        }