예제 #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);
                    }
                }
            }
        }
예제 #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("");
     }
 }
예제 #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;
        }
예제 #4
0
파일: ai.cs 프로젝트: cody82/spacewar-arena
 /// <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("");
     }
 }
예제 #5
0
파일: ai.cs 프로젝트: cody82/spacewar-arena
        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;
        }