def base_create_agent_configurations(cls) -> ConfigObject: """ This is used when initializing agent config via builder pattern. It also calls `create_agent_configurations` that can be used by BaseAgent subclasses for custom configs. :return: Returns an instance of a ConfigObject object. """ config = ConfigObject() location_config = config.add_header_name(BOT_CONFIG_MODULE_HEADER) location_config.add_value( LOOKS_CONFIG_KEY, str, default='./atba_looks.cfg', description='Path to loadout config from runner') location_config.add_value( PYTHON_FILE_KEY, str, default='./atba.py', description="Bot's python file.\nOnly need this if RLBot controlled" ) location_config.add_value( BOT_NAME_KEY, str, default='nameless', description='The name that will be displayed in game') cls.create_agent_configurations(config) return config
def base_create_agent_configurations(cls) -> ConfigObject: """ This is used when initializing agent config via builder pattern. It also calls `create_agent_configurations` that can be used by BaseAgent subclasses for custom configs. :return: Returns an instance of a ConfigObject object. """ config = ConfigObject() location_config = config.add_header_name(BOT_CONFIG_MODULE_HEADER) location_config.add_value(LOOKS_CONFIG_KEY, str, description='Path to loadout config from runner') location_config.add_value(PYTHON_FILE_KEY, str, description="Bot's python file.\nOnly need this if RLBot controlled") location_config.add_value(BOT_NAME_KEY, str, default='nameless', description='The name that will be displayed in game') details_config = config.add_header_name(BOT_CONFIG_DETAILS_HEADER) details_config.add_value('developer', str, description="Name of the bot's creator/developer") details_config.add_value('description', str, description="Short description of the bot") details_config.add_value('fun_fact', str, description="Fun fact about the bot") details_config.add_value('github', str, description="Link to github repository") details_config.add_value('language', str, description="Programming language") cls.create_agent_configurations(config) return config
def create_bot_config_layout(): config_object = ConfigObject() rlbot_header = config_object.add_header_name(RLBOT_CONFIGURATION_HEADER) rlbot_header.add_value( EXTENSION_PATH_KEY, str, default=None, description='A path to the extension file we want to load') team_header = config_object.add_header_name(TEAM_CONFIGURATION_HEADER) team_header.add_value( "Team Blue Color", int, default=0, description="Changes Blue team color, use 0 to use default color") team_header.add_value( "Team Blue Name", str, default="Blue", description="Changes the Team name to use instead of 'Blue'") team_header.add_value( "Team Orange Color", int, default=0, description="Changes Blue team color, use 0 to use default color") team_header.add_value( "Team Orange Name", str, default="Orange", description="Changes the Team name to use instead of 'Orange'") add_match_settings_header(config_object) add_mutator_header(config_object) add_participant_header(config_object) return config_object
def base_create_agent_configurations(cls) -> ConfigObject: """ This is used when initializing agent config via builder pattern. It also calls `create_agent_configurations` that can be used by BaseAgent subclasses for custom configs. :return: Returns an instance of a ConfigObject object. """ config = ConfigObject() location_config = config.add_header_name(LOCATIONS_HEADER) location_config.add_value(PYTHON_FILE_KEY, str, description="Bot's python file.\nOnly need this if RLBot controlled") location_config.add_value(REQUIREMENTS_FILE_KEY, str, description="Python requirements.txt file listing needed dependencies.") location_config.add_value(NAME_KEY, str, default='nameless', description='The name that will be displayed in game') location_config.add_value(LOGO_FILE_KEY, str, description="Location of an image file to use as your bot's logo") location_config.add_value(SUPPORTS_EARLY_START_KEY, bool, description="True if this bot can be started before the Rocket League match begins.") location_config.add_value(REQUIRES_TKINTER, bool, description="True if the tkinter library is needed.") location_config.add_value(USE_VIRTUAL_ENVIRONMENT_KEY, bool, description="True if the runnable wants to run in a virtual environment.") details_config = config.add_header_name(DETAILS_HEADER) details_config.add_value('developer', str, description="Name of the bot's creator/developer") details_config.add_value('description', str, description="Short description of the bot") details_config.add_value('fun_fact', str, description="Fun fact about the bot") details_config.add_value('github', str, description="Link to github repository") details_config.add_value('language', str, description="Programming language") details_config.add_value('tags', str, description="Comma separated list of tags, used by RLBotGUI") cls.create_agent_configurations(config) return config
def load_bot_appearance(looks_config_object: ConfigObject, team_num: int) -> LoadoutConfig: loadout_config = LoadoutConfig() loadout_config.paint_config = LoadoutPaintConfig() loadout_header = BOT_CONFIG_LOADOUT_HEADER if team_num == 1 and looks_config_object.has_section( BOT_CONFIG_LOADOUT_ORANGE_HEADER): loadout_header = BOT_CONFIG_LOADOUT_ORANGE_HEADER parse_bot_loadout(loadout_config, looks_config_object, loadout_header) if team_num == 0 and looks_config_object.has_section( BOT_CONFIG_LOADOUT_PAINT_BLUE_HEADER): parse_bot_loadout_paint(loadout_config.paint_config, looks_config_object, BOT_CONFIG_LOADOUT_PAINT_BLUE_HEADER) if team_num == 1 and looks_config_object.has_section( BOT_CONFIG_LOADOUT_PAINT_ORANGE_HEADER): parse_bot_loadout_paint(loadout_config.paint_config, looks_config_object, BOT_CONFIG_LOADOUT_PAINT_ORANGE_HEADER) return loadout_config
def create_looks_configurations() -> ConfigObject: config = ConfigObject() config.add_header(BOT_CONFIG_LOADOUT_HEADER, create_loadout()) config.add_header(BOT_CONFIG_LOADOUT_ORANGE_HEADER, create_loadout()) config.add_header(BOT_CONFIG_LOADOUT_PAINT_BLUE_HEADER, create_loadout_paint()) config.add_header(BOT_CONFIG_LOADOUT_PAINT_ORANGE_HEADER, create_loadout_paint()) return config
def load_config(self, framework_config: ConfigObject = None, config_location=DEFAULT_RLBOT_CONFIG_LOCATION, bot_configs=None, looks_configs=None): """ Loads the configuration into internal data structures, which prepares us to later launch bot processes and start the match. :param framework_config: A config object that indicates what bots to run. May come from parsing a rlbot.cfg. :param config_location: The location of the rlbot.cfg file, which will be used to resolve relative paths. :param bot_configs: Overrides for bot configurations. :param looks_configs: Overrides for looks configurations. """ self.logger.debug('reading the configs') # Set up RLBot.cfg if framework_config is None: framework_config = create_bot_config_layout() framework_config.parse_file(config_location, max_index=MAX_PLAYERS) if bot_configs is None: bot_configs = {} if looks_configs is None: looks_configs = {} match_config = parse_match_config(framework_config, config_location, bot_configs, looks_configs) self.load_match_config(match_config, bot_configs)
def parse_match_settings(match_settings, config: ConfigObject): """ Parses the matching settings modifying the match settings object. :param match_settings: :param config: :return: """ match_settings.game_mode = config.get(MATCH_CONFIGURATION_HEADER, GAME_MODE) match_settings.game_map = config.get(MATCH_CONFIGURATION_HEADER, GAME_MAP) match_settings.skip_replays = config.getboolean(MATCH_CONFIGURATION_HEADER, SKIP_REPLAYS) match_settings.instant_start = config.getboolean( MATCH_CONFIGURATION_HEADER, INSTANT_START) match_settings.existing_match_behavior = config.get( MATCH_CONFIGURATION_HEADER, EXISTING_MATCH_BEHAVIOR) match_settings.enable_lockstep = config.getboolean( MATCH_CONFIGURATION_HEADER, ENABLE_LOCKSTEP) match_settings.enable_rendering = config.getboolean( MATCH_CONFIGURATION_HEADER, ENABLE_RENDERING) match_settings.enable_state_setting = config.getboolean( MATCH_CONFIGURATION_HEADER, ENABLE_STATE_SETTING) match_settings.auto_save_replay = config.getboolean( MATCH_CONFIGURATION_HEADER, AUTO_SAVE_REPLAY) parse_mutator_settings(match_settings.mutators, config)
def parse_match_config(config_parser: ConfigObject, config_location, config_bundle_overrides, looks_config_overrides) -> MatchConfig: match_config = MatchConfig() match_config.mutators = MutatorConfig() # Determine number of participants num_players = get_num_players(config_parser) parse_match_settings(match_config, config_parser) # Retrieve bot config files config_bundles = get_bot_config_bundles(num_players, config_parser, config_location, config_bundle_overrides) match_config.player_configs = [] human_index_tracker = IncrementingInteger(0) # Set configuration values for bots and store name and team for i in range(num_players): config_bundle = config_bundles[i] looks_config_object = None if i in looks_config_overrides: looks_config_object = looks_config_overrides[i] player_config = _load_bot_config(i, config_bundle, looks_config_object, config_parser, human_index_tracker) match_config.player_configs.append(player_config) extension_path = config_parser.get(RLBOT_CONFIGURATION_HEADER, EXTENSION_PATH_KEY) if extension_path and extension_path != 'None': # The string 'None' ends up in people's config a lot. match_config.extension_config = ExtensionConfig() match_config.extension_config.python_file_path = extension_path match_config.networking_role = config_parser.get( RLBOT_CONFIGURATION_HEADER, NETWORKING_ROLE_KEY) match_config.network_address = config_parser.get( RLBOT_CONFIGURATION_HEADER, NETWORK_ADDRESS_KEY) match_config.script_configs = [ ScriptConfig(bundle.config_path) for bundle in get_script_config_bundles(config_parser, config_location) ] return match_config
def create_bot_config_layout(): config_object = ConfigObject() rlbot_header = config_object.add_header_name(RLBOT_CONFIGURATION_HEADER) rlbot_header.add_value( EXTENSION_PATH_KEY, str, default=None, description='A path to the extension file we want to load') rlbot_header.add_value( NETWORKING_ROLE_KEY, str, default='none', description= 'Defines the behavior when connecting multiple RLBot instances over a network.' ) rlbot_header.add_value( NETWORK_ADDRESS_KEY, str, default='127.0.0.1', description='The IP address to connect to if networking is desired.') rlbot_header.add_value( LAUNCHER_PREFERENCE_KEY, str, default=None, description="Determines whether to launch with epic or steam.") team_header = config_object.add_header_name(TEAM_CONFIGURATION_HEADER) team_header.add_value( "Team Blue Color", int, default=0, description="Changes Blue team color, use 0 to use default color") team_header.add_value( "Team Blue Name", str, default="Blue", description="Changes the Team name to use instead of 'Blue'") team_header.add_value( "Team Orange Color", int, default=0, description="Changes Blue team color, use 0 to use default color") team_header.add_value( "Team Orange Name", str, default="Orange", description="Changes the Team name to use instead of 'Orange'") add_match_settings_header(config_object) add_mutator_header(config_object) add_participant_header(config_object) add_scripts_header(config_object) return config_object
def parse_match_config(config_parser: ConfigObject, config_location, config_bundle_overrides, looks_config_overrides) -> MatchConfig: match_config = MatchConfig() match_config.mutators = MutatorConfig() # Determine number of participants num_players = get_num_players(config_parser) parse_match_settings(match_config, config_parser) # Retrieve bot config files config_bundles = get_bot_config_bundles(num_players, config_parser, config_location, config_bundle_overrides) match_config.player_configs = [] human_index_tracker = IncrementingInteger(0) # Set configuration values for bots and store name and team for i in range(num_players): config_bundle = config_bundles[i] if i not in looks_config_overrides: looks_config_object = config_bundle.get_looks_config() else: looks_config_object = looks_config_overrides[i] player_config = _load_bot_config(i, config_bundle, looks_config_object, config_parser, human_index_tracker) match_config.player_configs.append(player_config) for path in config_parser.get(BOTLESS_AGENT_CONFIGURATION_HEADER, BOTLESS_AGENT_PATH_KEY): if path != 'None': match_config.botless_agents.append(path) extension_path = config_parser.get(RLBOT_CONFIGURATION_HEADER, EXTENSION_PATH_KEY) if extension_path and extension_path != 'None': # The string 'None' ends up in people's config a lot. match_config.extension_config = ExtensionConfig() match_config.extension_config.python_file_path = extension_path return match_config
def create_agent_configurations(config: ConfigObject): """ creates the configurations for the recorder to have a well defined config file """ params = config.get_header(BOT_CONFIG_AGENT_HEADER) params.add_value( 'replay_path', str, default='./tests/replays', description='directory where the replays will be saved.') params.add_value( 'agent_path', str, default='./agents/legacy.py', description= 'python file containing the agent class, relative to RecorderAgent.py path' ) params.add_value( 'data_format', str, default='BINDao', description= "Dao name for the data format you want \n(BINDao for Binary, JSONDao for Json XMLDao for Xml, ...)" ) params.add_value( 'max_frames', int, default=-1, description= "Number of steps in onefile, -1 means one file for one replay\nthis might be resource intensive" )
def create_agent_configurations(config: ConfigObject): params = config.get_header(BOT_CONFIG_AGENT_HEADER) params.add_value("render_statue", bool, default=False) params.add_value("render_disco_ball", bool, default=False) params.add_value("enable_dodge_bounce_audio", bool, default=False) params.add_value("enable_goal_music", bool, default=False) params.add_value("enable_ball_touch_audio", bool, default=False)
def create_agent_configurations(config: ConfigObject): params = config.get_header(BOT_CONFIG_AGENT_HEADER) params.add_value('flip_turning', bool, default=False, description='if true bot will turn opposite way') params.add_value('test_rendering', bool, default=False, description='if true bot will render random stuff') params.add_value('test_quickchat', bool, default=False, description='if true bot will spam quickchats') params.add_value('test_dropshot', bool, default=False, description='if true bot will render dropshot info') params.add_value('test_state', bool, default=False, description='if true bot will alter its game state') params.add_value('test_ball_prediction', bool, default=False, description='if true bot will render ball prediction')
def create_agent_configurations(config: ConfigObject): params = config.get_header(BOT_CONFIG_AGENT_HEADER) params.add_value( 'java_executable_path', str, default=None, description='Relative path to the executable that runs java.')
def create_agent_configurations(config: ConfigObject): super(LeviAgent, LeviAgent).create_agent_configurations(config) params = config.get_header(BOT_CONFIG_AGENT_HEADER) params.add_value('model_path', str, default=os.path.join('models', 'cool_atba.mdl'), description='Path to the model file')
def parse_bot_loadout_paint(player_configuration, bot_config: ConfigObject, loadout_header: str): player_configuration.car_paint_id = bot_config.getint(loadout_header, 'car_paint_id') player_configuration.decal_paint_id = bot_config.getint(loadout_header, 'decal_paint_id') player_configuration.wheels_paint_id = bot_config.getint(loadout_header, 'wheels_paint_id') player_configuration.boost_paint_id = bot_config.getint(loadout_header, 'boost_paint_id') player_configuration.antenna_paint_id = bot_config.getint(loadout_header, 'antenna_paint_id') player_configuration.hat_paint_id = bot_config.getint(loadout_header, 'hat_paint_id') player_configuration.trails_paint_id = bot_config.getint(loadout_header, 'trails_paint_id') player_configuration.goal_explosion_paint_id = bot_config.getint(loadout_header, 'goal_explosion_paint_id')
def parse_bot_loadout_paint(paint_config: LoadoutPaintConfig, bot_config: ConfigObject, loadout_header: str): paint_config.car_paint_id = bot_config.getint(loadout_header, 'car_paint_id') paint_config.decal_paint_id = bot_config.getint(loadout_header, 'decal_paint_id') paint_config.wheels_paint_id = bot_config.getint(loadout_header, 'wheels_paint_id') paint_config.boost_paint_id = bot_config.getint(loadout_header, 'boost_paint_id') paint_config.antenna_paint_id = bot_config.getint(loadout_header, 'antenna_paint_id') paint_config.hat_paint_id = bot_config.getint(loadout_header, 'hat_paint_id') paint_config.trails_paint_id = bot_config.getint(loadout_header, 'trails_paint_id') paint_config.goal_explosion_paint_id = bot_config.getint(loadout_header, 'goal_explosion_paint_id')
def create_agent_configurations(config: ConfigObject): super(TeacherAgent, TeacherAgent).create_agent_configurations(config) params = config.get_header(BOT_CONFIG_AGENT_HEADER) params.add_value('teacher_path', str, default=os.path.join('agents', 'cool_atba', 'cool_atba_agent.py'), description='Path to the teacher bot')
def parse_match_settings(match_settings, config: ConfigObject): """ Parses the matching settings modifying the match settings object. :param match_settings: :param config: :return: """ match_settings.game_mode = config.get(MATCH_CONFIGURATION_HEADER, GAME_MODE) match_settings.game_map = config.get(MATCH_CONFIGURATION_HEADER, GAME_MAP) match_settings.skip_replays = config.getboolean(MATCH_CONFIGURATION_HEADER, SKIP_REPLAYS) match_settings.instant_start = config.getboolean( MATCH_CONFIGURATION_HEADER, INSTANT_START) parse_mutator_settings(match_settings.mutators, config)
def create_agent_configurations(config: ConfigObject): params = config.get_header(BOT_CONFIG_AGENT_HEADER) params.add_value('port', int, default=42008, description='Port to use for websocket communication') params.add_value('spawn_browser', bool, default=False, description='True if we should automatically open google chrome to the scratch page.') params.add_value('sb3file', str, default=None, description='Location of the scratch .sb3 file to load automatically') params.add_value('headless', bool, default=False, description='If true, bot will run automatically with no visible web browser')
def __init__(self, config_directory, config_obj: ConfigObject, config_file_name: str = None): self.config_directory = config_directory self.config_file_name = config_file_name self.config_path = os.path.join(self.config_directory, self.config_file_name) self.config_obj = config_obj self.base_agent_config = RLBotRunnable.base_create_agent_configurations() self.base_agent_config.parse_file(self.config_obj, config_directory=config_directory) self.name = config_obj.get(BOT_CONFIG_MODULE_HEADER, BOT_NAME_KEY) self.supports_early_start = self.base_agent_config.get(BOT_CONFIG_MODULE_HEADER, SUPPORTS_EARLY_START_KEY) self.requirements_file = self.get_absolute_path(BOT_CONFIG_MODULE_HEADER, REQUIREMENTS_FILE_KEY)
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
def create_agent_configurations(config: ConfigObject) -> None: params: ConfigHeader = config.get_header(BOT_CONFIG_AGENT_HEADER) params.add_value("ip", str, default="127.0.0.1", description="The IP address of the host machine") params.add_value( "port", int, default=5555, description="The port of the host machine that should be used")
def create_agent_configurations(config: ConfigObject): super(SwarmAgent, SwarmAgent).create_agent_configurations(config) params = config.get_header(BOT_CONFIG_AGENT_HEADER) params.add_value('model_path', str, default=os.path.join('models', 'cool_atba.mdl'), description='Path to the model file') params.add_value('load_model', bool, default=False, description='The model should be loaded')
def _create_looks_configurations() -> ConfigObject: config = ConfigObject() config.add_header(BOT_CONFIG_LOADOUT_HEADER, BaseAgent._create_loadout()) config.add_header(BOT_CONFIG_LOADOUT_ORANGE_HEADER, BaseAgent._create_loadout()) return config
def create_agent_configurations(config: ConfigObject): params = config.get_header(BOT_CONFIG_AGENT_HEADER) params.add_value('flip_turning', bool, default=False, description='if true bot will turn opposite way') params.add_value('test_rendering', bool, default=False, description='if true bot will render random stuff') params.add_value('test_quickchat', bool, default=False, description='if true bot will spam quickchats')
def get_script_config_bundles(match_config: ConfigObject, config_location): """ Adds all the script config bundles found in the match config file. Attempts to read indexed config keys until it hits an empty one. """ config_bundles = [] for i in itertools.count(): script_config_relative_path = match_config.get(SCRIPT_CONFIGURATION_HEADER, SCRIPT_CONFIG_KEY, i) if script_config_relative_path is None or script_config_relative_path == 'None': break script_config_path = os.path.join(os.path.dirname(config_location), script_config_relative_path) config_bundles.append(get_script_config_bundle(script_config_path)) return config_bundles
def __init__(self, config_directory, config_obj: ConfigObject, config_file_name: str = None): self.config_directory = config_directory self.config_file_name = config_file_name self.config_path = os.path.join(self.config_directory, self.config_file_name) self.config_obj = config_obj self.base_agent_config = BaseAgent.base_create_agent_configurations() self.base_agent_config.parse_file(self.config_obj, config_directory=config_directory) self.name = config_obj.get(BOT_CONFIG_MODULE_HEADER, BOT_NAME_KEY) self.looks_path = self.get_absolute_path(BOT_CONFIG_MODULE_HEADER, LOOKS_CONFIG_KEY) self.python_file = self.get_absolute_path(BOT_CONFIG_MODULE_HEADER, PYTHON_FILE_KEY)
def __init__(self, config_directory, config_obj: ConfigObject, config_file_name: str = None): self.config_directory = config_directory self.config_file_name = config_file_name self.config_path = os.path.join(self.config_directory, self.config_file_name) self.config_obj = config_obj self.base_agent_config = BaseAgent.base_create_agent_configurations() self.base_agent_config.parse_file(self.config_obj, config_directory=config_directory) self.name = config_obj.get(BOT_CONFIG_MODULE_HEADER, BOT_NAME_KEY) self.looks_path = self.get_absolute_path(BOT_CONFIG_MODULE_HEADER, LOOKS_CONFIG_KEY) self.python_file = self.get_absolute_path(BOT_CONFIG_MODULE_HEADER, PYTHON_FILE_KEY) self.loadout_generator_file = self.get_absolute_path( BOT_CONFIG_MODULE_HEADER, LOADOUT_GENERATOR_FILE_KEY) self.supports_early_start = self.base_agent_config.get( BOT_CONFIG_MODULE_HEADER, SUPPORTS_EARLY_START_KEY)