diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2016-07-23 01:14:27 +0200 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2016-07-23 01:14:27 +0200 |
commit | e1ed22231d955eedf3895adf72fd3fbbeb133376 (patch) | |
tree | 7741d2c4cfa2eac191def2a272b1cfa7dad57d95 /sidewinder.py | |
download | maze-e1ed22231d955eedf3895adf72fd3fbbeb133376.tar.xz |
Initial commit
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Diffstat (limited to 'sidewinder.py')
-rw-r--r-- | sidewinder.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sidewinder.py b/sidewinder.py new file mode 100644 index 0000000..c047eed --- /dev/null +++ b/sidewinder.py @@ -0,0 +1,28 @@ +import random + + +class Sidewinder(object): + def on(grid): + for row in grid.each_row(): + run = [] + + for cell in row: + run.append(cell) + + at_eastern_boundary = (cell.east == None) + at_northern_boundary = (cell.north == None) + + should_close_out = at_eastern_boundary or \ + (not at_northern_boundary and random.randint(0, 1) == 0) + + if should_close_out: + member = random.choice(run) + if member.north: + member.link(member.north) + del run[:] + else: + cell.link(cell.east) + + #print(grid) + + return grid |