Example #1
0
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), )
Example #2
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),
    }
Example #3
0
def test_trapseed_does_not_become_venus_after_10_moves_on_top_of_only_flower():
    turn_num = 12345

    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((), ),
                     flowers=((Flower(9,
                                      5,
                                      DEFAULT_GAME_PARAMETERS,
                                      expires=20000), ), ),
                     turn_num=turn_num,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = TrapSeed(
        9, 8, 0, mock_game_params.trap_seed_lifespan)

    for _ in range(DEFAULT_GAME_PARAMETERS.trap_seed_lifespan + 1):
        game.turn([None])

    assert {
        vid: volant
        for (vid, volant) in game.boards[0].inflight.items()
        if not isinstance(volant, Bee)
    } == {
        sentinel.seed_1: TrapSeed(9, 5, 0, -1)
    }
    assert game.boards[0].flowers == (Flower(9,
                                             5,
                                             DEFAULT_GAME_PARAMETERS,
                                             expires=20000), )
    assert game.boards[0].hives == ()
Example #4
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), )
Example #5
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),
    )
Example #6
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
Example #7
0
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
Example #8
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
Example #9
0
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), )
Example #10
0
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), )
Example #11
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])
Example #12
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),
    }
Example #13
0
def test_trapseed_becomes_venus_after_10_moves_on_top_of_a_flower():
    turn_num = 12345

    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((), ),
                     flowers=((Flower(9,
                                      5,
                                      DEFAULT_GAME_PARAMETERS,
                                      expires=20000),
                               Flower(5,
                                      5,
                                      DEFAULT_GAME_PARAMETERS,
                                      expires=20000)), ),
                     turn_num=turn_num,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = TrapSeed(
        9, 8, 0, mock_game_params.trap_seed_lifespan)

    for _ in range(DEFAULT_GAME_PARAMETERS.trap_seed_lifespan + 1):
        game.turn([None])

    assert not [(_, volant) for (_, volant) in game.boards[0].inflight.items()
                if isinstance(volant, TrapSeed)]
    assert sorted(map(str, game.boards[0].flowers)) == sorted(
        map(str, (VenusBeeTrap(
            9,
            5,
            DEFAULT_GAME_PARAMETERS,
            expires=turn_num + DEFAULT_GAME_PARAMETERS.trap_seed_lifespan +
            DEFAULT_GAME_PARAMETERS.flower_lifespan),
                  Flower(5, 5, DEFAULT_GAME_PARAMETERS, expires=20000))))
    assert game.boards[0].hives == ()
Example #14
0
def test_remove_over_expired_flowers_if_new_are_made():
    flowers = [
        Flower(sentinel.x,
               sentinel.y,
               DEFAULT_GAME_PARAMETERS,
               sentinel.potency,
               sentinel.visits,
               expires=99)
    ]
    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] in flowers

    flower = Flower(sentinel.x,
                    sentinel.y,
                    DEFAULT_GAME_PARAMETERS,
                    sentinel.potency,
                    sentinel.visits,
                    expires=203)

    game.boards[0].flowers += (flower, )
    game.remove_dead_flowers()

    assert len(game.boards[0].flowers) == 1
    assert game.boards[0].flowers[0] == flower
Example #15
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)}
Example #16
0
def test_queenbees_cant_create_hive_on_top_of_existing_hive():
    game = initialise_game(DEFAULT_GAME_PARAMETERS, 1, 10, 10, 1, 0, 23)
    board = game.boards[0]
    board.hives = (Hive(4, 4, 10), )
    board.flowers = (Flower(1, 1, DEFAULT_GAME_PARAMETERS, expires=9999), )
    # create queen bee on top of existing hive, like it has just launched
    board.inflight = {
        sentinel.queenbee_id: QueenBee(4, 4, 180, 10, DEFAULT_GAME_PARAMETERS)
    }
    # immediately create hive
    game.turn([{"entity": sentinel.queenbee_id, "command": "create_hive"}])
    # should only be one hive (not two)
    assert len(board.hives) == 1
    # it should be the new hive not the original (with 10 nectar)
    assert board.hives[0].nectar == 0
    # queen bee should be gone as she has 'hived'
    assert sentinel.queenbee_id not in board.inflight
Example #17
0
def test_queenbees_die_immediately_when_landing_on_hives():
    game = initialise_game(DEFAULT_GAME_PARAMETERS, 1, 10, 10, 1, 0, 23)
    game.boards[0].hives = (Hive(4, 4, 0), )
    game.boards[0].flowers = (Flower(1,
                                     1,
                                     DEFAULT_GAME_PARAMETERS,
                                     expires=9999), )
    # create queen bee that will land on hive on the next move
    game.boards[0].inflight = {
        sentinel.queenbee_id: QueenBee(4, 5, 180, 10, DEFAULT_GAME_PARAMETERS)
    }
    # with no command, queen bee should land and die
    game.turn([None])
    # make sure the queen is gone and can't execute a hive command on top of existing hive
    with pytest.raises(RuntimeError) as err:
        game.turn([{"entity": sentinel.queenbee_id, "command": "create_hive"}])
    assert "Unknown entity" in str(err.value)
Example #18
0
def test_apply_command_and_advance_no_command_bee_saved_from_exhaustion_by_flower(
):
    crashed, landed, lost = apply_command_and_advance(
        board_width=10,
        board_height=10,
        hives=[],
        flowers=[Flower(0, 1, DEFAULT_GAME_PARAMETERS, 1, 0, 1000).to_json()],
        inflight={
            "abee": ("Bee", 0, 0, 0, 0, DEFAULT_GAME_PARAMETERS._asdict(), 0)
        },
        turn_num=0,
        cmd=None)

    assert not crashed['collided']
    assert not crashed['exhausted']
    assert not crashed['headon']
    assert not crashed['seeds']
    assert not landed
    assert not lost
Example #19
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()
Example #20
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)
    }
Example #21
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)
    }
Example #22
0
def test_serialise_deserialise_game_state_to_json(nboards):
    params = GameParameters(launch_probability=1.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=30,
                            trap_seed_probability=1,
                            venus_score_factor=-50,
                            trap_seed_lifespan=10)

    game = GameState(
        game_params=params,
        game_id=sentinel.game_id,
        boards=nboards,
        board_width=sentinel.board_width,
        board_height=sentinel.board_height,
        hives=[(Hive(sentinel.hive_x, sentinel.hive_y, 23 * nboards), )] *
        nboards,
        flowers=[(Flower(sentinel.fx, sentinel.fy, DEFAULT_GAME_PARAMETERS,
                         sentinel.flower_size), )] * nboards,
        game_length=sentinel.game_length)
    # make sure there are some bees on the boards, and some of them will be queens
    # as the nectar in the hives should be over the queen making threshold
    with patch("hiveminder.game_state.rngs", {sentinel.game_id: Random(0)}):
        game.launch_bees(sentinel.turn_num)

    game_state_json = game.to_json()
    game_state_bounce = game.from_json(game_state_json)
    assert game == game_state_bounce
Example #23
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)
    }
Example #24
0
def test_can_not_hash_a_flower():
    h = Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency)
    with pytest.raises(TypeError) as err:
        hash(h)
    assert str(err.value) == "unhashable type: 'Flower'"
Example #25
0
def test_str():
    assert str(Flower(1337, 2000, DEFAULT_GAME_PARAMETERS, 54321, 1234, 3000)) == "Flower(1337, 2000, %s, 54321, 1234, 3000)" % DEFAULT_GAME_PARAMETERS._asdict()
Example #26
0
def test_Flowers_equality(x1, y1, size1, x2, y2, size2, are_equal):
    h1 = Flower(x1, y1, DEFAULT_GAME_PARAMETERS, size1)
    h2 = Flower(x2, y2, DEFAULT_GAME_PARAMETERS, size2)
    assert (h1 == h2) == are_equal
    assert (h1 != h2) == (not are_equal)