summaryrefslogtreecommitdiffstats
path: root/sidewinder.py
diff options
context:
space:
mode:
Diffstat (limited to 'sidewinder.py')
-rw-r--r--sidewinder.py28
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