// random /* * private void DoNextGenerationStep(List<MazeCell> activeCells) * { * int currentIndex = activeCells.Count - 1; * MazeCell currentCell = activeCells[currentIndex]; * MazeDirection direction = MazeDirections.RandomValue; * CellVector coordinates = currentCell.coordinates + direction.ToCellVector(); * if (ContainsCoordinates(coordinates)) * { * MazeCell neighbor = this.GetCellAt(coordinates); * if (neighbor == null) * { * neighbor = this.CreateCell(coordinates); * this.CreatePassage(currentCell, neighbor, direction); * activeCells.Add(neighbor); * } * else * { * this.CreateWall(currentCell, neighbor, direction); * activeCells.RemoveAt(currentIndex); * } * } * else * { * this.CreateWall(currentCell, null, direction); * activeCells.RemoveAt(currentIndex); * } * } */ // with connection check private void DoNextGenerationStep(List <MazeCell> activeCells) { //int currentIndex = activeCells.Count / 2; int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; CellVector coordinates = currentCell.coordinates + direction.ToCellVector(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = this.GetCellAt(coordinates); if (neighbor == null) { neighbor = this.CreateCell(coordinates); this.CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else { this.CreateWall(currentCell, neighbor, direction); // No longer remove the cell here. } } else { this.CreateWall(currentCell, null, direction); // No longer remove the cell here. } }
private void DoNextGenerationStep(List <MazeCell> activeCells) { // TODO: implement the maze generation // 1st: get the index of the cell you want to work with, lets take the last one in the list int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; // if the cell has already all walls and connections, we do not want to change it anymore if (currentCell.IsFullyInitialized) { // TODO: the cell should be removed from the list activeCells.RemoveAt(currentIndex); return; } // TODO: we need to find the next edge (north, east, south, or west), we want to connect. Change this to a random direction, // there is a convenient method for this defined in MazeCell MazeDirection direction = currentCell.RandomUninitializedDirection; //MazeDirection direction = MazeDirection.NORTH; // TODO: determine the new coordinates, have a look into the MazeDirections class on how to obtain CellVector from a direction CellVector coordinates = currentCell.coordinates + direction.ToCellVector(); // TODO: if the coordinates are valid, we might add a new cell, otherwise we create a wall (see functions below) if (ContainsCoordinates(coordinates)) { // TODO: fetch the cell, if its null, create a cell, add a passage (see functions below), and add the cell to the list; create a wall otherwise MazeCell neighbor = this.GetCellAt(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else { CreateWall(currentCell, neighbor, direction); } } else { // TODO: create a wall CreateWall(currentCell, null, direction); } }