private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; Vector2Int coordinates = currentCell.coords + direction.ToVector2Int(); if (ContainsCoordinates(coordinates) && GetCell(coordinates) == null) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }