本文整理匯總了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)