public static void GenerateSidewinder(Grid grid) { var run = new List <Cell>(grid.Columns); //For Each Row for (int row = 0; row < grid.Rows; ++row) { //For each cell in a row for (int col = 0; col < grid.Columns; ++col) { var cell = grid.Cells[col, row]; run.Add(cell); bool hasNorthCell = HasNorthCell(grid, cell.Column, cell.Row); bool hasEastCell = HasEastCell(grid, cell.Column, cell.Row); bool shouldCloseOut = !hasEastCell || (hasNorthCell && Random.value > 0.5f); if (shouldCloseOut) { var member = SampleUtil <Cell> .Sample(run); if (HasNorthCell(grid, member.Column, member.Row)) { member.Link(GetNorthCell(grid, member.Column, member.Row), true); } run.Clear(); } else { cell.Link(GetEastCell(grid, cell.Column, cell.Row), true); } } } }
public static void GenerateWilson(Grid grid) { var unvisitedCells = new List <Cell>(grid.Cells.Length); foreach (var cell in grid.Cells) { unvisitedCells.Add(cell); } var firstCell = SampleUtil <Cell> .Sample(unvisitedCells); unvisitedCells.Remove(firstCell); while (unvisitedCells.Count > 0) { var cell = SampleUtil <Cell> .Sample(unvisitedCells); List <Cell> path = new List <Cell> { cell }; while (unvisitedCells.Contains(cell)) { cell = SampleUtil <Cell> .Sample(cell.GetNeighboursList()); var cellIndex = path.IndexOf(cell); if (cellIndex == -1) { path.Add(cell); } else { path = path.GetRange(0, cellIndex + 1); } } for (int i = 0; i < path.Count - 1; ++i) { path[i].Link(path[i + 1], true); unvisitedCells.Remove(path[i]); } } }
public static void GenerateAldousBroder(Grid grid) { var cell = grid.GetRandomCell(); int unvisited = grid.Cells.Length - 1; while (unvisited > 0) { var neighbours = cell.GetNeighboursList(); var neighbour = SampleUtil <Cell> .Sample(neighbours); if (neighbour.Links.Count == 0) { cell.Link(neighbour, true); unvisited -= 1; } cell = neighbour; } }