def main(): definitions = BotDefinitions() zip_types = definitions.zippable zip_keys = list(zip_types.keys()) zip_keys.append("all") parser = argparse.ArgumentParser( description="Create a Ladder Manager ready zip archive for SC2 AI, AI Arena, Probots, ..." ) parser.add_argument("-n", "--name", help=f"Bot name: {zip_keys}.") parser.add_argument("-e", "--exe", help="Also make executable (Requires pyinstaller)", action="store_true") args = parser.parse_args() bot_name = args.name if not os.path.exists("dummy"): os.mkdir("dummy") update_version_txt() if bot_name == "all" or not bot_name: zip_keys.remove("all") for key in zip_keys: zip_types.get(key).create_ladder_zip(args.exe) else: if bot_name not in zip_keys: raise ValueError(f"Unknown bot: {bot_name}, allowed values are: {zip_keys}") zip_types.get(bot_name).create_ladder_zip(args.exe)
def main(): update_version_txt() root_dir = os.path.dirname(os.path.abspath(__file__)) ladder_bots_path = os.path.join("Bots") ladder_bots_path = os.path.join(root_dir, ladder_bots_path) definitions: BotDefinitions = BotDefinitions(ladder_bots_path) starter = GameStarter(definitions) starter.play()
def create_ladder_zip(archive_zip: LadderZip): update_version_txt() print() archive_name = archive_zip.archive bot_specific_paths = archive_zip.files # Remove previous archive if os.path.isfile(archive_name): print(f"Deleting {archive_name}") os.remove(archive_name) files_to_zip = [] directories_to_zip = [] files_to_delete = [] archive_zip.pre_zip() for file in bot_specific_paths: if not os.path.exists(file): raise ValueError(f"'{file}' does not exist.") if os.path.isdir(file): directories_to_zip.append(file) else: files_to_zip.append(file) print() print(f"Zipping {archive_name}") zipf = zipfile.ZipFile(archive_name, "w", zipfile.ZIP_DEFLATED) for file in files_to_zip: zipf.write(file) for directory in directories_to_zip: zipdir(directory, zipf) zipf.close() print() for file in files_to_delete: if os.path.isdir(file): print(f"Deleting directory {file}") # os.rmdir(file) shutil.rmtree(file) else: print(f"Deleting file {file}") os.remove(file) if not os.path.exists("publish"): os.mkdir("publish") shutil.move(archive_name, os.path.join("publish", archive_name)) archive_zip.post_zip() print(f"\nSuccessfully created {os.path.join('publish', archive_name)}")
def main(): parser = argparse.ArgumentParser( description= "Create a Ladder Manager ready zip archive for SC2 AI, AI Arena, Probots, ..." ) parser.add_argument("-e", "--exe", help="Also make executable (Requires pyinstaller)", action="store_true") args = parser.parse_args() update_version_txt() ladder_zip.create_ladder_zip(args.exe)
def create_ladder_zip(archive_zip: LadderZip, exe: bool): update_version_txt() print() archive_name = archive_zip.archive bot_specific_paths = archive_zip.files # Remove previous archive if os.path.isfile(archive_name): print(f"Deleting {archive_name}") os.remove(archive_name) files_to_zip = [] directories_to_zip = [] files_to_delete = [] f = open("ladderbots.json", "w+") f.write(archive_zip.create_json()) f.close() archive_zip.pre_zip() for src, dest in bot_specific_paths: if not os.path.exists(src): raise ValueError(f"'{src}' does not exist.") if dest is None: # the file or folder can be used as is. if os.path.isdir(src): directories_to_zip.append(src) else: files_to_zip.append(src) else: # need to move the file or folder. if os.path.isdir(src): shutil.copytree(src, dest) directories_to_zip.append(dest) files_to_delete.append(dest) else: # src is a file. src_file = os.path.basename(src) if os.path.isdir(dest): # Join directory with filename dest_path = os.path.join(dest, src_file) else: # Rename into another file dest_path = dest files_to_zip.append(dest_path) print(f"Copying {src} ... {dest_path}") files_to_delete.append(dest_path) shutil.copy(src, dest_path) print() print(f"Zipping {archive_name}") zipf = zipfile.ZipFile(archive_name, 'w', zipfile.ZIP_DEFLATED) for file in files_to_zip: zipf.write(file) for directory in directories_to_zip: zipdir(directory, zipf) zipf.close() print() for file in files_to_delete: if os.path.isdir(file): print(f"Deleting directory {file}") # os.rmdir(file) shutil.rmtree(file) else: print(f"Deleting file {file}") os.remove(file) os.remove("ladderbots.json") if not os.path.exists('publish'): os.mkdir('publish') shutil.move(archive_name, os.path.join("publish", archive_name)) archive_zip.post_zip() print(f"\nSuccessfully created {os.path.join('publish', archive_name)}") if exe: archive_zip.package_executable("publish")
import sc2 from config import get_config from dummies.protoss import * from dummies.terran import * from dummies.zerg import * from dummies.debug import * from examples.terran.mass_reaper import MassReaperBot from examples.terran.proxy_rax import ProxyRaxBot from examples.worker_rush import WorkerRushBot from sc2 import run_game, maps, Race, Difficulty, AIBuild from sc2.paths import Paths from sc2.player import Bot, Computer, AbstractPlayer, Human from version import update_version_txt update_version_txt() config = get_config() log_level = config["general"]["log_level"] root_logger = logging.getLogger() # python-sc2 logs a ton of spam with log level DEBUG. We do not want that. root_logger.setLevel(log_level) # Remove handlers from python-sc2 so we don't get the same messages twice. for handler in sc2.main.logger.handlers: sc2.main.logger.removeHandler(handler) new_line = '\n'