Beispiel #1
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
Beispiel #2
0
def create_drift_games(num_sp,
                       num_rb,
                       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())

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

    total_games = num_sp + num_rb
    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,
    ]

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

        bot1, g = create_game(act1_dc, ai1_option, game_option, game_id, seed)

        utype = idx2utype[random.randint(0, len(idx2utype) - 1)]
        bot2 = minirts.MediumAI(ai2_option, 0, None, utype, 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
Beispiel #3
0
def create_game(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())

    act_dc = tube.DataChannel(act_name, 1, -1)
    context = tube.Context()
    g = minirts.RTSGame(game_option)
    bot1 = minirts.CheatExecutorAI(ai1_option, 0, None, act_dc)
    bot2 = minirts.MediumAI(ai2_option, 0, None, minirts.UnitType.INVALID_UNITTYPE, False)
    g.add_bot(bot1)
    g.add_bot(bot2)
    g.add_default_spectator()

    context.push_env_thread(g)
    return context, act_dc
Beispiel #4
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))
    act_dc = tube.DataChannel(act_name, 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, act_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, act_dc
Beispiel #5
0
# Copyright (c) Facebook, Inc. and its affiliates.