示例#1
0
def main():
    args = parser.parse_args()
    if args.ai_under_test is not None:
        combatants_provider = EvaluationCombatantsProvider(
            PLAYING_AIs, args.ai_under_test)
    else:
        combatants_provider = TournamentCombatantsProvider(PLAYING_AIs)
    random.seed(args.seed)

    signal(SIGCHLD, signal_handler)

    if args.load:
        with open(args.load, 'rb') as f:
            all_games = pickle.load(f)
    else:
        all_games = []

    boards_played = 0
    reporter = SingleLineReporter(not args.report)
    try:
        for board_definition in board_definitions(args.board):
            if boards_played == args.nb_boards:
                break
            boards_played += 1

            combatants = combatants_provider.get_combatants(args.game_size)
            nb_permutations, permutations_generator = rotational_permunations_generator(
                combatants)
            for i, permuted_combatants in enumerate(permutations_generator):
                reporter.report('\r{} {}/{} {}'.format(
                    boards_played, i + 1, nb_permutations,
                    ' vs. '.join(permuted_combatants)))
                game_summary = run_ai_only_game(
                    args.port,
                    args.address,
                    procs,
                    permuted_combatants,
                    board_definition,
                    fixed=UNIVERSAL_SEED,
                    client_seed=UNIVERSAL_SEED,
                    logdir=args.logdir,
                    debug=args.debug,
                )
                all_games.append(game_summary)
    except (Exception, KeyboardInterrupt) as e:
        sys.stderr.write("Breaking the tournament because of {}\n".format(
            repr(e)))
        lockfile = open('/mnt/w/lock', 'w')
        fcntl.flock(lockfile, fcntl.LOCK_EX)
        for p in procs:
            p.kill()
        fcntl.flock(lockfile, fcntl.LOCK_UN)

    reporter.clean()

    if args.save:
        with open(args.save, 'wb') as f:
            pickle.dump(all_games, f)

    for game in all_games:
        participants = game.participants()
        for player in players_info:
            if get_nickname(player) in participants:
                players_info[player]['games'].append(game)

    performances = [
        PlayerPerformance(player, info['games'], PLAYING_AIs)
        for player, info in players_info.items()
    ]
    performances.sort(key=lambda perf: perf.winrate, reverse=True)

    perf_strings = [performances[0].competitors_header()
                    ] + [str(perf) for perf in performances]
    fields = [perf.split() for perf in perf_strings]

    print(column_t(fields))
示例#2
0
def main():

    args = parser.parse_args()

    PLAYING_AIs.append(args.user_ai_name)
    players_info = {ai: {'games': []} for ai in PLAYING_AIs}

    if args.ai_under_test is not None:
        combatants_provider = EvaluationCombatantsProvider(
            PLAYING_AIs, args.ai_under_test)
    else:
        combatants_provider = TournamentCombatantsProvider(PLAYING_AIs)
    random.seed(args.seed)

    signal(SIGCHLD, signal_handler)

    all_games = []

    boards_played = 0
    try:
        for board_definition in board_definitions(args.board):
            if boards_played == args.nb_boards:
                break
            boards_played += 1

            combatants = combatants_provider.get_combatants(args.game_size)
            nb_permutations, permutations_generator = rotational_permunations_generator(
                combatants)
            for i, permuted_combatants in enumerate(permutations_generator):
                game_summary = run_ai_only_game(
                    args.port,
                    args.address,
                    procs,
                    permuted_combatants,
                    board_definition,
                    fixed=UNIVERSAL_SEED,
                    client_seed=UNIVERSAL_SEED,
                )
                all_games.append(game_summary)
    except (Exception, KeyboardInterrupt) as e:
        sys.stderr.write("Breaking the tournament because of {}\n".format(
            repr(e)))
        for p in procs:
            p.kill()
        raise

    for game in all_games:
        participants = game.participants()
        for player in players_info:
            if get_nickname(player) in participants:
                players_info[player]['games'].append(game)

    performances = [
        PlayerPerformance(player, info['games'], PLAYING_AIs)
        for player, info in players_info.items()
    ]
    performances.sort(key=lambda perf: perf.winrate, reverse=True)

    perf_strings = [performances[0].competitors_header()
                    ] + [str(perf) for perf in performances]
    fields = [perf.split() for perf in perf_strings]

    print(column_t(fields))