Streamlined program interface.
6 def iterate(self, oldgrid):
7 grid = copy.deepcopy(oldgrid)
8 for x in xrange(oldgrid.minx - 1, oldgrid.maxx + 2):
9 for y in xrange(oldgrid.miny - 1, oldgrid.maxy + 2):
10 #print x, y, self.neighbours(oldgrid, x, y)
11 n = self.neighbours(oldgrid, (x, y))
16 def neighbours(self, grid, (testx, testy)):
18 #print "testing ", testx, testy
19 for x in range(testx - 1, testx + 2):
20 for y in range(testy - 1, testy + 2):
21 if (x, y) in grid.cells:
29 def iterate(self, oldgrid):
30 grid = copy.deepcopy(oldgrid)
31 for x in xrange(oldgrid.minx - 1, oldgrid.maxx + 2):
32 for y in xrange(oldgrid.miny, oldgrid.maxy + 2):
33 #print "testing ", x, y,
34 if (x+1, y) in oldgrid.cells or (x, y-1) in oldgrid.cells:
41 class PotentialGrowth(object):
45 self.potential = 4 # values 4-8 are viable
47 def iterate(self, oldgrid):
50 for i in range(2, self.potential+1):
51 if i in oldgrid.valuemap:
52 value_pos[i] = copy.deepcopy(oldgrid.valuemap[i])
53 for value, cells in value_pos.iteritems():
55 new_pos, new_value = self.grow(grid, pos)
56 grid.set(new_pos, new_value)
57 grid.set(pos, value - 1)
60 def grow(self, grid, (x, y)):
61 n1 = [(x-1, y), (x, y+1), (x+1, y), (x, y-1)]
62 n2 = [(x+1, y+1), (x+1, y-1), (x-1, y-1), (x-1, y+1)]
66 neighbours = random.choice(random.choice((c0, c1, c2)))
67 neighbours = [n for n in neighbours if n not in grid.cells]
69 pos = random.choice(neighbours)
70 value = self.potential
73 value = grid.cells[pos]