Пример #1
0
def main():
    """
    Main function gets the args input and determines which method to call to handle. Handles exceptions from
    malformed input.
    :return: Nothing
    """
    try:
        args = _parse_arguments()
        if args.mode == AUTH_MODE:
            if not (args.metadata and Config.auth_exists()):
                authorize()
            if args.metadata:
                print(Config())
        elif args.mode == BOT_MODE:
            upload_bot.upload(args.bot_path)
        elif args.mode == REPLAY_MODE:
            download_game.download(
                args.replay_mode, args.destination,
                getattr(args, 'date', None), getattr(args, 'all', None),
                Config().user_id if Config.auth_exists() else None,
                getattr(args, 'user_id', None), getattr(args, 'limit', None))
        elif args.mode == GYM_MODE:
            compare_bots.play_games(args.halite_binary, args.map_width,
                                    args.map_height, args.run_commands,
                                    args.iterations)
    except (IndexError, TypeError, ValueError, IOError,
            FileNotFoundError) as err:
        sys.stderr.write(str(err) + os.linesep)
        exit(-1)
Пример #2
0
def main():
    """
    Main function gets the args input and determines which method to call to handle. Handles exceptions from
    malformed input.
    :return: Nothing
    """
    try:
        args = _parse_arguments()

        if args.json:
            output.set_mode('json')

        if args.mode == AUTH_MODE:
            if args.key:
                Config(args.key)
                output.output("Saved API key.")
                return

            if not (args.metadata and Config.auth_exists()):
                authorize()
            if args.metadata:
                output.output(Config())
        elif args.mode == BOT_MODE:
            if args.bot_mode == BOT_UPLOAD_MODE:
                upload_bot.upload(args.bot_path, args.dry_run,
                                  args.include_extensions)
            else:
                upload_bot.download(args.bot_path)
        elif args.mode == REPLAY_MODE:
            if not args.replay_mode:
                raise ValueError("Provide a download mode (date or user)")
            download_game.download(
                args.replay_mode, args.destination,
                getattr(args, 'date', None), getattr(args, 'all', None),
                Config().user_id if Config.auth_exists() else None,
                getattr(args, 'user_id', None), getattr(args, 'limit', None))
        elif args.mode == PLAY_MODE:
            compare_bots.play_games(args.halite_binary, args.game_output_dir,
                                    args.map_width, args.map_height,
                                    args.run_commands, args.iterations, [])
        elif args.mode == GYM_MODE:
            gym.main(args)
    except (IndexError, TypeError, ValueError, IOError) as err:
        output.error(str(err))
        sys.exit(-1)
Пример #3
0
def main():
    """
    Main function gets the args input and determines which method to call to handle. Handles exceptions from
    malformed input.
    :return: Nothing
    """
    args = _parse_arguments()
    if not (len(args.run_commands) == 2 or len(args.run_commands) == 4):
        sys.stderr.write("Error: You must specify 2 or 4 bots to compare.\n")
        exit(-1)
    if args.halite_binary is None:
        if sys.platform == "win32":
            args.halite_binary = "halite.exe"
        else:
            args.halite_binary = "./halite"
    if not os.path.isfile(args.halite_binary):
        sys.stderr.write(usage_str)
        sys.stderr.write("Error: Unable to locate halite binary.\n")
        sys.stderr.write(
            "If it is not in the current directory, did you forget to specify a -b option?"
        )
        exit(-1)
    if (args.map_width == 0) != (args.map_height == 0):
        sys.stderr.write(usage_str)
        sys.stderr.write("Error: Map width and height "
                         "must be specified together.\n")
        exit(-1)
    add_args = list()
    if args.timeouts:
        add_args.append("--no-timeout")
    if args.map_height != 0 and args.map_width != 0:
        add_args.append("--width {} --height {}".format(
            args.map_width, args.map_height))
    if args.noreplay:
        add_args.append("--no-replay")
        add_args.append("--no-logs")
    # Random unsigned int
    compare_bots.play_games(args.halite_binary, ".", args.run_commands,
                            args.iterations, add_args)