Exemple #1
0
def test_count_neighbors(rules, world, world_single):
    gl = GameOfLife(rules, world_single)
    neighbors = gl.get_neighbors((1, 1))
    count = gl.count_neighbors(neighbors)

    assert count == 3

    gl.world = world
    neighbors = gl.get_neighbors((0, 0))
    count = gl.count_neighbors(neighbors)
    assert count == 2
Exemple #2
0
 def test_get_neighbors_corner(self):
     game = GameOfLife(xsize=3, ysize=3)
     neighbors = game.get_neighbors(0, 0)
     self.assertEqual(len(neighbors), 3)
     self.assertIn((0, 1), neighbors)
     self.assertIn((1, 0), neighbors)
     self.assertIn((1, 1), neighbors)
Exemple #3
0
def birth(gl: GameOfLife, value: int, index: Tuple[int, int]):
    neighbors = gl.get_neighbors(index)
    count = gl.count_neighbors(neighbors)

    if count == 3:
        return 1
    return value
Exemple #4
0
 def test_get_neighbors_with_focal(self):
     game = GameOfLife(xsize=3, ysize=3)
     game.set_include_focal()
     neighbors = game.get_neighbors(1, 0)
     self.assertEqual(len(neighbors), 6)
     self.assertIn((0, 0), neighbors)
     self.assertIn((0, 1), neighbors)
     self.assertIn((1, 0), neighbors)
     self.assertIn((1, 1), neighbors)
     self.assertIn((2, 0), neighbors)
     self.assertIn((2, 1), neighbors)
Exemple #5
0
 def test_get_neighbors(self):
     game = GameOfLife(xsize=3, ysize=3)
     neighbors = game.get_neighbors(1, 1)
     self.assertEqual(len(neighbors), 8)
     self.assertIn((0, 0), neighbors)
     self.assertIn((0, 1), neighbors)
     self.assertIn((0, 2), neighbors)
     self.assertIn((1, 0), neighbors)
     self.assertIn((1, 2), neighbors)
     self.assertIn((2, 0), neighbors)
     self.assertIn((2, 1), neighbors)
     self.assertIn((2, 2), neighbors)
Exemple #6
0
def underpopulation(gl: GameOfLife, value: int, index: Tuple[int, int]):
    neighbors = gl.get_neighbors(index)
    count = gl.count_neighbors(neighbors)
    if count <= 2:
        return 0
    return value
Exemple #7
0
def overpopulation(gl: GameOfLife, value: int, index: Tuple[int, int]):
    neighbors = gl.get_neighbors(index)
    count = gl.count_neighbors(neighbors)
    if count > 3:
        return 0 if value <= 0 else value - 1
    return value
Exemple #8
0
def test_get_neighbors(rules, world, world_single):
    gl = GameOfLife(rules, world_single)

    neighbors = gl.get_neighbors((1, 1))
    assert world_single.all() == np.array(neighbors).all()
    assert world_single.shape == (3, 3)