def create(grid: Grid) -> None: unvisited = [] for cell in grid.eachCell(): unvisited.append(cell) first = unvisited[random.randrange(len(unvisited))] unvisited.remove(first) while any(unvisited): cell = unvisited[random.randrange(len(unvisited))] path = [cell] while cell in unvisited: cell = cell.neighbors[random.randrange(len(cell.neighbors))] position = -1 if cell in path: position = path.index(cell) if position >= 0: path = list(islice(path, position + 1)) else: path.append(cell) for index in range(len(path) - 1): path[index].link(path[index + 1]) unvisited.remove(path[index])
def create(grid: Grid) -> None: for cell in grid.eachCell(): for neighbor in cell.neighbors: cell.link(neighbor, False) RecursiveDivision.divide(0, 0, grid.rows, grid.cols, grid)
def create(grid: Grid) -> None: for cell in grid.eachCell(): neighbors = [] if cell.north is not None: neighbors.append(cell.north) if cell.east is not None: neighbors.append(cell.east) if len(neighbors) > 0: neighbor = random.choice(neighbors) cell.link(neighbor)
def create(grid: Grid) -> None: cell = grid.randomCell() unvisited = grid.size - 1 while unvisited > 0: neighbor = cell.neighbors[random.randrange(len(cell.neighbors))] if len(neighbor.links()) == 0: cell.link(neighbor) unvisited -= 1 cell = neighbor
def create(grid: Grid) -> None: unvisited = [] for cell in grid.eachCell(): unvisited.append(cell) threshold = int(grid.size / 3) current = grid.randomCell() unvisited.remove(current) while threshold != 0: neighbor = current.neighbors[random.randrange( len(current.neighbors))] if len(neighbor.links()) == 0: current.link(neighbor) unvisited.remove(neighbor) threshold -= 1 current = neighbor while any(unvisited): cell = unvisited[random.randrange(len(unvisited))] path = [cell] while cell in unvisited: cell = cell.neighbors[random.randrange(len(cell.neighbors))] position = -1 if cell in path: position = path.index(cell) if position >= 0: path = list(islice(path, position + 1)) else: path.append(cell) for index in range(len(path) - 1): path[index].link(path[index + 1]) unvisited.remove(path[index])
def create(grid: Grid) -> None: start = grid.randomCell() active = [start] costs = {} for cell in grid.eachCell(): costs[cell] = random.randrange(100) while any(active): cell = reduce( lambda minValue, nextValue: minValue if costs[minValue] < costs[nextValue] else nextValue, active) availableNeighbors = list( filter(lambda e: len(e.links()) == 0, cell.neighbors)) if any(availableNeighbors): neighbor = reduce( lambda minValue, nextValue: minValue if costs[minValue] < costs[nextValue] else nextValue, availableNeighbors) cell.link(neighbor) active.append(neighbor) else: active.remove(cell)
def create(grid: Grid) -> None: start = grid.randomCell() active = [start] while any(active): cell = active[random.randrange(len(active))] availableNeighbors = list( filter(lambda e: len(e.links()) == 0, cell.neighbors)) if any(availableNeighbors): neighbor = availableNeighbors[random.randrange( len(availableNeighbors))] cell.link(neighbor) active.append(neighbor) else: active.remove(cell)
def create(grid: Grid) -> None: for eachRow in grid.eachRow(): run = [] for cell in eachRow: run.append(cell) atEasternBoundary = cell.east is None atNorthernBoundary = cell.north is None shouldCloseOut = atEasternBoundary or (atNorthernBoundary is not None and random.randrange(0, 2) == 0) if shouldCloseOut: member: Cell = run[random.randrange(len(run))] if member.north is not None: member.link(member.north) run.clear() else: cell.link(cell.east)
def generateGridMaze(size: int): seed = random.randint(-sys.maxsize, sys.maxsize) grid = Grid(size, size, seed) TruePrims.create(grid) grid.toPNG() print("seed: %d" % seed)