Add sidewinder generator

master
JD Cantrell 7 years ago
parent 60c8276c5e
commit 3c438783aa

@ -3,12 +3,16 @@ import time
import os
def show(grid, cell, sleep=.1):
os.system('clear')
print grid.display([cell])
time.sleep(sleep)
os.system('clear')
def binary_tree_maze_generator(grid):
for cell in grid.cells():
os.system('clear')
print grid.display([cell])
time.sleep(.1)
os.system('clear')
show(grid, cell)
cells = []
if cell.east:
@ -19,7 +23,25 @@ def binary_tree_maze_generator(grid):
if len(cells):
link_to = random.choice(cells)
cell.link(link_to)
print grid.display([cell])
time.sleep(.1)
os.system('clear')
show(grid, cell)
return grid
def sidwinder_maze_generator(grid):
for row in grid.rows()[::-1]:
run = []
for cell in row:
show(grid, cell)
flip = random.randint(1, 2)
run.append(cell)
if cell.east and ((flip == 1) or (flip == 2 and not cell.north)):
cell.link(cell.east)
elif cell.north:
# if this cell does not have a north neither will our run
c = random.choice(run)
c.link(c.north)
show(grid, c)
run = []
return grid

@ -0,0 +1,4 @@
from grid import Grid
from maze_generators import sidwinder_maze_generator
print sidwinder_maze_generator(Grid(11, 20))
Loading…
Cancel
Save