def load_all_bots(ld: LeagueDir) -> Mapping[BotID, BotConfigBundle]: bots = { fmt_bot_name(bot_config.name): bot_config for bot_config in scan_directory_for_bot_configs(ld.bots) } # Psyonix bots psyonix_allstar = get_bot_config_bundle(PackageFiles.psyonix_allstar) psyonix_pro = get_bot_config_bundle(PackageFiles.psyonix_pro) psyonix_rookie = get_bot_config_bundle(PackageFiles.psyonix_rookie) psyonix_allstar_name = fmt_bot_name(psyonix_allstar.name) psyonix_pro_name = fmt_bot_name(psyonix_pro.name) psyonix_rookie_name = fmt_bot_name(psyonix_rookie.name) bots[psyonix_allstar_name] = psyonix_allstar bots[psyonix_pro_name] = psyonix_pro bots[psyonix_rookie_name] = psyonix_rookie # Psyonix bots have skill values psyonix_bot_skill[psyonix_allstar_name] = 1.0 psyonix_bot_skill[psyonix_pro_name] = 0.5 psyonix_bot_skill[psyonix_rookie_name] = 0.0 return bots
def gather_versioned_bots(self): git_root = self.working_dir._working_dir subprocess.call(['git', 'pull'], cwd=git_root) bot_folders = [p for p in self.working_dir.bots.iterdir() if p.is_dir()] versioned_bots = set() for folder in bot_folders: relative_path = relpath(folder, git_root) iso_date_binary = subprocess.check_output( ["git", "log", "-n", "1", '--format="%ad"', "--date=iso-strict", "--", relative_path], cwd=git_root) iso_date = iso_date_binary.decode(sys.stdout.encoding).strip("\"\n") for bot_config in scan_directory_for_bot_configs(folder): versioned_bot = VersionedBot(bot_config, datetime.fromisoformat(iso_date)) print(versioned_bot) versioned_bots.add(versioned_bot) self.bundle_map = { vb.get_unversioned_key(): vb.bot_config for vb in versioned_bots } self.versioned_bots_by_name = { vb.get_unversioned_key(): vb for vb in versioned_bots } bots_available = set([vb.get_unversioned_key() for vb in versioned_bots]) incoming_bots = bots_available.difference(set(self.ladder.bots)) self.ladder.bots.extend(incoming_bots) self.ladder.bots = [bot for bot in self.ladder.bots if bot in bots_available] self.ladder.write(self.working_dir.ladder)
def bootstrap_python_bot(bot_name, directory): sanitized_name = convert_to_filename(bot_name) bot_directory = Path(directory or '.') top_dir = bot_directory / sanitized_name if os.path.exists(top_dir): raise FileExistsError(f'There is already a bot named {sanitized_name}, please choose a different name!') with tempfile.TemporaryDirectory() as tmpdirname: tmpdir = Path(tmpdirname) print('created temporary directory', tmpdir) download_and_extract_zip( download_url='https://github.com/RLBot/RLBotPythonExample/archive/master.zip', local_folder_path=tmpdir) safe_move(tmpdir / 'RLBotPythonExample-master', top_dir) bundle = scan_directory_for_bot_configs(top_dir).pop() config_file = bundle.config_path python_file = bundle.python_file replace_all(config_file, r'name = .*$', 'name = ' + bot_name) # This is intended to open the example python file in the default system editor for .py files. # Hopefully this will be VS Code or notepad++ or something. If it gets executed as a python script, no harm done. # This is in a try/except so no error is raised if the user does not have any editor associated with .py files. try: os.startfile(python_file) except OSError: print(f"You have no default program to open .py files. Your new bot is located at {os.path.abspath(top_dir)}") return config_file
def bootstrap_rust_bot(bot_name, directory): sanitized_name = convert_to_filename(bot_name) bot_directory = Path(directory or '.') top_dir = bot_directory / sanitized_name if os.path.exists(top_dir): raise FileExistsError(f'There is already a bot named {sanitized_name}, please choose a different name!') with tempfile.TemporaryDirectory() as tmpdirname: tmpdir = Path(tmpdirname) print('created temporary directory', tmpdir) download_and_extract_zip( download_url='https://github.com/NicEastvillage/RLBotRustTemplateBot/archive/master.zip', local_folder_path=tmpdir) safe_move(tmpdir / 'RLBotRustTemplateBot-master', top_dir) bundle = scan_directory_for_bot_configs(top_dir).pop() config_file = bundle.config_path replace_all(config_file, r'name = .*$', f'name = {bot_name}') replace_all(config_file, r'path = .*$', f'path = ../target/debug/{bot_name}.exe') cargo_toml_file = top_dir / 'Cargo.toml' replace_all(cargo_toml_file, r'name = .*$', f'name = "{bot_name}"') replace_all(cargo_toml_file, r'authors = .*$', f'authors = []') # This is intended to open the main module in the default system editor for .rs files. # Hopefully this will be VS Code or notepad++ or something. try: os.startfile(top_dir / 'src' / 'main.rs') except OSError: print(f"You have no default program to open .rs files. Your new bot is located at {os.path.abspath(top_dir)}") return config_file
def get_bots_from_directory(bot_directory): return [{ 'name': bundle.name, 'type': 'rlbot', 'image': 'imgs/rlbot.png', 'path': bundle.config_path, 'info': read_info(bundle) } for bundle in scan_directory_for_bot_configs(bot_directory)]
def scan_for_bots(directory): bot_directory = directory or settings.value(DEFAULT_BOT_FOLDER, type=str) or "." return [{ 'name': bundle.name, 'type': 'rlbot', 'image': 'imgs/rlbot.png', 'path': bundle.config_path, 'info': read_info(bundle) } for bundle in scan_directory_for_bot_configs(bot_directory)]
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()
def load_all_bots_versioned( working_dir: WorkingDir) -> Mapping[str, VersionedBot]: bot_folders = [p for p in working_dir.bots.iterdir() if p.is_dir()] root = working_dir._working_dir versioned_bots = set() for folder in bot_folders: relative_path = relpath(folder, root) date = None try: iso_date_binary = subprocess.check_output([ "git", "log", "-n", "1", '--format="%ad"', "--date=iso-strict", "--", relative_path ], cwd=root) iso_date = iso_date_binary.decode( sys.stdout.encoding).strip("\"\n") if len(iso_date) > 0: date = datetime.fromisoformat(iso_date) except Exception: pass if date is None: date = get_modified_date(folder) for bot_config in scan_directory_for_bot_configs(folder): versioned_bot = VersionedBot(bot_config, date) versioned_bots.add(versioned_bot) psyonix_allstar, psyonix_pro, psyonix_rookie = load_psyonix_bots() versioned_bots.add(VersionedBot(psyonix_allstar, DEFAULT_TIMESTAMP)) versioned_bots.add(VersionedBot(psyonix_pro, DEFAULT_TIMESTAMP)) versioned_bots.add(VersionedBot(psyonix_rookie, DEFAULT_TIMESTAMP)) return {vb.get_unversioned_key(): vb for vb in versioned_bots}
def load_bot_directory(self, directory): for bundle in scan_directory_for_bot_configs(directory): try: self.load_bot_config_bundle(bundle) except Exception as e: print(e)
def get_bots(self) -> Mapping[str, BotConfigBundle]: return { bot_config.name.lower(): bot_config for bot_config in scan_directory_for_bot_configs(self.bots) }
def get_bots_from_directory(bot_directory): bundles = filter_hidden_bundles( scan_directory_for_bot_configs(bot_directory)) return [serialize_bundle(bundle) for bundle in bundles]
def get_bots_from_directory(bot_directory): return [ serialize_bundle(bundle) for bundle in scan_directory_for_bot_configs(bot_directory) ]
def get_bots(self): return scan_directory_for_bot_configs(BOT_DIRECTORY)
def get_bots(working_dir: WorkingDir) -> Mapping[BotID, BotConfigBundle]: return { make_bot_id(working_dir, bot_config): bot_config for bot_config in scan_directory_for_bot_configs(working_dir.bots) }