Esempio n. 1
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
Esempio n. 2
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
Esempio n. 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
Esempio n. 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)]
Esempio n. 5
0
    def test_generations_to_iterate_for_blinker_lives(self):
        # Ref.: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
        universe = Universe(5, 5)
        blinker_lives = [
            Cell(2, 1),
            Cell(2, 2),
            Cell(2, 3),
        ]
        universe.seed(blinker_lives)
        universe.generations_to_iterate(4)
        assert universe.lives == blinker_lives

        universe.generations_to_iterate(3)
        assert universe.lives == [Cell(1, 2), Cell(2, 2), Cell(3, 2)]
Esempio n. 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)
Esempio n. 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),
     ]
Esempio n. 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)]
Esempio n. 9
0
 def test_lives_before_seeding(self):
     universe = Universe(5, 5)
     assert universe.lives == []
Esempio n. 10
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