summaryrefslogtreecommitdiffstats
path: root/binary_tree.py
blob: b12553976cfffc7c1f35a84058c2a14d1d04639d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import random


class BinaryTree(object):
    def on(grid):
        for cell in grid.each_cell():
            neighbors = []
            if cell.north:
                neighbors.append(cell.north)
            if cell.east:
                neighbors.append(cell.east)

            if neighbors:
                neighbor = random.choice(neighbors)
                cell.link(neighbor)

        return grid