Esempio n. 1
0
def generate_round(rd, mapmode_pool, round_ctx):
    if rd.get("ignore_game_history"):
        round_ctx = RoundContext()
    num_games = 1 if rd.get('counterpicks') else (rd.get('num_games') or 3)

    for i in range(num_games):
        overrides = rd.get('game_overrides')
        limited_mapmode_pool = None
        map_quality_str = rd.get('map_quality') or "normal"
        map_quality = 7 if map_quality_str == "high" else 8 if map_quality_str == "very high" else 5
        if overrides:
            override = next(
                (o for o in overrides if o.get('game_num') == i + 1), None)
            if override:
                limited_mapmode_pool = mapmode_pool.filter_include_mode(override.get('mode')) \
                 if override.get('mode') else mapmode_pool
                limited_mapmode_pool = limited_mapmode_pool.filter_include_map(override.get('map')) \
                 if override.get('map') else limited_mapmode_pool
        if limited_mapmode_pool:
            limited_mapmode_pool = limited_mapmode_pool.filter_from_ctx(
                round_ctx)
            chosen_mapmode = limited_mapmode_pool.random_choice(map_quality)
            round_ctx.append_game(chosen_mapmode)
        else:
            filtered_pool = mapmode_pool.filter_from_ctx(round_ctx)
            chosen_mapmode = filtered_pool.random_choice(map_quality)
            round_ctx.append_game(chosen_mapmode)
    round_final = round_ctx.current_round
    if rd.get('counterpicks'):
        round_final = round_final + ["Counterpick"] * (
            (rd.get('num_games') or 3) - 1)
    round_ctx.finalize_round()
    return round_final
Esempio n. 2
0
def create_rounds_tournament(mapmode_list, tournament_dict):
    round_ctx = RoundContext()
    maplist = []
    rounds = []
    map_pool_config = MapPoolConfig()
    for k, v in tournament_dict.items():
        if k == "rounds":
            rounds = v
        else:
            map_pool_config.set_parameter(k, v)
    mapmode_pool = MapModePool(mapmode_list, map_pool_config)
    for rd in rounds:
        maplist.append(generate_round(rd, mapmode_pool, round_ctx))

    used_map_pool = get_map_pool_by_mode(
        mapmode_pool.filter_exclude_bad_mapmodes().mapmode_list)
    output_dict = {
        'tournament_type':
        'rounds',
        'map_pool':
        used_map_pool,
        'rounds': [
            round_to_dict(f"Round {i + 1}", mm_list)
            for i, mm_list in enumerate(maplist)
        ]
    }

    return output_dict
Esempio n. 3
0
def create_continuous_maplist(mapmode_list, num_games, map_quality=5):
	distinct_modes = len(get_map_pool_by_mode(mapmode_list).keys())
	map_pool_config = MapPoolConfig(exclude_map_score_threshold=5.5, 
		preferred_map_score_threshold=7, 
		max_non_preferred_maps_per_round=10,
		distinct_maps_in_consecutive_rounds=True,
		min_games_before_repeat_mode=distinct_modes - 1,
		decreased_past_mapmode_likelihood=True,
		max_maps_per_mode=10)
	round_ctx = RoundContext()
	mapmode_pool = MapModePool(mapmode_list, map_pool_config)
	for i in range(num_games):
		filtered_pool = mapmode_pool.filter_from_ctx(round_ctx)
		chosen_mapmode = filtered_pool.random_choice(map_quality)
		round_ctx.append_game(chosen_mapmode)
	round_final = round_ctx.current_round

	return [str(mapmode) for mapmode in round_final]
Esempio n. 4
0
def create_single_elim_tournament(mapmode_list, tournament_dict):
    num_players = 16
    round_ctx = RoundContext()
    round_cfg = {}
    map_pool_config = MapPoolConfig()
    for k, v in tournament_dict.items():
        if k == 'round_config':
            round_cfg = v
        elif k == 'num_players':
            num_players = v
        else:
            map_pool_config.set_parameter(k, v)
    mapmode_pool = MapModePool(mapmode_list, map_pool_config)

    output_rounds = []

    # Generate rounds
    num_winners_rounds = get_number_winners_rounds(num_players)
    for i in range(num_winners_rounds):
        if i == num_winners_rounds - 3 and 'quarterfinals' in round_cfg:
            rd = round_cfg.get('quarterfinals')
        elif i == num_winners_rounds - 2 and 'semifinals' in round_cfg:
            rd = round_cfg.get('semifinals')
        elif i == num_winners_rounds - 1 and 'finals' in round_cfg:
            rd = round_cfg.get('finals')
        else:
            rd = round_cfg.get('default')
        output_rounds.append(round_to_dict(get_round_name(i, num_winners_rounds), \
         generate_round(rd, mapmode_pool, round_ctx)))

    used_map_pool = get_map_pool_by_mode(
        mapmode_pool.filter_exclude_bad_mapmodes().mapmode_list)

    output_dict = {
        'tournament_type': 'single_elim',
        'num_players': num_players,
        'map_pool': used_map_pool,
        'rounds': output_rounds
    }

    return output_dict
Esempio n. 5
0
def create_double_elim_tournament(mapmode_list, tournament_dict):
    num_players = 16
    round_ctx = RoundContext()
    winners_rounds = []
    losers_rounds = []
    round_cfg = {}
    map_pool_config = MapPoolConfig()
    for k, v in tournament_dict.items():
        if k == 'round_config':
            round_cfg = v
        elif k == 'num_players':
            num_players = v
        else:
            map_pool_config.set_parameter(k, v)
    mapmode_pool = MapModePool(mapmode_list, map_pool_config)

    # Generate wr1
    winners_rounds.append(
        generate_round(round_cfg.get('default'), mapmode_pool, round_ctx))

    round_ctx_copy = round_ctx.clone()

    # Generate losers rounds
    num_losers_rounds = get_number_losers_rounds(num_players)
    for rd_num in range(num_losers_rounds):
        if rd_num == num_losers_rounds - 2 and 'l_semifinals' in round_cfg:
            rd = round_cfg.get('l_semifinals')
        elif rd_num == num_losers_rounds - 1 and 'l_finals' in round_cfg:
            rd = round_cfg.get('l_finals')
        else:
            rd = round_cfg.get('default')
        losers_rounds.append(generate_round(rd, mapmode_pool, round_ctx))

    # Generate winners rounds
    num_winners_rounds = get_number_winners_rounds(num_players)
    # If 'share_rounds_w_l' setting is on, winners sets are copies of some losers rounds.
    if round_cfg.get('share_rounds_w_l'):
        for rd_num in range(1, num_winners_rounds):
            if rd_num == 1:
                winners_rounds.append(losers_rounds[0])
            else:
                winners_rounds.append(losers_rounds[2 * (rd_num - 1) - 1])
    # If off, generate rounds as normal
    else:
        for rd_num in range(1, num_winners_rounds):
            if rd_num == num_winners_rounds - 3 and 'w_quarterfinals' in round_cfg:
                rd = round_cfg.get('w_quarterfinals')
            elif rd_num == num_winners_rounds - 2 and 'w_semifinals' in round_cfg:
                rd = round_cfg.get('w_semifinals')
            elif rd_num == num_winners_rounds - 1 and 'w_finals' in round_cfg:
                rd = round_cfg.get('w_finals')
            else:
                rd = round_cfg.get('default')
            winners_rounds.append(
                generate_round(rd, mapmode_pool, round_ctx_copy))

    gf_rd = generate_round(
        round_cfg.get('grand_finals') if 'grand_finals' in round_cfg else
        round_cfg.get('default'), mapmode_pool, round_ctx_copy)
    gf_reset_rd = generate_round(
        round_cfg.get('grand_finals_reset')
        if 'grand_finals_reset' in round_cfg else round_cfg.get('default'),
        mapmode_pool, round_ctx_copy)

    used_map_pool = get_map_pool_by_mode(
        mapmode_pool.filter_exclude_bad_mapmodes().mapmode_list)

    output_rounds = []
    for i in range(num_winners_rounds):
        output_rounds.append(
            round_to_dict(f"Winners {get_round_name(i, num_winners_rounds)}",
                          winners_rounds[i]))

    for i in range(num_losers_rounds):
        output_rounds.append(
            round_to_dict(f"Losers {get_round_name(i, num_losers_rounds)}",
                          losers_rounds[i]))

    output_rounds.append(round_to_dict("Grand Finals", gf_rd))
    output_rounds.append(
        round_to_dict("Grand Finals Set 2 (If needed)", gf_reset_rd))

    output_dict = {
        'tournament_type': 'double_elim',
        'num_players': num_players,
        'map_pool': used_map_pool,
        'rounds': output_rounds
    }

    return output_dict