Ejemplo n.º 1
0
    def load_match_config(self, match_config: MatchConfig, bot_config_overrides={}):
        """
        Loads the match config into internal data structures, which prepares us to later
        launch bot processes and start the match.

        This is an alternative to the load_config method; they accomplish the same thing.
        """
        self.num_participants = match_config.num_players
        self.names = [bot.name for bot in match_config.player_configs]
        self.teams = [bot.team for bot in match_config.player_configs]

        bundles = [bot_config_overrides[index] if index in bot_config_overrides else
                   get_bot_config_bundle(bot.config_path) if bot.config_path else None
                   for index, bot in enumerate(match_config.player_configs)]

        self.python_files = [bundle.python_file if bundle else None
                             for bundle in bundles]

        self.parameters = []

        for index, bot in enumerate(match_config.player_configs):
            python_config = None
            if bot.rlbot_controlled:
                python_config = load_bot_parameters(bundles[index])
            self.parameters.append(python_config)
            if bot.loadout_config is None and bundles[index]:
                looks_config = bundles[index].get_looks_config()
                bot.loadout_config = load_bot_appearance(looks_config, bot.team)

        if match_config.extension_config is not None and match_config.extension_config.python_file_path is not None:
            self.load_extension(match_config.extension_config.python_file_path)

        self.match_config = match_config
        self.start_match_configuration = match_config.create_match_settings()
        self.game_interface.start_match_configuration = self.start_match_configuration
Ejemplo n.º 2
0
    def setup_match(self):
        # Set up RLBot.cfg
        framework_config = create_bot_config_layout()
        config_location = os.path.join(os.path.dirname(__file__), 'rlbot.cfg')
        framework_config.parse_file(config_location, max_index=MAX_PLAYERS)
        match_config = parse_match_config(framework_config, config_location, {}, {})
        match_config.game_map = self.choreo_obj.map_name

        # The three blocks of code below are basically identical.
        # TODO Make them into a function?

        # Gets appearance list from choreo.
        appearances = self.choreo_obj.get_appearances(self.min_bots)
        # Checks that it is the correct length.
        if len(appearances) != self.min_bots:
            print('[RLBotChoreography]: Number of appearances does not match number of bots.')
            print('[RLBotChoreography]: Using default appearances.')
            appearances = ['default.cfg'] * self.min_bots

        # Gets teams list from choreo.
        teams = self.choreo_obj.get_teams(self.min_bots)
        # Checks that it is the correct length.
        if len(teams) != self.min_bots:
            print('[RLBotChoreography]: Number of teams does not match number of bots.')
            print('[RLBotChoreography]: Putting all on blue.')
            teams = [0] * self.min_bots

        # Gets names list from choreo.
        names = self.choreo_obj.get_names(self.min_bots)
        # Checks that it is the correct length.
        if len(names) != self.min_bots:
            print('[RLBotChoreography]: Number of names does not match number of bots.')
            print('[RLBotChoreography]: Using bot indices as names.')
            names = range(self.min_bots)

        # Loads appearances.
        looks_configs = {
            idx: create_looks_configurations().parse_file(
                os.path.abspath('./ChoreographyHive/appearances/' + file_name))
            for idx, file_name in enumerate(appearances)
        }

        # rlbot.cfg specifies only one bot, 
        # so we have to copy each and assign correct appearance.
        player_config = match_config.player_configs[0]
        match_config.player_configs.clear()
        for i in range(self.min_bots):
            copied = PlayerConfig()
            copied.name = names[i]
            copied.team = teams[i]
            copied.bot = player_config.bot
            copied.rlbot_controlled = player_config.rlbot_controlled
            copied.config_path = player_config.config_path
            copied.loadout_config = load_bot_appearance(looks_configs[i], copied.team)
            match_config.player_configs.append(copied)

        manager = SetupManager()
        manager.load_match_config(match_config, {})
        manager.connect_to_game()
        manager.start_match()
Ejemplo n.º 3
0
def spawn_car_for_viewing(looks: dict, team: int, showcase_type: str,
                          map_name: str):
    looks_config = convert_to_looks_config(looks)
    loadout_config = load_bot_appearance(looks_config, team)
    launcher_settings_map = get_launcher_settings()
    launcher_prefs = launcher_preferences_from_map(launcher_settings_map)
    spawn_car_in_showroom(loadout_config, team, showcase_type, map_name,
                          launcher_prefs)
Ejemplo n.º 4
0
def set_random_psyonix_bot_preset(player: PlayerConfig):
    """
    Sets the name and loadout to a randomly selected psyonix bot preset.
    """
    loadout_file = PSYONIX_PRESET_LIST[0]
    PSYONIX_PRESET_LIST.append(PSYONIX_PRESET_LIST.pop(0))  # Move preset to the end of the list.
    loadout_config = create_looks_configurations().parse_file(loadout_file)
    player.loadout_config = load_bot_appearance(loadout_config, player.team)
    player.name = loadout_file.name.split("_")[1].title()
    player.name = ["Rookie ", "Pro ", ""][min(int(abs(player.bot_skill) * 3), 2)] + player.name
Ejemplo n.º 5
0
def rlbot_to_player_config(player: dict, team: Team):
    bot_path = collapse_path(player["path"])

    player_config = PlayerConfig()
    player_config.bot = True
    player_config.rlbot_controlled = True
    player_config.name = player["name"]
    player_config.team = team.value
    player_config.config_path = bot_path
    config = get_bot_config_bundle(bot_path)
    loadout = load_bot_appearance(config.get_looks_config(), team.value)
    player_config.loadout_config = loadout
    return player_config
Ejemplo n.º 6
0
 def bot_config(player_config_path: Path, team: Team) -> 'PlayerConfig':
     """
     A function to cover the common case of creating a config for a bot.
     """
     bot_config = PlayerConfig()
     bot_config.bot = True
     bot_config.rlbot_controlled = True
     bot_config.team = team.value
     bot_config.config_path = str(player_config_path.absolute()) # TODO: Refactor to use Path's
     config_bundle = get_bot_config_bundle(bot_config.config_path)
     bot_config.name = config_bundle.name
     bot_config.loadout_config = load_bot_appearance(config_bundle.get_looks_config(), bot_config.team)
     return bot_config
Ejemplo n.º 7
0
    def generate_loadout_config(self, player_index: int, team: int) -> LoadoutConfig:
        if self.loadout_generator_file:
            try:
                generator_wrapper = import_class_with_base(self.loadout_generator_file, BaseLoadoutGenerator)
                generator_class = generator_wrapper.get_loaded_class()
                generator = generator_class(Path(self.config_directory))
                loadout_config = generator.generate_loadout(player_index, team)
                if loadout_config and isinstance(loadout_config, LoadoutConfig):
                    return loadout_config
                else:
                    logger.warn(f"Generated loadout is invalid, will fall back to file. Loadout was: {loadout_config}")
            except Exception as e:
                logger.warn(f"Failed to generate loadout config, will fall back to file. Error was: {e}")

        config_object = self.get_looks_config()
        return load_bot_appearance(config_object, team)
Ejemplo n.º 8
0
    def load_match_config(self, match_config: MatchConfig, bot_config_overrides={}):
        """
        Loads the match config into internal data structures, which prepares us to later
        launch bot processes and start the match.

        This is an alternative to the load_config method; they accomplish the same thing.
        """
        self.num_participants = match_config.num_players
        self.names = [bot.name for bot in match_config.player_configs]
        self.teams = [bot.team for bot in match_config.player_configs]

        self.configs = [bot.config_path for bot in match_config.player_configs]
        
        bundles = [bot_config_overrides[index] if index in bot_config_overrides else
                   get_bot_config_bundle(bot.config_path) if bot.config_path else None
                   for index, bot in enumerate(match_config.player_configs)]

        self.python_files = [bundle.python_file if bundle else None
                             for bundle in bundles]

        self.bot_bundles = []

        for index, bot in enumerate(match_config.player_configs):
            self.bot_bundles.append(bundles[index])
            if bot.loadout_config is None and bundles[index]:
                looks_config = bundles[index].get_looks_config()
                bot.loadout_config = load_bot_appearance(looks_config, bot.team)

        for path in match_config.botless_agents:
            try:
                spec = impu.spec_from_file_location(path)
                m = impu.module_from_spec(spec)
                spec.loader.exec_module(m)
                if m.hasattr("agent"):
                    self.botless_agents.append(m.agent())
                else:
                    self.logg.warning(f"No agent class found in {path}")
            except:
                self.logger.warning(f"Failed to import botless agent at {path}.")
        
        if match_config.extension_config is not None and match_config.extension_config.python_file_path is not None:
            self.load_extension(match_config.extension_config.python_file_path)

        self.match_config = match_config
        self.start_match_configuration = match_config.create_match_settings()
        self.game_interface.start_match_configuration = self.start_match_configuration
Ejemplo n.º 9
0
def _load_bot_config(index, config_bundle: BotConfigBundle,
                     looks_config_object: ConfigObject,
                     overall_config: ConfigObject,
                     human_index_tracker: IncrementingInteger) -> PlayerConfig:
    """
    Loads the config data of a single bot
    :param index: This is the bot index (where it appears in game_cars)
    :param bot_configuration: A config object that will eventually be transformed and sent to the game.
    :param config_bundle: A config object for a single bot
    :param overall_config: This is the config for the entire session not one particular bot
    :param human_index_tracker: An object of type HumanIndexManager that helps set human_index correctly.
    :return:
    """

    bot_configuration = PlayerConfig()
    bot_configuration.config_path = config_bundle.config_path

    team_num = get_team(overall_config, index)

    bot_configuration.team = team_num

    # Setting up data about what type of bot it is
    bot_type = overall_config.get(PARTICIPANT_CONFIGURATION_HEADER,
                                  PARTICIPANT_TYPE_KEY, index)
    bot_configuration.bot, bot_configuration.rlbot_controlled = get_bot_options(
        bot_type)
    bot_configuration.bot_skill = overall_config.getfloat(
        PARTICIPANT_CONFIGURATION_HEADER, PARTICIPANT_BOT_SKILL_KEY, index)

    if not bot_configuration.bot:
        bot_configuration.human_index = human_index_tracker.increment()

    # Setting up the bots name
    bot_configuration.name = config_bundle.name

    if looks_config_object:
        loadout_config = load_bot_appearance(looks_config_object, team_num)
    else:
        loadout_config = config_bundle.generate_loadout_config(index, team_num)

    bot_configuration.loadout_config = loadout_config

    return bot_configuration
Ejemplo n.º 10
0
    def setup_match(self):
        # TODO This should be replaced?
        arguments = docopt(__doc__)

        bot_directory = arguments['--bot-folder']
        bundles = scan_directory_for_bot_configs(bot_directory)

        # Set up RLBot.cfg
        framework_config = create_bot_config_layout()
        config_location = os.path.join(os.path.dirname(__file__), 'rlbot.cfg')
        framework_config.parse_file(config_location, max_index=MAX_PLAYERS)
        match_config = parse_match_config(framework_config, config_location,
                                          {}, {})

        looks_configs = {
            idx: bundle.get_looks_config()
            for idx, bundle in enumerate(bundles)
        }
        names = [bundle.name for bundle in bundles]

        player_config = match_config.player_configs[0]
        match_config.player_configs.clear()
        for i in range(max(len(bundles), self.min_bots)):
            copied = PlayerConfig()
            copied.bot = player_config.bot
            copied.name = player_config.name
            copied.rlbot_controlled = player_config.rlbot_controlled
            copied.config_path = player_config.config_path
            copied.team = player_config.team if i % 2 == 0 else not player_config.team
            if i < len(bundles):
                copied.name = names[i]
                # If you want to override bot appearances to get a certain visual effect, e.g. with
                # specific boost colors, this is a good place to do it.
                copied.loadout_config = load_bot_appearance(
                    looks_configs[i], 0)
            match_config.player_configs.append(copied)

        manager = SetupManager()
        manager.load_match_config(match_config, {})
        manager.connect_to_game(
            RocketLeagueLauncherPreference(
                RocketLeagueLauncherPreference.STEAM, False))
        manager.start_match()
Ejemplo n.º 11
0
def rlbot_to_player_config(player: dict, team: Team):
    bot_path = player["path"]
    if isinstance(bot_path, list):
        bot_path = path.join(*bot_path)

    if "$RLBOTPACKROOT" in bot_path:
        for bot_folder in rlbot_gui.bot_folder_settings["folders"].keys():
            adjusted_folder = path.join(bot_folder, "RLBotPack-master")
            subbed_path = bot_path.replace("$RLBOTPACKROOT", adjusted_folder)
            if path.exists(subbed_path):
                print("it exists!")
                bot_path = subbed_path
                break

    player_config = PlayerConfig()
    player_config.bot = True
    player_config.rlbot_controlled = True
    player_config.name = player["name"]
    player_config.team = team.value
    player_config.config_path = bot_path
    config = get_bot_config_bundle(bot_path)
    loadout = load_bot_appearance(config.get_looks_config(), team.value)
    player_config.loadout_config = loadout
    return player_config
Ejemplo n.º 12
0
def spawn_car_for_viewing(looks: dict, team: int, showcase_type: str,
                          map_name: str):
    looks_config = convert_to_looks_config(looks)
    loadout_config = load_bot_appearance(looks_config, team)
    spawn_car_in_showroom(loadout_config, team, showcase_type, map_name)
Ejemplo n.º 13
0
 def load_cfg_file(self, file_path: Path, team: int) -> LoadoutConfig:
     file = self.base_directory / Path(file_path)
     config_object = create_looks_configurations().parse_file(file)
     return load_bot_appearance(config_object, team)