コード例 #1
0
ファイル: Program.cs プロジェクト: gabsot22/maze-traversal
        /// <summary>
        /// This is the main entry point for the program.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Starting Coordinates.
            const int X_START = 1;
            const int Y_START = 1;

            // The first maze that needs to be solved.
            // Note: You may want to make a smaller version to test and debug with.
            // You don't have to, but it might make your life easier.
            char[,] maze1 =
                // USE THIS
            { { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' },
              { '#', '.', '.', '.', '#', '.', '.', '.', '.', '.', '.', '#' },
              { '#', '.', '#', '.', '#', '.', '#', '#', '#', '#', '.', '#' },
              { '#', '#', '#', '.', '#', '.', '.', '.', '.', '#', '.', '#' },
              { '#', '.', '.', '.', '.', '#', '#', '#', '.', '#', '.', '.' },
              { '#', '#', '#', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
              { '#', '.', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
              { '#', '#', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
              { '#', '.', '.', '.', '.', '.', '.', '.', '.', '#', '.', '#' },
              { '#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '.', '#' },
              { '#', '.', '.', '.', '.', '.', '.', '#', '.', '.', '.', '#' },
              { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' } };

            //// Small maze to test
            //{ { '#', '#', '#', '#', '#' },
            // { '#', '.', '.', '#', '#', },
            // { '#', '#', '.', '#', '#', },
            // { '#', '#', '.', '.', '.', },
            // { '#', '#', '#', '#', '#' } };


            // Create a new instance of a mazeSolver.
            MazeSolver mazeSolver = new MazeSolver();

            // Solve the original maze.
            mazeSolver.SolveMaze(maze1, X_START, Y_START);


            // Create the second maze by transposing the first maze
            char[,] maze2 = transposeMaze(maze1);

            //for (int r = 0; r < maze2.GetLength(0); r++)
            //{
            //    for (int c = 0; c < maze2.GetLength(1); c++)
            //        Console.Write("{0}  ", maze2[r, c]);            // rOW, cOLUMN - USE IT kiss!
            //    Console.WriteLine();
            //}
            //Console.WriteLine();

            // Solve the transposed maze.
            mazeSolver.SolveMaze(maze2, X_START, Y_START);
        }
コード例 #2
0
        /// <summary>
        /// This is the main entry point for the program.
        /// </summary>
        static void Main()
        {
            // Starting Coordinates.
            const int X_START = 1;
            const int Y_START = 1;

            ArrayTransposer transposer = new ArrayTransposer();

            // The first maze that needs to be solved.
            char[,] maze1 =
            {
                { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' },
                { '#', '.', '.', '.', '#', '.', '.', '.', '.', '.', '.', '#' },
                { '#', '.', '#', '.', '#', '.', '#', '#', '#', '#', '.', '#' },
                { '#', '#', '#', '.', '#', '.', '.', '.', '.', '#', '.', '#' },
                { '#', '.', '.', '.', '.', '#', '#', '#', '.', '#', '.', '.' },
                { '#', '#', '#', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
                { '#', '.', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
                { '#', '#', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
                { '#', '.', '.', '.', '.', '.', '.', '.', '.', '#', '.', '#' },
                { '#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '.', '#' },
                { '#', '.', '.', '.', '.', '.', '.', '#', '.', '.', '.', '#' },
                { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' }
            };

            // Create a new instance of a mazeSolver.
            MazeSolver mazeSolver = new MazeSolver();

            // Solve the original maze.
            if (mazeSolver.SolveMaze(maze1, X_START, Y_START))
            {
                Console.WriteLine("Maze 1 is solved!\n\nSolving Maze 2...");
                // Since we wrote into the maze to mark the positions,
                // we have to unwrite it back to its initial state
                MazeReset(maze1);
                System.Threading.Thread.Sleep(2000);
            }

            // Create the second maze by transposing the first maze
            char[,] maze2 = TransposeMaze(transposer, maze1);
            if (mazeSolver.SolveMaze(maze2, X_START, Y_START))
            {
                Console.WriteLine("Maze 2 is solved!\n\nexiting program...");
                System.Threading.Thread.Sleep(2000);
                Environment.Exit(0);
            }
        }
コード例 #3
0
        /// <summary>
        /// This is the main entry point for the program.
        /// You are free to add anything else you would like to this program,
        /// however the maze solving part needs to occur in the MazeSolver class.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Starting Coordinates.
            const int X_START = 1;
            const int Y_START = 1;

            // The first maze that needs to be solved.
            // Note: You may want to make a smaller version to test and debug with.
            // You don't have to, but it might make your life easier.
            char[,] maze1 =
            {
                { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' },
                { '#', '.', '.', '.', '#', '.', '.', '.', '.', '.', '.', '#' },
                { '#', '.', '#', '.', '#', '.', '#', '#', '#', '#', '.', '#' },
                { '#', '#', '#', '.', '#', '.', '.', '.', '.', '#', '.', '#' },
                { '#', '.', '.', '.', '.', '#', '#', '#', '.', '#', '.', '.' },
                { '#', '#', '#', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
                { '#', '.', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
                { '#', '#', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
                { '#', '.', '.', '.', '.', '.', '.', '.', '.', '#', '.', '#' },
                { '#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '.', '#' },
                { '#', '.', '.', '.', '.', '.', '.', '#', '.', '.', '.', '#' },
                { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' }
            };

            // Create a new instance of a mazeSolver.
            MazeSolver mazeSolver = new MazeSolver();

            // Create the second maze by transposing the first maze
            char[,] maze2 = transposeMaze(maze1);

            // Solve the original maze.
            mazeSolver.SolveMaze(maze1, X_START, Y_START);

            // Stop after solving the first maze
            Console.WriteLine();
            Console.WriteLine("Enter any Key to Solve the Transposed Maze.");
            Console.ReadLine();

            // Solve the transposed maze.
            mazeSolver.SolveMaze(maze2, X_START, Y_START);

            // Hold console open to show transposed maze solution
            Console.ReadLine();
        }
コード例 #4
0
        /// <summary>
        /// This is the main entry point for the program.
        /// You are free to add anything else you would like to this program,
        /// however the maze solving part needs to occur in the MazeSolver class.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Increase the console buffer height
            Console.BufferHeight = Int16.MaxValue - 1;

            // Starting Coordinates.
            const int X_START = 1;
            const int Y_START = 1;

            // The first maze that needs to be solved.
            // Note: You may want to make a smaller version to test and debug with.
            // You don't have to, but it might make your life easier.
            char[,] maze1 =
            { { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' },
              { '#', '.', '.', '.', '#', '.', '.', '.', '.', '.', '.', '#' },
              { '#', '.', '#', '.', '#', '.', '#', '#', '#', '#', '.', '#' },
              { '#', '#', '#', '.', '#', '.', '.', '.', '.', '#', '.', '#' },
              { '#', '.', '.', '.', '.', '#', '#', '#', '.', '#', '.', '.' },
              { '#', '#', '#', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
              { '#', '.', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
              { '#', '#', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
              { '#', '.', '.', '.', '.', '.', '.', '.', '.', '#', '.', '#' },
              { '#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '.', '#' },
              { '#', '.', '.', '.', '.', '.', '.', '#', '.', '.', '.', '#' },
              { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' } };

            // Create a new instance of a mazeSolver.
            MazeSolver mazeSolver = new MazeSolver();

            // Create the second maze by transposing the first maze
            char[,] maze2 = transposeMaze(maze1);

            // Solve the original maze.
            mazeSolver.SolveMaze(maze1, X_START, Y_START);

            // Break between solves
            Console.WriteLine("Press enter to solve the 2nd maze");
            Console.ReadLine();

            // Solve the transposed maze.
            mazeSolver.SolveMaze(maze2, X_START, Y_START);
        }