public PrimsAlgorithm(Maze maze) { _common = new Common(); _common.Rand = new Random((int)DateTime.Now.Ticks); _common.EndReached = false; _common.Maze = maze; }
public CustomAlgorithm(Maze maze) { _common = new Common(); _common.Rand = new Random((int)DateTime.Now.Ticks); _common.EndReached = false; _common.Maze = maze; _common.Stack = new Stack<Cell>(); }
private void CreateMaze(int rows, int columns) { Maze = new Maze(rows, columns); _common = new Common(); _common.CreateAdjacents(Maze); ConfigurationManager.RefreshSection(SECTION); string algorithm = ConfigurationManager.AppSettings[ALGORITHM_SECTION]; if(algorithm.Equals(PRIM)) Maze.SetMazeCreationStrategy(new PrimsAlgorithm(Maze)); else if(algorithm.Equals(RECURSIVE_BACKTRACKING)) Maze.SetMazeCreationStrategy(new RecursiveBacktrackingAlgorithm(Maze)); else if (algorithm.Equals(CUSTOM)) Maze.SetMazeCreationStrategy(new CustomAlgorithm(Maze)); Maze.CreateMaze(); PrintMaze(); }
public void CreateAdjacents(Maze maze) { // TODO: Add diagonal adjacents. // The adjacents are currently only: // towards the left, the top, right, and beneath Maze = maze; for (int i = 0; i < Maze.Rows; i++) { for (int j = 0; j < Maze.Columns; j++) { if ((i - 1) >= 0) { Maze.Grid[i, j].Adjacents.Add(Maze.Grid[i - 1, j]); Maze.Grid[i - 1, j].AdjacentValue = Maze.Rand.Next(Maze.Size); } if ((i + 1) < Maze.Rows) { Maze.Grid[i, j].Adjacents.Add(Maze.Grid[i + 1, j]); Maze.Grid[i + 1, j].AdjacentValue = Maze.Rand.Next(Maze.Size); } if ((j - 1) >= 0) { Maze.Grid[i, j].Adjacents.Add(Maze.Grid[i, j - 1]); Maze.Grid[i, j - 1].AdjacentValue = Maze.Rand.Next(Maze.Size); } if ((j + 1) < Maze.Columns) { Maze.Grid[i, j].Adjacents.Add(Maze.Grid[i, j + 1]); Maze.Grid[i, j + 1].AdjacentValue = Maze.Rand.Next(Maze.Size); } } } }