static void Main(string[] args) { MazeFactory mazeFact = new MazeFactory(20, 32); MazeSolverFactory bfsSolverFact = new MazeSolverFactory(WayToSolve.BFS); MazeSolverFactory dfsSolverFact = new MazeSolverFactory(WayToSolve.BFS); WallBreakerFactory dfsWBreakerFact = new WallBreakerFactory(WallBreakerFactory.BreakingType.DFS); WallBreakerFactory randomPrimWBreakerFact = new WallBreakerFactory(WallBreakerFactory.BreakingType.Random); Console.WriteLine("Randomized DFS Generated Maze :"); IMaze mazeDfs = mazeFact.GetMaze(dfsWBreakerFact); Console.WriteLine(mazeDfs.ToString()); Console.WriteLine("\n\nRandomized DFS Maze Solution is :"); mazeDfs.SolveMaze(new MazeSolverFactory(WayToSolve.DFS)); Console.WriteLine(mazeDfs.SolutionToString()); Console.WriteLine("\n\nRandomized Prim Generated Maze :"); IMaze mazePrim = mazeFact.GetMaze(randomPrimWBreakerFact); Console.WriteLine(mazePrim.ToString()); Console.WriteLine("\n\nRandomized Prim Maze Solution is :"); mazePrim.SolveMaze(new MazeSolverFactory(WayToSolve.BFS)); Console.WriteLine(mazePrim.SolutionToString()); Console.ReadLine(); }
/// <summary> /// Creates the maze. /// </summary> /// <param name="type">The type of algorithm to use to create the maze.</param> /// <returns>the created maze</returns> public static IMaze CreateMaze(int type) { WallBreakerFactory breaker = new WallBreakerFactory((WallBreakerFactory.BreakingType)type); MazeFactory factory = new MazeFactory(int.Parse(AppSettings.Settings["rows"]), int.Parse(AppSettings.Settings["cols"])); return(factory.GetMaze(breaker)); }
/// <summary> /// Initializes a new instance of the <see cref="MatrixMaze"/> class. /// </summary> /// <param name="height">The height of the maze.</param> /// <param name="width">The width of the maze.</param> /// <param name="BreakerFact">The wall breaker factory.</param> public MatrixMaze(int height, int width, WallBreakerFactory BreakerFact) { this.mazeMatrix = new char[this.height = height * 2 - 1, this.width = width * 2 - 1]; Random r = new Random(); // randomly set a start and end positions int startCol = r.Next(this.width); startCol = startCol % 2 == 0 ? startCol : startCol - 1; int endCol = r.Next(this.width); endCol = endCol % 2 == 0 ? endCol : endCol - 1; this.startPosition = new MazePosition(0, startCol); this.endPosition = new MazePosition(this.height - 1, endCol); // initiallizes the matrix array of the maze will all doors open this.OpenAllDoors(); // generates the maze BreakerFact.GetWallBreaker().BreakWalls(this); this.solution = null; }
/// <summary> /// Gets the maze created with the given wall Breaker factory. /// </summary> /// <param name="wBreakerFactory">The wall breaker factory.</param> /// <returns>the newly created maze</returns> public IMaze GetMaze(WallBreakerFactory wBreakerFactory) { return(new MatrixMaze(this.rows, this.colomns, wBreakerFactory)); }