示例#1
0
        public static void PrintPath(int[,] array,
                                     PathSearchLee.Point[] path,
                                     PathSearchLee.Point start,
                                     PathSearchLee.Point end)
        {
            var width  = array.GetLength(0);
            var height = array.GetLength(1);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    if (x == start.X && y == start.Y)
                    {
                        Console.Write($"STR\t");
                        continue;
                    }
                    if (x == end.X && y == end.Y)
                    {
                        Console.Write($"END\t");
                        continue;
                    }
                    if (path.Any(point => point.X == x && point.Y == y))
                    {
                        Console.Write($"===\t");
                        continue;
                    }
                    Console.Write($"{array[x, y],3}\t");
                }
                Console.WriteLine();
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            //для иллюстрации того, как повёрнуты координаты
            DebugHelpers.PrintToConsole2DCoordinates(testMap);

            var searcher = new PathSearchLee(PathSearchLee.SearchMethod.Path4);
            var start    = new PathSearchLee.Point(5, 0);
            var end      = new PathSearchLee.Point(0, 6);
            var path     = searcher.Search(testMap, start, end);

            if (path.Length == 0)
            {
                Console.WriteLine("Нет пути");
            }
            else
            {
                DebugHelpers.PrintPath(testMap, path, start, end);
                Console.WriteLine("\nПуть по шагам:");

                foreach (var step in path)
                {
                    Console.WriteLine($"X:{step.X} Y:{step.Y}");
                }
            }
        }