コード例 #1
0
ファイル: Program.cs プロジェクト: kristijorgji/Shortest-Path
        public static List <Node> GetAvailableNodes(Node parent, Location destination)
        {
            List <Node>     result         = new List <Node>();
            List <Location> availableMoves = RedKnight.AvailableMoves(parent.Location);

            foreach (Location l in availableMoves)
            {
                //Console.WriteLine("{0} {1}", l.X, l.Y);
                Node n = new Node(l.X, l.Y);
                n.Parent = parent;

                if (!visitedNodes.Contains(n))
                {
                    result.Add(n);
                    visitedNodes.Add(n);
                }
            }

            return(result);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kristijorgji/Shortest-Path
 public static void PrintResult(List <Node> path)
 {
     if (path != null && path.Count > 1) //valid path
     {
         Console.WriteLine(path.Count - 1);
         for (int c = 0; c < path.Count - 1; c++)
         {
             Console.Write(RedKnight.GetMoveName(path[c].Location.X, path[c].Location.Y, path[c + 1].Location.X, path[c + 1].Location.Y));
             if (c < path.Count - 2)
             {
                 Console.Write(" ");
             }
             //Console.WriteLine("{1} {0} to {3} {2}, move Type: {4}",
             //    path[c].Location.X, path[c].Location.Y,
             //    path[c + 1].Location.X, path[c + 1].Location.Y,
             //    RedKnight.GetMoveName(path[c].Location.X,
             //    path[c].Location.Y, path[c + 1].Location.X, path[c + 1].Location.Y));
         }
     }
     else
     {
         Console.WriteLine("Impossible");
     }
 }