// Adds a successor to a list if it is not impassible or the parent node private void AddSuccessor(ArrayList ASuccessors, int AX, int AY) { double CurrentCost = planner.GetMap(AX, AY); if (CurrentCost < 0.0) { return; } AStarNodeBC NewNode = new AStarNodeBC(this, GoalNode, Cost + CurrentCost, AX, AY, planner); if (NewNode.IsSameState(Parent)) { return; } ASuccessors.Add(NewNode); }
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); }