Example #1
0
        public void AutoExplore_when_called_for_minimalistic_maze_returns_route()
        {
            var explorer = new Explorer(MinimalMaze);

            var route = AutoExplorer.Explore(explorer).ToArray();

            Assert.AreEqual(new Cell(0, 1), route[0]);
            Assert.AreEqual(new Cell(1, 1), route[1]);
            Assert.AreEqual(new Cell(2, 1), route[2]);
        }
Example #2
0
        public void AutoExplore_when_called_for_big_maze_finds_finish()
        {
            MazeGenerator generator = new MazeGenerator();
            var           maze      = generator.Generate(10, 10, new MazeGeneratorTest.RandomizerMock());

            var explorer = new Explorer(maze);

            var route = AutoExplorer.Explore(explorer).ToArray();

            Assert.IsTrue(explorer.IsFinish);
        }
Example #3
0
        public void AutoExplore_when_called_for_randomly_generated_maze_finds_finish()
        {
            for (int i = 0; i < 10; i++)
            {
                MazeGenerator generator = new MazeGenerator();
                var           maze      = generator.Generate(10, 10, new Excelian.Maze.Generator.Randomizer());

                var explorer = new Explorer(maze);

                var route = AutoExplorer.Explore(explorer).ToArray();
                Assert.IsTrue(explorer.IsFinish);
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            MazeGenerator generator = new MazeGenerator();
            var           maze      = generator.Generate(20, 20, new Excelian.Maze.Generator.Randomizer());

            Console.WriteLine("Generated maze:");
            Console.WriteLine(maze.Render());
            var explorer = new Explorer(maze);

            Console.WriteLine("Route:");

            var route = AutoExplorer.Explore(explorer);

            Console.WriteLine(maze.RenderWithRoute(route));

            Console.ReadKey();
        }
Example #5
0
        public void AutoExplore_when_called_for_minimalistic_maze2_returns_route()
        {
            var maze = Maze.Create(
                new MazeCellType[, ] {
                { MazeCellType.Wall, MazeCellType.Finish, MazeCellType.Wall },   // XXX
                { MazeCellType.Wall, MazeCellType.Space, MazeCellType.Wall },    // F.S
                { MazeCellType.Wall, MazeCellType.Start, MazeCellType.Wall }
            });                                                                  // XXX

            var explorer = new Explorer(maze);

            var route = AutoExplorer.Explore(explorer).ToArray();

            Assert.IsTrue(explorer.IsFinish);
            Assert.AreEqual(new Cell(2, 1), route[0]);
            Assert.AreEqual(new Cell(1, 1), route[1]);
            Assert.AreEqual(new Cell(0, 1), route[2]);
        }
Example #6
0
        public void AutoExplore_when_called_for_maze_with_vertical_coridor()
        {
            var maze = Maze.Create(

                // ...
                // XSX
                // XFX
                new MazeCellType[, ] {
                { MazeCellType.Space, MazeCellType.Wall, MazeCellType.Wall },
                { MazeCellType.Space, MazeCellType.Start, MazeCellType.Finish },
                { MazeCellType.Space, MazeCellType.Wall, MazeCellType.Wall }
            });

            var explorer = new Explorer(maze);

            var route = AutoExplorer.Explore(explorer).ToArray();

            Assert.IsTrue(explorer.IsFinish);
        }
Example #7
0
        static void Main(string[] args)
        {
            //handle any unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                Console.WriteLine("Unhandled Exception. Exception:" + (e.ExceptionObject as Exception).ToString());
            };

            try
            {
                var mazeResourceFile = ConfigurationManager.AppSettings["MazeResourceFile"];
                if (string.IsNullOrWhiteSpace(mazeResourceFile))
                {
                    Console.WriteLine("Maze resource file not configured. Press Enter key to exit.....");
                    Console.ReadLine();
                    return;
                }
                mazeResourceFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, mazeResourceFile);
                if (!File.Exists(mazeResourceFile))
                {
                    Console.WriteLine("Maze resource file doest not exist. Press Enter key to exit.....");
                    Console.ReadLine();
                    return;
                }

                var maze = new Maze();

                maze.CreateMazeMap(File.ReadAllLines(mazeResourceFile));
                if (!maze.IsValidMaz)
                {
                    Console.WriteLine("Maze resource file is not a valid file, must have exactly one start and finishing point. Press Enter key to exit.....");
                    Console.ReadLine();
                    return;
                }
                else
                {
                    Console.WriteLine("Maze map has been created successfully.");
                    Console.WriteLine("Maze Walls:" + maze.TotalWalls());
                    Console.WriteLine("Maze Spaces:" + maze.TotalSpaces());
                    Console.WriteLine("Maze Width:" + maze.Width);
                    Console.WriteLine("Maze Height:" + maze.Height);
                    Console.WriteLine(string.Format("Maze Start Position, X:{0},Y:{1}", maze.StartPosition.X, maze.StartPosition.Y));
                    Console.WriteLine(string.Format("Maze Finishing Position, X:{0},Y:{1}", maze.FinishPosition.X, maze.FinishPosition.Y));

                    Console.WriteLine();
                }

                var           drawExplorerMovementsOnMaze = new DrawExplorerMovementsOnMaze();
                IAutoExplorer autoExplore = new AutoExplorer(maze, drawExplorerMovementsOnMaze);
                IExplorer     explorer    = autoExplore as IExplorer;

                Console.WriteLine("Shortly maze will be displayed.");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("You can navigate from the start postion to finishing point using keyboard left, right, down and up arrow keys.");
                Console.ResetColor();
                Console.WriteLine("Press Enter key to continue.....");
                Console.ReadLine();
                Console.Clear();
                //Set the x, y coordinates and draw the maze
                explorer.ShowExplorerMovementsOnMaz();
                Console.SetCursorPosition(maze.StartPosition.X, maze.StartPosition.Y);
                while (!explorer.ReachedFinishingPoint)
                {
                    var key = Console.ReadKey().Key;

                    switch (key)
                    {
                    case ConsoleKey.DownArrow:
                        explorer.MoveDown();
                        break;

                    case ConsoleKey.UpArrow:
                        explorer.MoveUp();
                        break;

                    case ConsoleKey.RightArrow:
                        explorer.MoveRight();
                        break;

                    case ConsoleKey.LeftArrow:
                        explorer.MoveLeft();
                        break;

                    default:
                        Console.SetCursorPosition(explorer.CurrentPosition.X, explorer.CurrentPosition.Y);
                        break;
                    }
                }

                Console.Beep();
                Console.Beep();

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("You have successfully made to the exit. Press Enter key to see the path taken from start to finish.....");
                Console.ReadLine();
                Console.Clear();
                explorer.ShowExplorerMovementsOnMaz();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Auto explorer will run shortly and will display the path taken on Maze. Press Enter key to continue.....");
                Console.ReadLine();
                Console.Clear();
                Console.WriteLine("Running the autoexplorer now......");
                System.Threading.Thread.Sleep(1000);
                autoExplore.AutoExplore();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Press Enter key to exit the process.....");
                Console.ReadLine();
            }

            catch (Exception ex)
            {
                Console.WriteLine("Errored while exploring the Maze. Exception:" + ex.ToString());
                Console.ReadLine();
            }
        }