Esempio n. 1
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
Esempio n. 2
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