Пример #1
0
def get_game_option(args, lua_files=None):

    game_option = minirts.RTSGameOption()
    game_option.seed = args.seed
    game_option.max_tick = args.max_tick
    game_option.no_terrain = args.no_terrain
    game_option.resource = args.resource
    game_option.resource_dist = args.resource_dist
    game_option.fair = args.fair
    game_option.save_replay_freq = args.save_replay_freq
    game_option.save_replay_per_games = args.save_replay_per_games

    if lua_files is None:
        game_option.lua_files = args.lua_files
    else:
        game_option.lua_files = lua_files

    game_option.num_games_per_thread = args.game_per_thread
    # !!! this is important
    game_option.max_num_units_per_player = args.max_num_units

    save_dir = os.path.abspath(args.save_dir)
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
    game_option.save_replay_prefix = save_dir + "/"

    return game_option
Пример #2
0
def init_botvbot(bot1idx,
                 bot2idx,
                 num_games,
                 args,
                 ai1_option,
                 ai2_option,
                 game_option,
                 *,
                 act_name="act",
                 viz=False):
    # print('ai1 option:')
    # print(ai1_option.info())
    # print('ai2 option:')
    # print(ai2_option.info())
    # print('game option:')
    # print(game_option.info())
    total_games = num_games
    batchsize = min(32, max(total_games // 2, 1))

    act1_dc = tube.DataChannel(act_name + "1", batchsize, 1)
    act2_dc = tube.DataChannel(act_name + "2", batchsize, 1)
    context = tube.Context()
    idx2utype = [
        minirts.UnitType.SPEARMAN,
        minirts.UnitType.SWORDMAN,
        minirts.UnitType.CAVALRY,
        minirts.UnitType.DRAGON,
        minirts.UnitType.ARCHER,
    ]

    if game_option.seed == 777:
        print("Using random seeds...")

    game_id = 0
    rnd_num = random.randint(1, num_games - 1)
    for i in range(num_games):
        if game_option.seed == 777:
            seed = random.randint(1, 123456)
        else:
            seed = game_option.seed

        g_option = minirts.RTSGameOption(game_option)
        g_option.seed = seed + i
        g_option.game_id = str(i)
        g = minirts.RTSGame(g_option)

        bot1 = minirts.MediumAI(ai1_option, 0, None, idx2utype[bot1idx], 1)
        bot2 = minirts.MediumAI(ai2_option, 0, None, idx2utype[bot2idx],
                                1)  # Utype + tower

        g.add_bot(bot1)
        g.add_bot(bot2)

        if viz and i == rnd_num:
            g.add_default_spectator()

        context.push_env_thread(g)
        game_id += 1

    return context, act1_dc, act2_dc
Пример #3
0
def create_game(act1_dc, ai1_option, game_option, i, seed):
    g_option = minirts.RTSGameOption(game_option)
    g_option.seed = seed + i
    g_option.game_id = str(i)
    if game_option.save_replay_prefix:
        g_option.save_replay_prefix = game_option.save_replay_prefix + "_0_" + str(
            i)
    g = minirts.RTSGame(g_option)
    bot1 = minirts.CheatExecutorAI(ai1_option, 0, None, act1_dc)
    return bot1, g
Пример #4
0
def init_games(num_games,
               ai1_option,
               ai2_option,
               game_option,
               *,
               act_name="act"):
    # print('ai1 option:')
    # print(ai1_option.info())
    # print('ai2 option:')
    # print(ai2_option.info())
    # print('game option:')
    # print(game_option.info())

    batchsize = min(32, max(num_games // 2, 1))
    act1_dc = tube.DataChannel(act_name + "1", batchsize, 1)
    act2_dc = tube.DataChannel(act_name + "2", batchsize, 1)
    context = tube.Context()
    idx2utype = [
        minirts.UnitType.SPEARMAN,
        minirts.UnitType.SWORDMAN,
        minirts.UnitType.CAVALRY,
        minirts.UnitType.DRAGON,
        minirts.UnitType.ARCHER,
    ]

    if game_option.seed == 777:
        print("Using random seeds...")

    for i in range(num_games):
        g_option = minirts.RTSGameOption(game_option)
        if game_option.seed == 777:
            print("Using random seeds...")
            seed = random.randint(1, 123456)
        else:
            seed = game_option.seed

        g_option.seed = seed + i
        g_option.game_id = str(i)
        if game_option.save_replay_prefix:
            g_option.save_replay_prefix = (game_option.save_replay_prefix +
                                           "_0_" + str(i))

        g = minirts.RTSGame(g_option)
        bot1 = minirts.CheatExecutorAI(ai1_option, 0, None, act1_dc)
        bot2 = minirts.CheatExecutorAI(ai2_option, 0, None, act2_dc)
        # utype = idx2utype[i % len(idx2utype)]
        # bot2 = minirts.MediumAI(ai2_option, 0, None, utype, False)

        g.add_bot(bot1)
        g.add_bot(bot2)
        context.push_env_thread(g)

    return context, act1_dc, act2_dc
Пример #5
0
def get_game_option(args):
    game_option = minirts.RTSGameOption()
    game_option.seed = args.seed
    game_option.max_tick = args.max_tick
    game_option.no_terrain = args.no_terrain
    game_option.resource = args.resource
    game_option.resource_dist = args.resource_dist
    game_option.fair = args.fair
    game_option.save_replay_freq = args.save_replay_freq
    game_option.save_replay_per_games = args.save_replay_per_games
    game_option.lua_files = args.lua_files
    game_option.num_games_per_thread = 1
    # !!! this is important
    game_option.max_num_units_per_player = args.max_num_units
    return game_option
Пример #6
0
def create_game(num_games,
                ai1_option,
                ai2_option,
                game_option,
                *,
                act_name='act'):
    print('ai1 option:')
    print(ai1_option.info())
    print('ai2 option:')
    print(ai2_option.info())
    print('game option:')
    print(game_option.info())

    batchsize = min(32, max(num_games // 2, 1))
    act1_dc = tube.DataChannel(act_name + '1', batchsize, 1)
    act2_dc = tube.DataChannel(act_name + '2', batchsize, 1)
    context = tube.Context()
    idx2utype = [
        minirts.UnitType.SPEARMAN,
        minirts.UnitType.SWORDMAN,
        minirts.UnitType.CAVALRY,
        minirts.UnitType.DRAGON,
        minirts.UnitType.ARCHER,
    ]

    for i in range(num_games):
        g_option = minirts.RTSGameOption(game_option)
        g_option.seed = game_option.seed + i
        if game_option.save_replay_prefix:
            g_option.save_replay_prefix = game_option.save_replay_prefix + str(
                i)

        g = minirts.RTSGame(g_option)
        bot1 = minirts.CheatExecutorAI(ai1_option, 0, None, act1_dc)
        bot2 = minirts.CheatExecutorAI(ai2_option, 0, None, act2_dc)
        # utype = idx2utype[i % len(idx2utype)]
        # bot2 = minirts.MediumAI(ai2_option, 0, None, utype, False)
        g.add_bot(bot1)
        g.add_bot(bot2)
        context.push_env_thread(g)

    return context, act1_dc, act2_dc
Пример #7
0
# Copyright (c) Facebook, Inc. and its affiliates.
Пример #8
0
# Copyright (c) Facebook, Inc. and its affiliates.
Пример #9
0
# Copyright (c) Facebook, Inc. and its affiliates.
Пример #10
0
# Copyright (c) Facebook, Inc. and its affiliates.