Exemple #1
0
        public override void Tick(float dtime)
        {
            base.Tick(dtime);

            if (Owner.Distance(TargetNode) < Dist)
            {
                Done = true;
                return;
            }
            Point p2 = map.GetCell(Owner.AbsolutePosition);

            for (int i = 0; i < astar.Solution.Count; ++i)
            {
                AStarMap.AStarNode2D node = (AStarMap.AStarNode2D)astar.Solution[i];
                Point p1 = new Point(node.X, node.Y);

                if (p2 == p1)
                {
                    if (i == astar.Solution.Count - 1)
                    {
                        Done = true;
                        System.Console.WriteLine("arrived at last node");
                    }
                    else if (i > currentnode - 1)
                    {
                        currentnode = i;
                        System.Console.WriteLine("next node: " + ++currentnode);
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Prints the solution
 /// </summary>
 /// <param name="ASolution">The list that holds the solution</param>
 public void PrintSolution(ArrayList ASolution)
 {
     for (int j = -20; j < 21; j++)
     {
         for (int i = -20; i < 21; i++)
         {
             bool solution = false;
             foreach (AStarMap.AStarNode2D n in ASolution)
             {
                 AStarMap.AStarNode2D tmp = new AStarMap.AStarNode2D(null, null, 0, i, j, map);
                 solution = n.IsSameState(tmp);
                 if (solution)
                 {
                     break;
                 }
             }
             if (solution)
             {
                 System.Console.Write("S ");
             }
             else
             if (map.GetMap(i, j) == -1)
             {
                 System.Console.Write("X ");
             }
             else
             {
                 System.Console.Write(". ");
             }
         }
         System.Console.WriteLine("");
     }
 }
Exemple #3
0
        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;
        }
Exemple #4
0
 /// <summary>
 /// Prints the solution
 /// </summary>
 /// <param name="ASolution">The list that holds the solution</param>
 public void PrintSolution(ArrayList ASolution)
 {
     for (int j = -20; j <21; j++)
     {
         for (int i = -20; i < 21; i++)
         {
             bool solution = false;
             foreach (AStarMap.AStarNode2D n in ASolution)
             {
                 AStarMap.AStarNode2D tmp = new AStarMap.AStarNode2D(null, null, 0, i, j,map);
                 solution = n.IsSameState(tmp);
                 if (solution)
                     break;
             }
             if (solution)
                 System.Console.Write("S ");
             else
                 if (map.GetMap(i, j) == -1)
                     System.Console.Write("X ");
                 else
                     System.Console.Write(". ");
         }
         System.Console.WriteLine("");
     }
 }
Exemple #5
0
        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;
        }