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
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
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
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