Example #1
0
def test_choose_map_all_maps_played(map_pool_factory):
    maps = [
        Map(1, "some_map", "maps/some_map.v001.zip"),
        Map(2, "some_map", "maps/some_map.v001.zip"),
        Map(3, "some_map", "maps/some_map.v001.zip"),
    ]
    map_pool = map_pool_factory(maps=maps)

    chosen_map = map_pool.choose_map([1, 2, 3])

    assert chosen_map is not None
    assert chosen_map in maps
Example #2
0
def test_choose_map(map_pool_factory):
    map_pool = map_pool_factory(maps=[
        Map(1, "some_map", "maps/some_map.v001.zip"),
        Map(2, "some_map", "maps/some_map.v001.zip"),
        Map(3, "some_map", "maps/some_map.v001.zip"),
        Map(4, "CHOOSE_ME", "maps/choose_me.v001.zip"),
    ])

    # Make the probability very low that the test passes because we got lucky
    for _ in range(20):
        chosen_map = map_pool.choose_map([1, 2, 3])
        assert chosen_map == (4, "CHOOSE_ME", "maps/choose_me.v001.zip")
Example #3
0
def test_choose_map_all_maps_played_not_in_pool(map_pool_factory):
    maps = [
        Map(1, "some_map", "maps/some_map.v001.zip"),
        Map(2, "some_map", "maps/some_map.v001.zip"),
        Map(3, "some_map", "maps/some_map.v001.zip"),
    ]
    map_pool = map_pool_factory(maps=maps)

    # None of the recently played maps are in the current pool
    chosen_map = map_pool.choose_map([4, 5, 6])

    assert chosen_map is not None
    assert chosen_map in maps
Example #4
0
async def test_load_from_database(ladder_service, queue_factory):
    # Insert some outdated data
    ladder_service.queues["test"] = queue_factory(name="test")

    # Data should be the same on each load
    for _ in range(3):
        await ladder_service.update_data()

        assert len(ladder_service.queues) == 2

        queue = ladder_service.queues["ladder1v1"]
        assert queue.name == "ladder1v1"
        assert len(queue.map_pools) == 3
        assert list(queue.map_pools[1][0].maps.values()) == [
            Map(id=15, name="SCMP_015", path="maps/scmp_015.v0003.zip"),
        ]
        assert list(queue.map_pools[2][0].maps.values()) == [
            Map(id=11, name="SCMP_011", path="maps/scmp_011.zip"),
            Map(id=14, name="SCMP_014", path="maps/scmp_014.zip"),
            Map(id=15, name="SCMP_015", path="maps/scmp_015.v0003.zip"),
        ]
        assert list(queue.map_pools[3][0].maps.values()) == [
            Map(id=1, name="SCMP_001", path="maps/scmp_001.zip"),
            Map(id=2, name="SCMP_002", path="maps/scmp_002.zip"),
            Map(id=3, name="SCMP_003", path="maps/scmp_003.zip"),
        ]
Example #5
0
def test_choose_map_single_map(map_pool_factory, history):
    map_pool = map_pool_factory(maps=[
        Map(1, "CHOOSE_ME", "maps/choose_me.v001.zip"),
    ])

    # Make the probability very low that the test passes because we got lucky
    for _ in range(20):
        chosen_map = map_pool.choose_map(history)
        assert chosen_map == (1, "CHOOSE_ME", "maps/choose_me.v001.zip")
Example #6
0
def test_choose_map_all_maps_played_returns_least_played(map_pool_factory):
    # Large enough so the test is unlikely to pass by chance
    num_maps = 1000
    limit = 3

    played_map_ids = [
        # Set up player history so map 1 is played the least
        i + 1 + j for i in range(limit) for j in range(num_maps)
        if i + 1 + j <= num_maps
    ]

    maps = [
        Map(i + 1, "some_map", "maps/some_map.v001.zip")
        for i in range(num_maps)
    ]
    # Shuffle the list so that `choose_map` can't just return the first map
    random.shuffle(maps)
    map_pool = map_pool_factory(maps=maps)

    chosen_map = map_pool.choose_map(played_map_ids)

    # Map 1 was played only once
    assert chosen_map == (1, "some_map", "maps/some_map.v001.zip")
Example #7
0
async def test_start_game_start_spots(ladder_service: LadderService,
                                      game_service: GameService, queue_factory,
                                      monkeypatch, team1, team2):
    queue = queue_factory("test_3v3",
                          mod="faf",
                          team_size=3,
                          rating_type=RatingType.GLOBAL)
    queue.add_map_pool(MapPool(1, "test",
                               [Map(1, "scmp_007", "maps/scmp_007.zip")]),
                       min_rating=None,
                       max_rating=None)

    monkeypatch.setattr(LadderGame, "wait_hosted", CoroutineMock())
    monkeypatch.setattr(LadderGame, "wait_launched", CoroutineMock())
    await ladder_service.start_game(team1, team2, queue)

    game = game_service[game_service.game_id_counter]

    def get_start_spot(player_id) -> int:
        return game.get_player_option(player_id, "StartSpot")

    assert get_start_spot(1) == get_start_spot(2) - 1
    assert get_start_spot(3) == get_start_spot(4) - 1
    assert get_start_spot(5) == get_start_spot(6) - 1