Пример #1
0
 def test_rebirth_of_dead_cell_from_reproducable_population(self):
     universe = Universe(5, 5)
     subjectCell = Cell(2, 2)
     lives = [Cell(1, 1), Cell(3, 1), Cell(3, 3)]
     universe.seed(lives)
     next_gen_lives = universe.evolve().lives
     assert subjectCell in next_gen_lives
Пример #2
0
 def test_survival_from_wellpopulated_neighbourhood(self):
     universe = Universe(5, 5)
     subjectCell = Cell(2, 2)
     lives = [Cell(1, 1), Cell(3, 1), subjectCell, Cell(3, 3)]
     universe.seed(lives)
     next_gen_lives = universe.evolve().lives
     assert subjectCell in next_gen_lives
Пример #3
0
 def test_death_from_underpopulated_neighbourhood(self):
     universe = Universe(5, 5)
     lives = [Cell(2, 2)]
     universe.seed(lives)
     actual = universe.evolve().lives
     expected = []
     assert actual == expected
Пример #4
0
 def test_alive_neighbours(self):
     universe = Universe(5, 5)
     lives = [
         Cell(1, 1),
         Cell(3, 3),
     ]
     universe.seed(lives)
     assert universe.alive_neighbours(Cell(2,
                                           2)) == [Cell(1, 1),
                                                   Cell(3, 3)]
Пример #5
0
 def test_generations_to_iterate_for_tub_lives(self):
     # Ref.: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
     universe = Universe(5, 5)
     tub_lives = [
         Cell(1, 2),
         Cell(2, 1),
         Cell(2, 3),
         Cell(3, 2),
     ]
     universe.seed(tub_lives)
     universe.generations_to_iterate(3)
     assert universe.lives == tub_lives
Пример #6
0
def main():
    # Configure your Universe Gride size here
    universe = Universe(25, 25)
    number_of_gens_to_iterate = 3

    # Different seed data to try
    tub_lives = [Cell(1, 2), Cell(2, 1), Cell(2, 3), Cell(3, 2)]
    glider_lives = [
        Cell(9, 8),
        Cell(10, 9),
        Cell(8, 10),
        Cell(9, 10),
        Cell(10, 10),
    ]
    # Configure your seed data here
    seed_data = glider_lives

    universe.seed(seed_data)
    universe.generations_to_iterate(number_of_gens_to_iterate)
Пример #7
0
 def test_generations_to_iterate_for_glider_lives(self):
     # Ref.: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
     universe = Universe(25, 25)
     glider_lives = [
         Cell(9, 8),
         Cell(10, 9),
         Cell(8, 10),
         Cell(9, 10),
         Cell(10, 10),
     ]
     universe.seed(glider_lives)
     universe.generations_to_iterate(3)
     assert universe.lives == [
         Cell(9, 9),
         Cell(9, 11),
         Cell(10, 10),
         Cell(10, 11),
         Cell(11, 10),
     ]
Пример #8
0
 def test_lives_after_seeding(self):
     universe = Universe(5, 5)
     lives = [Cell(2, 2)]
     universe.seed(lives)
     assert universe.lives == [Cell(2, 2)]
Пример #9
0
 def test_is_dead_cell(self):
     universe = Universe(5, 5)
     lives = [Cell(2, 2)]
     universe.seed(lives)
     assert universe.is_dead_cell(Cell(1, 1)) == True
     assert universe.is_dead_cell(Cell(2, 2)) == False