def test_that_death_cell_lives_with_3_alive_neighbours(self): world = World(2, 2) world.set([ [Cell(0), Cell(1)], [Cell(1), Cell(1)] ]) world.evolve() self.assertEqual(1, world.world[0][0].status)
def test_that_cell_keeps_death_4_alive_neighbours(self): world = World(3, 2) world.set([ [Cell(1), Cell(0), Cell(1)], [Cell(1), Cell(1), Cell(0)] ]) world.evolve() self.assertEqual(0, world.world[0][1].status)
class GameOfLife(Widget): def create_world(self): self.world = World(80, 60) self.world.generate() self.paint() def update(self, dt): self.world.evolve() self.paint() def paint(self): self.canvas.clear() with self.canvas: for x in range(self.world.width): for y in range(self.world.height): if self.world.world[y][x].status == 1: Rectangle(pos=(x*10, y*10), size=(10, 10))