コード例 #1
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),
    }
コード例 #2
0
ファイル: test_land_bees.py プロジェクト: mkerin/hiveminder
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)
コード例 #3
0
ファイル: test_land_bees.py プロジェクト: mkerin/hiveminder
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)
コード例 #4
0
ファイル: test_land_bees.py プロジェクト: mkerin/hiveminder
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)
コード例 #5
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
コード例 #6
0
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)
コード例 #7
0
def test_apply_command_single_board_single_bee(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.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)
コード例 #8
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)
    }
コード例 #9
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)
    }
コード例 #10
0
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)
コード例 #11
0
def test_visit_flowers_two_bees_two_flowers_more_potent_and_live_longer():
    flower1 = Flower(5,
                     5,
                     DEFAULT_GAME_PARAMETERS,
                     3,
                     expires=DEFAULT_GAME_PARAMETERS.flower_lifespan)
    flower2 = Flower(5,
                     4,
                     DEFAULT_GAME_PARAMETERS,
                     2,
                     expires=DEFAULT_GAME_PARAMETERS.flower_lifespan)

    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=(sentinel.hives, ),
                     flowers=((flower1, flower2), ),
                     game_length=sentinel.game_length)

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

    assert flower1.expires == flower2.expires == DEFAULT_GAME_PARAMETERS.flower_lifespan + DEFAULT_GAME_PARAMETERS.flower_lifespan_visit_impact

    assert game.boards[0].inflight == {
        sentinel.bee_1:
        Bee(5, 5, 0,
            10 + 3 * DEFAULT_GAME_PARAMETERS.bee_energy_boost_per_nectar,
            DEFAULT_GAME_PARAMETERS, 5),
        sentinel.bee_2:
        Bee(5, 4, 0,
            10 + 2 * DEFAULT_GAME_PARAMETERS.bee_energy_boost_per_nectar,
            DEFAULT_GAME_PARAMETERS, 4),
    }
コード例 #12
0
def test_visit_flowers_does_not_feed_bee_if_not_on_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,
            expires=DEFAULT_GAME_PARAMETERS.flower_lifespan), ), ),
        game_length=sentinel.game_length)

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

    assert game.boards[0].inflight == {
        sentinel.bee_1: Bee(5, 4, 0, 10, DEFAULT_GAME_PARAMETERS, 1)
    }
コード例 #13
0
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."
コード例 #14
0
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."
コード例 #15
0
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")