Beispiel #1
0
        static void Main(string[] args)
        {
            var mazeFilePath = Path.Combine(Environment.CurrentDirectory, @"TestMazes\large_maze.txt");
            var mazePuzzle   = new MazePuzzle(mazeFilePath);

            var escapeRoute = MazeRunner.SolveMaze(mazePuzzle.Maze, mazePuzzle.StartPoint, mazePuzzle.EndPoint);
            var strMaze     = MazePrinter.PrintMaze(mazePuzzle.Maze, escapeRoute);

            Console.WriteLine(strMaze);
            Console.Read();
        }
Beispiel #2
0
        /// <summary>
        /// In the context of <paramref name="maze"/>,
        /// starting at position <paramref name="currentPos"/>,
        /// Move in any available direction.
        /// </summary>
        /// <param name="maze">The current maze</param>
        /// <param name="currentPos">The current position within the maze</param>
        /// <returns>A Point representing the new location, or null if there where no legal moves</returns>
        internal static Point?MoveInAnyValidDirection(int[,] maze, Point currentPos)
        {
            if (!IsLegalPosition(maze, currentPos))
            {
                var msg = string.Format("Current position {0} is invalid for the current maze", currentPos);
                throw new ArgumentException(msg);
            }

            foreach (Direction direction in Enum.GetValues(typeof(Direction)))
            {
                var point = MazeRunner.Move(maze, currentPos, direction);
                if (point != null)
                {
                    return(point);
                }
            }
            return(null);
        }