本文整理汇总了Python中game_of_life.GameOfLife.get_next_generation方法的典型用法代码示例。如果您正苦于以下问题:Python GameOfLife.get_next_generation方法的具体用法?Python GameOfLife.get_next_generation怎么用?Python GameOfLife.get_next_generation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类game_of_life.GameOfLife
的用法示例。
在下文中一共展示了GameOfLife.get_next_generation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestGameOfLife
# 需要导入模块: from game_of_life import GameOfLife [as 别名]
# 或者: from game_of_life.GameOfLife import get_next_generation [as 别名]
#.........这里部分代码省略.........
self._assert_cells_are_dead_in_next_generation((1, 1))
def test_any_live_cell_with_more_than_three_live_neighbours_dies_example_3(self):
self.game_of_life.set_alive_cells(((0, 0), (0, 1), (0, 2),
(1, 0), (1, 1), (1, 2),
(2, 1)))
self._assert_cells_are_dead_in_next_generation((1, 1))
def test_any_live_cell_with_more_than_three_live_neighbours_dies_example_4(self):
self.game_of_life.set_alive_cells(((0, 0), (0, 1), (0, 2),
(1, 0), (1, 1), (1, 2),
(2, 0), (2, 1)))
self._assert_cells_are_dead_in_next_generation((1, 1))
def test_any_live_cell_with_more_than_three_live_neighbours_dies_example_5(self):
self.game_of_life.set_alive_cells(((0, 0), (0, 1), (0, 2),
(1, 0), (1, 1), (1, 2),
(2, 0), (2, 1), (2, 2)))
self._assert_cells_are_dead_in_next_generation((1, 1))
def test_any_live_cell_with_two_or_three_live_neighbours_lives_on_example_1(self):
self.game_of_life.set_alive_cells(( (0, 1),
(1, 0), (1, 2),
(2, 1)))
self._assert_cells_are_alive_in_next_generation(( (0, 1),
(1, 0), (1, 2),
(2, 1)))
def test_any_live_cell_with_two_or_three_live_neighbours_lives_on_example_2(self):
self.game_of_life.set_alive_cells(( (0, 1),
(1, 0), (1, 1), (1, 2),
(2, 1)))
self._assert_cells_are_alive_in_next_generation(( (0, 1),
(1, 0), (1, 2),
(2, 1)))
def test_any_dead_cell_with_exactly_three_live_neighbours_becomes_alive(self):
self.game_of_life.set_alive_cells(( (0, 1),
(1, 0), (1, 1), (1, 2),
(2, 1)))
self._assert_cells_are_alive_in_next_generation(((0, 0), (0, 2),
(2, 0), (2, 2)))
def test_suggested_example(self):
self.game_of_life.set_alive_cells(( (1, 4),
(2, 3), (2, 4)))
self._assert_exactly_these_cells_are_alive_in_next_generation(
((1, 3), (1, 4),
(2, 3), (2, 4)))
def test_oscillation(self):
initially_alive_cells = ((0, 0), (0, 1), (0, 2))
self.game_of_life.set_alive_cells(initially_alive_cells)
self._assert_exactly_these_cells_are_alive_in_next_generation(
((-1, 1),
( 0, 1),
( 1, 1)))
self._assert_exactly_these_cells_are_alive_in_next_generation(initially_alive_cells)
def test_glider(self):
self.game_of_life.set_alive_cells(
( (0, 1),
(1, 2),
(2, 0), (2, 1), (2, 2)))
self._assert_exactly_these_cells_are_alive_in_next_generation(
(
(1, 0), (1, 2),
(2, 1), (2, 2),
(3, 1)))
self._assert_exactly_these_cells_are_alive_in_next_generation(
(
(1, 2),
(2, 0), (2, 2),
(3, 1), (3, 2)))
self._assert_exactly_these_cells_are_alive_in_next_generation(
(
(1, 1),
(2, 2), (2, 3),
(3, 1), (3, 2)))
self._assert_exactly_these_cells_are_alive_in_next_generation(
(
(1, 2),
(2, 3),
(3, 1), (3, 2), (3, 3)))
def _assert_cells_are_dead_in_next_generation(self, cells):
self._cells_alive = self.game_of_life.get_next_generation()
self.assertEqual(Set(), Set(cells) & self._cells_alive)
def _assert_cells_are_alive_in_next_generation(self, cells):
self._cells_alive = self.game_of_life.get_next_generation()
self.assertTrue(Set(cells) <= self._cells_alive)
def _assert_exactly_these_cells_are_alive_in_next_generation(self, cells):
self._cells_alive = self.game_of_life.get_next_generation()
self.assertEqual(Set(cells), self._cells_alive)