def fill(self, ttype, alive=False): c1, c3 = self.c1, self.c3 for y in range(c1.y, c3.y + 1): for x in range(c1.x, c3.x + 1): if ttype == ' ': fld.remove(wall, Location(x, y)) else: Thing(fld, ttype, Location(x, y), alive)
def add_walls(): for x in range(5, 80, 4): L = Location locs = [] for y in range(2, 10): locs.append(L(x, y)) locs.append(L(x + 1, y)) for l in locs: Thing(fld, wall, l, False)
def lifernd(self, fld, location, val, neighbours): """Fuzzy game of life.""" add = 3 rnd = random() if rnd > 0.8: add = 2 elif rnd > 0.7: add = 5 elif rnd > 0.6: add = 4 if val == ' ': if neighbours == add: things.append(Thing(fld, cell, location)) elif not val.alive: return elif not (1 < neighbours < 4) and random() > 0.5: val.remove()
def __init__(self, screen, screen_size, mic=None): # parent class init super().__init__(screen, screen_size, mic) from things import Thing # create thing self.thing = Thing(position=self.grid_world.grid_to_pos([22, 18]), scale=(2, 2)) # add to sprites self.all_sprites.add(self.thing) self.henry.thing_sprites.add(self.thing) # determine position self.henry.set_position(self.grid_world.grid_to_pos([10, 10]), is_init_pos=True)
def lifend(self, fld, location, val, neighbours): """Fuzzy game of life with night/day variations.""" add = 3 rmv = [1, 4] rmv_rnd = 0.5 rnd = random() if rnd > 0.8: add = 2 elif rnd > 0.7: add = 5 elif rnd > 0.6: add = 4 x = int(self.n / 10) if int(self.n / 15) % 2: add += 1 rmv[0] = 2 rmv_rnd = 0.58 if val == ' ': if neighbours == add: things.append(Thing(fld, cell, location)) elif not val.alive: return elif not (rmv[0] < neighbours < rmv[1]) and random() > rmv_rnd: val.remove() self.add = add
def life(self, fld, location, val, neighbours): if val == ' ': if neighbours == 3: things.append(Thing(fld, cell, location)) elif not (1 < neighbours < 4): val.remove()