public FlySmart(SpaceShip owner, Node target, float dist) : base(owner, target.AbsolutePosition) { map = new AStarMap(400, owner); Dist = dist; TargetNode = target; astar = new AStar(); //map.Print(-22,-22,22,22); Point p1 = map.GetCell(target.AbsolutePosition); Point p2 = map.GetCell(owner.AbsolutePosition); p1 = map.GetNearestFreePosition(p1); p2 = map.GetNearestFreePosition(p2); if (p1 == p2) { System.Console.WriteLine("start=end!"); } AStarMap.AStarNode2D GoalNode = new AStarMap.AStarNode2D(null, null, 0, p1.X, p1.Y, map); AStarMap.AStarNode2D StartNode = new AStarMap.AStarNode2D(null, null, 0, p2.X, p2.Y, map); StartNode.GoalNode = GoalNode; astar.FindPath(StartNode, GoalNode); if (astar.Solution.Count == 0) { System.Console.WriteLine("no solution! from " + p2 + " to " + p1); Done = true; } PrintSolution(astar.Solution); currentnode = 0; }
/// <summary> /// Constructor for a node in a 2-dimensional map /// </summary> /// <param name="AParent">Parent of the node</param> /// <param name="AGoalNode">Goal node</param> /// <param name="ACost">Accumulative cost</param> /// <param name="AX">X-coordinate</param> /// <param name="AY">Y-coordinate</param> public AStarNode2D(AStarNode AParent, AStarNode AGoalNode, double ACost, int AX, int AY, AStarMap map) : base(AParent, AGoalNode, ACost) { FX = AX; FY = AY; Map = map; }
public FlySmart(SpaceShip owner, Node target, float dist) : base(owner,target.AbsolutePosition) { map = new AStarMap(400, owner); Dist = dist; TargetNode = target; astar = new AStar(); //map.Print(-22,-22,22,22); Point p1 = map.GetCell(target.AbsolutePosition); Point p2 = map.GetCell(owner.AbsolutePosition); p1 = map.GetNearestFreePosition(p1); p2 = map.GetNearestFreePosition(p2); if (p1 == p2) System.Console.WriteLine("start=end!"); AStarMap.AStarNode2D GoalNode = new AStarMap.AStarNode2D(null, null, 0, p1.X, p1.Y, map); AStarMap.AStarNode2D StartNode = new AStarMap.AStarNode2D(null, null, 0, p2.X, p2.Y, map); StartNode.GoalNode = GoalNode; astar.FindPath(StartNode, GoalNode); if (astar.Solution.Count == 0) { System.Console.WriteLine("no solution! from " + p2 + " to " + p1); Done = true; } PrintSolution(astar.Solution); currentnode = 0; }
/// <summary> /// Constructor for a node in a 2-dimensional map /// </summary> /// <param name="AParent">Parent of the node</param> /// <param name="AGoalNode">Goal node</param> /// <param name="ACost">Accumulative cost</param> /// <param name="AX">X-coordinate</param> /// <param name="AY">Y-coordinate</param> public AStarNode2D(AStarNode AParent, AStarNode AGoalNode, double ACost, int AX, int AY,AStarMap map) : base(AParent, AGoalNode, ACost) { FX = AX; FY = AY; Map = map; }