def reset(self, cells=[]): for y, l in enumerate(cells): for x, c in enumerate(l): switch(c, '_', lambda: self.cells[(x, y)].die(), '*', lambda: self.cells[(x, y)].live(), '*', lambda: self.cells.__setitem__((x, y), Cell.ALIVE))
def next(self): for cell in self.cells.values(): count = len(filter(lambda c: c.state == Cell.ALIVE, cell.neighbors)) cell.next_state = switch(count, 2, cell.state, 3, Cell.ALIVE, Cell.DEAD) for cell in self.cells.values(): cell.tick()
def next(self): for cell in self.cells.values(): count = len(filter(lambda c: c.state == Cell.ALIVE, cell.neighbors)) cell.next_state = switch( count, 2, cell.state, 3, Cell.ALIVE, Cell.DEAD) for cell in self.cells.values(): cell.tick()
def reset(self, cells=[]): for y, l in enumerate(cells): for x, c in enumerate(l): switch(c, '_', lambda: self.cells[ (x, y)].die(), '*', lambda: self.cells[(x, y)].live(), '*', lambda: self.cells.__setitem__((x, y), Cell.ALIVE))
def tick(self): switch(self.state(), 'seed', self.tick_for_seed, 'rooted', self.tick_for_rooted, 'sprouted', self.tick_for_sprouted)