示例#1
0
 /// <summary>
 /// Prints the solution
 /// </summary>
 /// <param name="ASolution">The list that holds the solution</param>
 static public void PrintSolution(ArrayList ASolution)
 {
     for (int j = 0; j < 10; j++)
     {
         for (int i = 0; i < 10; i++)
         {
             bool solution = false;
             foreach (AStarNode2D n in ASolution)
             {
                 AStarNode2D tmp = new AStarNode2D(null, null, 0, i, j);
                 solution = n.IsSameState(tmp);
                 if (solution)
                 {
                     break;
                 }
             }
             if (solution)
             {
                 Console.Write("S ");
             }
             else
             if (MainClass.GetMap(i, j) == -1)
             {
                 Console.Write("X ");
             }
             else
             {
                 Console.Write(". ");
             }
         }
         Console.WriteLine("");
     }
 }
示例#2
0
        /// <summary>
        /// Adds a successor to a list if it is not impassible or the parent node
        /// </summary>
        /// <param name="ASuccessors">List of successors</param>
        /// <param name="AX">X-coordinate</param>
        /// <param name="AY">Y-coordinate</param>
        private void AddSuccessor(ArrayList ASuccessors, int AX, int AY)
        {
            int CurrentCost = MainClass.GetMap(AX, AY);

            if (CurrentCost == -1)
            {
                return;
            }
            AStarNode2D NewNode = new AStarNode2D(this, GoalNode, Cost + CurrentCost, AX, AY);

            if (NewNode.IsSameState(Parent))
            {
                return;
            }
            ASuccessors.Add(NewNode);
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting...");

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

            AStarNode2D GoalNode  = new AStarNode2D(null, null, 0, 9, 9);
            AStarNode2D StartNode = new AStarNode2D(null, GoalNode, 0, 0, 0);

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


            PrintSolution(astar.Solution);
            Console.ReadLine();
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting...");

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

            AStarNode2D GoalNode = new AStarNode2D(null,null,0,9,9);
            AStarNode2D StartNode = new AStarNode2D(null,GoalNode,0,0,0);
            StartNode.GoalNode = GoalNode;
            astar.FindPath(StartNode,GoalNode);

            PrintSolution(astar.Solution);
            Console.ReadLine();
        }
示例#5
0
 /// <summary>
 /// Prints the solution
 /// </summary>
 /// <param name="ASolution">The list that holds the solution</param>
 public static void PrintSolution(ArrayList ASolution)
 {
     for(int j=0;j<10;j++)
     {
         for(int i=0;i<10;i++)
         {
             bool solution = false;
             foreach(AStarNode2D n in ASolution)
             {
                 AStarNode2D tmp = new AStarNode2D(null,null,0,i,j);
                 solution = n.IsSameState(tmp);
                 if(solution)
                     break;
             }
             if(solution)
                 Console.Write("S ");
             else
                 if(MainClass.GetMap(i,j) == -1)
                 Console.Write("X ");
             else
                 Console.Write(". ");
         }
         Console.WriteLine("");
     }
 }
示例#6
0
 /// <summary>
 /// Adds a successor to a list if it is not impassible or the parent node
 /// </summary>
 /// <param name="ASuccessors">List of successors</param>
 /// <param name="AX">X-coordinate</param>
 /// <param name="AY">Y-coordinate</param>
 private void AddSuccessor(ArrayList ASuccessors,int AX,int AY)
 {
     int CurrentCost = MainClass.GetMap(AX,AY);
     if(CurrentCost == -1)
     {
         return;
     }
     AStarNode2D NewNode = new AStarNode2D(this,GoalNode,Cost + CurrentCost,AX,AY);
     if(NewNode.IsSameState(Parent))
     {
         return;
     }
     ASuccessors.Add(NewNode);
 }