示例#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
示例#2
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
示例#3
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
示例#4
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