Exemple #1
0
def test_keep_one_healthy_flower_if_all_expired():
    healthy_flower = Flower(sentinel.x,
                            sentinel.y,
                            DEFAULT_GAME_PARAMETERS,
                            sentinel.potency,
                            sentinel.visits,
                            expires=99)
    venus = VenusBeeTrap(sentinel.x,
                         sentinel.y,
                         DEFAULT_GAME_PARAMETERS,
                         sentinel.potency,
                         sentinel.visits,
                         expires=99)
    flowers = [healthy_flower, venus]
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[flowers],
                     turn_num=100,
                     game_length=sentinel.game_length)

    game.remove_dead_flowers()

    assert len(game.boards[0].flowers) == 1
    assert game.boards[0].flowers[0] == healthy_flower
Exemple #2
0
def test_land_bees_two_bees_single_board_single_hive():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(5, 5), ), ),
                     flowers=((), ),
                     game_length=sentinel.game_length)

    assert all(
        board.calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor
        for board in game.boards)

    game.boards[0].inflight[sentinel.bee_1] = Bee(5, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS, 1)
    game.boards[0].inflight[sentinel.bee_2] = Bee(5, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS, 2)
    landed_bees = game.land_bees()

    for board in game.boards:
        assert sentinel.bee_1 not in board.inflight
        assert sentinel.bee_2 not in board.inflight

    assert [board.calculate_score() for board in game.boards] == [
        DEFAULT_GAME_PARAMETERS.hive_score_factor +
        3 * DEFAULT_GAME_PARAMETERS.nectar_score_factor
    ]
    assert landed_bees == [{
        sentinel.bee_1:
        Bee(5, 5, 0, 10, DEFAULT_GAME_PARAMETERS, 1),
        sentinel.bee_2:
        Bee(5, 5, 0, 10, DEFAULT_GAME_PARAMETERS, 2)
    }]
    assert check_bee_nectar_eq_hive_nectar(landed_bees, game)
Exemple #3
0
def test_launch_bees_single_board_single_hive_probability_zero():
    params = GameParameters(launch_probability=0.0,
                            initial_energy=10,
                            dead_bee_score_factor=-5,
                            hive_score_factor=100,
                            flower_score_factor=100,
                            nectar_score_factor=2,
                            queen_bee_nectar_threshold=20,
                            bee_nectar_capacity=5,
                            bee_energy_boost_per_nectar=25,
                            flower_seed_visit_initial_threshold=10,
                            flower_seed_visit_subsequent_threshold=10,
                            flower_visit_potency_ratio=10,
                            flower_lifespan=100,
                            flower_lifespan_visit_impact=10,
                            trap_seed_probability=1,
                            venus_score_factor=-50,
                            trap_seed_lifespan=10)
    game = GameState(game_params=params,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(5, 5), ), ),
                     flowers=(sentinel.flowers, ),
                     game_length=sentinel.game_length)

    assert len(game.boards[0].inflight) == 0
    with patch("hiveminder.game_state.rngs", {sentinel.game_id: Random(0)}):
        game.launch_bees(sentinel.turn_num)

    assert len(game.boards[0].inflight) == 0
Exemple #4
0
def test_land_bees_do_not_land_bee_not_on_hive():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(5, 5), ), ),
                     flowers=((), ),
                     game_length=sentinel.game_length)

    assert all(
        board.calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor
        for board in game.boards)

    game.boards[0].inflight[sentinel.bee_1] = Bee(5, 4, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS, 1)
    landed_bees = game.land_bees()

    assert all(
        board.calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor
        for board in game.boards)
    assert sentinel.bee_1 in game.boards[0].inflight
    assert landed_bees == [{}]
    assert game.boards[0].inflight == {
        sentinel.bee_1: Bee(5, 4, 0, 10, DEFAULT_GAME_PARAMETERS, 1)
    }
    assert check_bee_nectar_eq_hive_nectar(landed_bees, game)
def test_apply_command_multiple_boards_single_bee():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=3,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives] * 3,
                     flowers=[sentinel.flowers] * 3,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.bee_1] = Bee(5, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    game.boards[1].inflight[sentinel.bee_2] = Bee(5, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    game.boards[2].inflight[sentinel.bee_3] = Bee(5, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)

    game.apply_commands([dict(entity=sentinel.bee_1, command=60), None, None])

    assert game.boards[0].inflight[sentinel.bee_1] == Bee(
        5, 5, 60, 10, DEFAULT_GAME_PARAMETERS)
    assert game.boards[1].inflight[sentinel.bee_2] == Bee(
        5, 5, 0, 10, DEFAULT_GAME_PARAMETERS)
    assert game.boards[2].inflight[sentinel.bee_3] == Bee(
        5, 5, 0, 10, DEFAULT_GAME_PARAMETERS)
Exemple #6
0
def test_flowers_remain_if_unexpired():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[[
                         Flower(sentinel.x,
                                sentinel.y,
                                DEFAULT_GAME_PARAMETERS,
                                sentinel.potency,
                                sentinel.visits,
                                expires=100)
                     ]],
                     turn_num=0,
                     game_length=sentinel.game_length)

    game.remove_dead_flowers()

    assert game.boards[0].flowers == (Flower(sentinel.x,
                                             sentinel.y,
                                             DEFAULT_GAME_PARAMETERS,
                                             sentinel.potency,
                                             sentinel.visits,
                                             expires=100), )
def test_apply_venus_command_over_existing_flower():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(9, 9), ), ),
                     flowers=((Flower(0, 0, DEFAULT_GAME_PARAMETERS,
                                      sentinel.potency, sentinel.visits),
                               Flower(9, 9, DEFAULT_GAME_PARAMETERS,
                                      sentinel.potency, sentinel.visits)), ),
                     turn_num=12345,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = TrapSeed(
        0, 0, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan)
    game.apply_commands([dict(entity=sentinel.seed_1, command="flower")])

    assert game.boards[0].inflight == {}
    assert sorted(map(str, game.boards[0].flowers)) == sorted(
        map(str, (VenusBeeTrap(
            0,
            0,
            DEFAULT_GAME_PARAMETERS,
            1,
            0,
            expires=12345 + DEFAULT_GAME_PARAMETERS.flower_lifespan),
                  Flower(9, 9, DEFAULT_GAME_PARAMETERS, sentinel.potency,
                         sentinel.visits))))
    assert game.boards[0].hives == (Hive(9, 9), )
def test_create_hive_deletes_flower():
    queen_bee = QueenBee(1,
                         2,
                         0,
                         10,
                         DEFAULT_GAME_PARAMETERS,
                         nectar=sentinel.nectar)
    game = GameState(
        game_params=DEFAULT_GAME_PARAMETERS,
        game_id=sentinel.game_id,
        boards=1,
        board_width=10,
        board_height=10,
        hives=[[]],
        flowers=[[Flower(queen_bee.x, queen_bee.y, DEFAULT_GAME_PARAMETERS)]],
        game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.queenbee_1] = queen_bee

    game.apply_commands(
        [dict(entity=sentinel.queenbee_1, command="create_hive")])
    assert game.boards[0].hives[0] == Hive(queen_bee.x, queen_bee.y,
                                           queen_bee.nectar)
    assert len(game.boards[0].inflight) == 0
    assert len(game.boards[0].flowers) == 0
Exemple #9
0
def test_land_queenbees_single_queenbee_single_board_single_hive():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(5, 5), ), ),
                     flowers=((), ),
                     game_length=sentinel.game_length)

    assert all(
        board.calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor
        for board in game.boards)

    game.boards[0].inflight[sentinel.bee_1] = QueenBee(
        5, 5, 0, 10, DEFAULT_GAME_PARAMETERS, 1)
    landed_bees = game.land_bees()

    for board in game.boards:
        assert sentinel.bee_1 not in board.inflight

    assert [board.calculate_score() for board in game.boards] == [
        DEFAULT_GAME_PARAMETERS.hive_score_factor +
        DEFAULT_GAME_PARAMETERS.dead_bee_score_factor
    ]
    assert landed_bees == [{
        sentinel.bee_1:
        QueenBee(5, 5, 0, 10, DEFAULT_GAME_PARAMETERS, 1)
    }]
    assert game.boards[0].inflight == {}
def test_apply_command_single_board_multiple_bees(initial_heading,
                                                  new_heading):
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[sentinel.flowers],
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.bee_1] = Bee(4, 5, initial_heading, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    game.boards[0].inflight[sentinel.bee_2] = Bee(5, 5, initial_heading, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    game.boards[0].inflight[sentinel.bee_3] = Bee(6, 5, initial_heading, 10,
                                                  DEFAULT_GAME_PARAMETERS)

    game.apply_commands([dict(entity=sentinel.bee_1, command=new_heading)])

    assert game.boards[0].inflight[sentinel.bee_1] == Bee(
        4, 5, new_heading, 10, DEFAULT_GAME_PARAMETERS)
    assert game.boards[0].inflight[sentinel.bee_2] == Bee(
        5, 5, initial_heading, 10, DEFAULT_GAME_PARAMETERS)
    assert game.boards[0].inflight[sentinel.bee_3] == Bee(
        6, 5, initial_heading, 10, DEFAULT_GAME_PARAMETERS)
Exemple #11
0
def test_land_bees_single_queenbee_single_regular_bee_single_board_single_hive(
):
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(5, 5), ), ),
                     flowers=((), ),
                     game_length=sentinel.game_length)

    assert all(
        board.calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor
        for board in game.boards)
    queen_bee = QueenBee(5, 5, 0, 10, DEFAULT_GAME_PARAMETERS, 1)
    bee = Bee(5, 5, 0, 10, DEFAULT_GAME_PARAMETERS, 1)
    both_bees = {sentinel.bee_1: queen_bee, sentinel.bee_2: bee}
    game.boards[0].inflight = both_bees.copy()
    landed_bees = game.land_bees()

    for board in game.boards:
        assert sentinel.bee_1 not in board.inflight
        assert sentinel.bee_2 not in board.inflight

    assert [board.calculate_score() for board in game.boards] == [
        DEFAULT_GAME_PARAMETERS.hive_score_factor +
        DEFAULT_GAME_PARAMETERS.dead_bee_score_factor +
        bee.nectar * DEFAULT_GAME_PARAMETERS.nectar_score_factor
    ]
    assert landed_bees == [both_bees]
    assert game.boards[0].inflight == {}
    assert check_bee_nectar_eq_hive_nectar([{sentinel.bee_2: bee}], game)
Exemple #12
0
def test_visit_flowers_two_bees_two_flowers():
    game = GameState(
        game_params=DEFAULT_GAME_PARAMETERS,
        game_id=sentinel.game_id,
        boards=1,
        board_width=10,
        board_height=10,
        hives=(sentinel.hives, ),
        flowers=((Flower(5,
                         5,
                         DEFAULT_GAME_PARAMETERS,
                         1,
                         expires=DEFAULT_GAME_PARAMETERS.flower_lifespan),
                  Flower(5,
                         4,
                         DEFAULT_GAME_PARAMETERS,
                         1,
                         expires=DEFAULT_GAME_PARAMETERS.flower_lifespan)), ),
        game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.bee_1] = Bee(5, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS, 0)
    game.boards[0].inflight[sentinel.bee_2] = Bee(5, 4, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS, 0)
    game.visit_flowers()

    assert game.boards[0].inflight == {
        sentinel.bee_1:
        Bee(5, 5, 0, 10 + DEFAULT_GAME_PARAMETERS.bee_energy_boost_per_nectar,
            DEFAULT_GAME_PARAMETERS, 1),
        sentinel.bee_2:
        Bee(5, 4, 0, 10 + DEFAULT_GAME_PARAMETERS.bee_energy_boost_per_nectar,
            DEFAULT_GAME_PARAMETERS, 1),
    }
Exemple #13
0
def test_expire_venus_flowers_when_there_are_no_healthy_flowers():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[[
                         VenusBeeTrap(sentinel.x1,
                                      sentinel.y1,
                                      DEFAULT_GAME_PARAMETERS,
                                      sentinel.potency,
                                      sentinel.visits,
                                      expires=100),
                         VenusBeeTrap(sentinel.x2,
                                      sentinel.y2,
                                      DEFAULT_GAME_PARAMETERS,
                                      sentinel.potency,
                                      sentinel.visits,
                                      expires=200)
                     ]],
                     turn_num=100,
                     game_length=sentinel.game_length)

    game.remove_dead_flowers()

    assert game.boards[0].flowers == (VenusBeeTrap(sentinel.x2,
                                                   sentinel.y2,
                                                   DEFAULT_GAME_PARAMETERS,
                                                   sentinel.potency,
                                                   sentinel.visits,
                                                   expires=200), )
Exemple #14
0
def test_only_expired_flowers_removed_from_mixed_bunch():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[[
                         Flower(sentinel.x1,
                                sentinel.y1,
                                DEFAULT_GAME_PARAMETERS,
                                sentinel.potency1,
                                sentinel.visits1,
                                expires=10),
                         Flower(sentinel.x2,
                                sentinel.y2,
                                DEFAULT_GAME_PARAMETERS,
                                sentinel.potency2,
                                sentinel.visits2,
                                expires=50),
                         Flower(sentinel.x3,
                                sentinel.y3,
                                DEFAULT_GAME_PARAMETERS,
                                sentinel.potency3,
                                sentinel.visits3,
                                expires=100),
                         VenusBeeTrap(sentinel.x3,
                                      sentinel.y3,
                                      DEFAULT_GAME_PARAMETERS,
                                      sentinel.potency3,
                                      sentinel.visits3,
                                      expires=50),
                         VenusBeeTrap(sentinel.x3,
                                      sentinel.y3,
                                      DEFAULT_GAME_PARAMETERS,
                                      sentinel.potency3,
                                      sentinel.visits3,
                                      expires=100),
                     ]],
                     turn_num=75,
                     game_length=sentinel.game_length)

    game.remove_dead_flowers()

    assert game.boards[0].flowers == (
        Flower(sentinel.x3,
               sentinel.y3,
               DEFAULT_GAME_PARAMETERS,
               sentinel.potency3,
               sentinel.visits3,
               expires=100),
        VenusBeeTrap(sentinel.x3,
                     sentinel.y3,
                     DEFAULT_GAME_PARAMETERS,
                     sentinel.potency3,
                     sentinel.visits3,
                     expires=100),
    )
Exemple #15
0
def test_game_over(turn_num, game_length, game_over):
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[sentinel.flowers],
                     turn_num=turn_num,
                     game_length=game_length)

    assert game.game_over() == game_over
Exemple #16
0
def test_do_nothing_if_there_are_no_flowers():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[[]],
                     turn_num=100,
                     game_length=sentinel.game_length)

    game.remove_dead_flowers()

    assert len(game.boards[0].flowers) == 0
def test_only_queenbees_can_create_hive():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[[]],
                     flowers=[[Flower(1, 2, DEFAULT_GAME_PARAMETERS)]],
                     game_length=sentinel.game_length)

    queen_bee = QueenBee(4,
                         4,
                         0,
                         10,
                         DEFAULT_GAME_PARAMETERS,
                         nectar=sentinel.nectar)
    game.boards[0].inflight[sentinel.bee_1] = Bee(4, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    game.boards[0].inflight[sentinel.queenbee_1] = queen_bee
    game.boards[0].inflight[sentinel.seed_1] = Seed(3, 3, 0)

    with pytest.raises(RuntimeError):
        game.apply_commands(
            [dict(entity=sentinel.bee_1, command="create_hive")])

    with pytest.raises(RuntimeError):
        game.apply_commands(
            [dict(entity=sentinel.seed_1, command="create_hive")])

    game.apply_commands(
        [dict(entity=sentinel.queenbee_1, command="create_hive")])
    assert game.boards[0].hives[0] == Hive(queen_bee.x, queen_bee.y,
                                           queen_bee.nectar)
    assert len(game.boards[0].inflight) == 2
def test_apply_command_no_command():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[sentinel.flowers],
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.bee_1] = Bee(4, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    game.apply_commands([None])

    assert game.boards[0].inflight[sentinel.bee_1] == Bee(
        4, 5, 0, 10, DEFAULT_GAME_PARAMETERS)
def test_apply_command_too_many_commands():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[sentinel.flowers],
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.bee_1] = Bee(4, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    with pytest.raises(ValueError) as err:
        game.apply_commands([dict(entity=sentinel.bee_1, command=0), None])

    assert str(err.value) == "You must specify a command for each board."
def test_apply_command_bee_in_wrong_board():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=2,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives] * 2,
                     flowers=[sentinel.flowers] * 2,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.bee_1] = Bee(4, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    with pytest.raises(RuntimeError) as err:
        game.apply_commands([None, dict(entity=sentinel.bee_1, command=0)])

    assert str(err.value) == "Unknown entity."
def test_bees_can_not_flower():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[sentinel.flowers],
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.bee_1] = Bee(4, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)

    with pytest.raises(RuntimeError) as err:
        game.apply_commands([dict(entity=sentinel.bee_1, command="flower")])

    assert str(err.value).startswith("Can not rotate to heading")
Exemple #22
0
def test_seed_does_not_visit_flower():
    game = GameState(
        game_params=DEFAULT_GAME_PARAMETERS,
        game_id=sentinel.game_id,
        boards=1,
        board_width=10,
        board_height=10,
        hives=(sentinel.hives, ),
        flowers=((Flower(
            5, 5, DEFAULT_GAME_PARAMETERS, 1,
            DEFAULT_GAME_PARAMETERS.flower_lifespan_visit_impact), ), ),
        game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = Seed(5, 5, 0)
    game.visit_flowers()

    assert game.boards[0].inflight == {sentinel.seed_1: Seed(5, 5, 0)}
Exemple #23
0
def move_seeds_test_impl(boards, from_details, to_board, to_details):
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=boards,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives] * boards,
                     flowers=[sentinel.flowers] * boards,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = from_details
    game.move_volants()

    assert [
        i for i, board in enumerate(game.boards)
        if sentinel.seed_1 in board.inflight
    ] == [to_board]
    assert game.boards[to_board].inflight == {sentinel.seed_1: to_details}
Exemple #24
0
def test_flowers_seeds_make_flowers_means_points():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(9, 9), ), ),
                     flowers=((), ),
                     game_length=sentinel.game_length)

    assert all(
        board.calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor
        for board in game.boards)

    game.boards[0].inflight[sentinel.seed_1] = Seed(4, 5, 0)
    game.apply_commands([dict(entity=sentinel.seed_1, command="flower")])

    assert all(board.calculate_score() == (
        DEFAULT_GAME_PARAMETERS.hive_score_factor +
        DEFAULT_GAME_PARAMETERS.flower_score_factor) for board in game.boards)
Exemple #25
0
def test_visiting_flower_does_not_create_seeds_when_not_seed_threshold(visits):
    game = GameState(
        game_params=DEFAULT_GAME_PARAMETERS,
        game_id=sentinel.game_id,
        boards=1,
        board_width=10,
        board_height=10,
        hives=(sentinel.hives, ),
        flowers=((Flower(
            5, 5, DEFAULT_GAME_PARAMETERS, 3, visits - 1,
            DEFAULT_GAME_PARAMETERS.flower_lifespan_visit_impact), ), ),
        game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.bee_1] = Bee(5, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    game.visit_flowers()

    assert game.boards[0].inflight == {
        sentinel.bee_1: Bee(5, 5, 0, 85, DEFAULT_GAME_PARAMETERS, 3)
    }
Exemple #26
0
def test_no_expiry_causes_error():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[[
                         Flower(sentinel.x,
                                sentinel.y,
                                DEFAULT_GAME_PARAMETERS,
                                sentinel.potency,
                                sentinel.visits,
                                expires=None)
                     ]],
                     turn_num=0,
                     game_length=sentinel.game_length)

    with pytest.raises(RuntimeError):
        game.remove_dead_flowers()
def test_apply_flower_command_empty_tile():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(9, 9), ), ),
                     flowers=((Flower(0, 0, DEFAULT_GAME_PARAMETERS), ), ),
                     turn_num=12345,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = Seed(4, 5, 0)
    game.apply_commands([dict(entity=sentinel.seed_1, command="flower")])

    assert game.boards[0].inflight == {}
    assert game.boards[0].flowers == (Flower(0, 0, DEFAULT_GAME_PARAMETERS),
                                      Flower(4,
                                             5,
                                             DEFAULT_GAME_PARAMETERS,
                                             expires=12645))
    assert game.boards[0].hives == (Hive(9, 9), )
def test_apply_venus_command_over_existing_single_hive():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(9, 9), ), ),
                     flowers=((Flower(0, 0, DEFAULT_GAME_PARAMETERS), ), ),
                     turn_num=12345,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = TrapSeed(
        9, 9, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan)
    game.apply_commands([dict(entity=sentinel.seed_1, command="flower")])

    assert game.boards[0].inflight == {
        sentinel.seed_1:
        TrapSeed(9, 9, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan)
    }
    assert game.boards[0].flowers == (Flower(0, 0, DEFAULT_GAME_PARAMETERS), )
    assert game.boards[0].hives == (Hive(9, 9), )
Exemple #29
0
def test_visiting_flower_creates_seed_every_ten_visits(_, visits):
    game = GameState(
        game_params=DEFAULT_GAME_PARAMETERS,
        game_id=sentinel.game_id,
        boards=1,
        board_width=10,
        board_height=10,
        hives=(sentinel.hives, ),
        flowers=((Flower(
            5, 5, DEFAULT_GAME_PARAMETERS, 3, visits - 1,
            DEFAULT_GAME_PARAMETERS.flower_lifespan_visit_impact), ), ),
        game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.bee_1] = Bee(5, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    game.visit_flowers()

    assert game.boards[0].inflight == {
        sentinel.bee_1: Bee(5, 5, 0, 85, DEFAULT_GAME_PARAMETERS, 3),
        'sentinel.uuid': Seed(5, 5, ANY)
    }
Exemple #30
0
def test_flowers_and_venus_removed_if_expired():
    flowers = [
        Flower(sentinel.x,
               sentinel.y,
               DEFAULT_GAME_PARAMETERS,
               sentinel.potency,
               sentinel.visits,
               expires=99),
        Flower(sentinel.x,
               sentinel.y,
               DEFAULT_GAME_PARAMETERS,
               sentinel.potency,
               sentinel.visits,
               expires=102),
        VenusBeeTrap(sentinel.x,
                     sentinel.y,
                     DEFAULT_GAME_PARAMETERS,
                     sentinel.potency,
                     sentinel.visits,
                     expires=99),
        VenusBeeTrap(sentinel.x,
                     sentinel.y,
                     DEFAULT_GAME_PARAMETERS,
                     sentinel.potency,
                     sentinel.visits,
                     expires=102)
    ]
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[sentinel.hives],
                     flowers=[flowers],
                     turn_num=100,
                     game_length=sentinel.game_length)

    game.remove_dead_flowers()

    assert game.boards[0].flowers == (flowers[1], flowers[3])