コード例 #1
0
ファイル: example.py プロジェクト: yattom/pypattern
 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))
コード例 #2
0
 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()
コード例 #3
0
ファイル: example.py プロジェクト: yattom/pypattern
 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()
コード例 #4
0
 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))
コード例 #5
0
ファイル: designed_plant.py プロジェクト: yattom/flower
 def tick(self):
     switch(self.state(),
            'seed', self.tick_for_seed,
            'rooted', self.tick_for_rooted,
            'sprouted', self.tick_for_sprouted)