def cli(): # mini/unit test """ PURPOSE: command-line interface for map information """ options = optionsParser().parse_args() params = getSelectionParams(options) if options.list or options.details: specifiedMaps = filterMapNames(options.mapname, records=filterMapAttrs(**params), excludeRegex=options.exclude, closestMatch=options.best) if specifiedMaps: for v in specifiedMaps: if options.details: v.display() else: print(v) print("Found %d maps that match given criteria." % (len(specifiedMaps))) else: print("No matching maps found.") else: try: specifiedMaps = selectMap(options.mapname, excludeName=options.exclude, closestMatch=options.best, **params) except Exception as e: specifiedMaps = [] print("No matching maps found: %s" % e) if not isinstance(specifiedMaps, list): specifiedMaps = [specifiedMaps] for m in specifiedMaps: if options.path: print(m.path) else: print(m.name)
def test_filter_map_names(): r = f.filterMapNames("water", closestMatch=False) assert len(r) == 1 assert r[0].name == "Backwater" r = f.filterMapNames("w[ea][rt]", closestMatch=False) rNames = {m.name for m in r} display_test(rNames, len(rNames), 3) assert "Backwater" in rNames assert "Eastwatch" in rNames assert "FlowerFields" in rNames rNames = {m.name for m in f.filterMapNames("at", closestMatch=True)} display_test(rNames, len(rNames), 4) assert "Flat32" in rNames assert "Flat48" in rNames assert "Flat64" in rNames assert "Flat96" in rNames rNames = {m.name for m in f.filterMapNames("[rst]e", closestMatch=True)} display_test(rNames, len(rNames), 3) assert "Acolyte" in rNames assert "Odyssey" in rNames assert "RedCity" in rNames rNames = {m.name for m in f.filterMapNames("bi", closestMatch=True)} display_test(rNames, len(rNames), 1) assert "16Bit" in rNames rNames = {m.name for m in f.filterMapNames("[amoqy6]", excludeRegex=True, closestMatch=False)} display_test(rNames, len(rNames), 4) assert "BelShirVestige" in rNames assert "Redshift" in rNames assert "Blueshift" in rNames assert "NewkirkPrecinct" in rNames rNames = {m.name for m in f.filterMapNames("[toi]", excludeRegex=True, closestMatch=True)} display_test(rNames, len(rNames), 1) assert "Sequencer" in rNames
def cli(): # mini/unit test """ PURPOSE: command-line interface for map information """ from argparse import ArgumentParser description = "" parser = ArgumentParser(description=description, epilog="version: %s" % __version__) actionOpt = parser.add_argument_group( 'main routine behavior indicating information to provide') actionOpt.add_argument("--list", default=None, action="store_true", help="Display all known maps by category.") actionOpt.add_argument("--details", default=None, action="store_true", help="show details of each mapname.") actionOpt.add_argument("--path", default=None, action="store_true", help="provide the absolute path to the file") functnOpt = parser.add_argument_group('function operation parameters') functnOpt.add_argument("--mapname", default="", help="the name of the specific map to load.") functnOpt.add_argument( "--exclude", action="store_true", help="exclude maps with names specified by --mapname.") functnOpt.add_argument("--best", action="store_true", help="match maps that are closer with --mapname") matchOptn = parser.add_argument_group('record match criteria') matchOptn.add_argument("--ladder", default=None, type=bool, help="ladder must be selected (True) or ignored.") matchOptn.add_argument( "--combat", default=None, type=bool, help="combat maps must be selected (True) or ignored.") matchOptn.add_argument( "--economy", default=None, type=bool, help="economy maps must be selected (True) or ignored.") matchOptn.add_argument( "--scenario", default=None, type=bool, help= "single-player games with a specific objective to achieve must be selected (True) or ignored." ) matchOptn.add_argument("--misc", default=None, type=bool, help="misc maps must be seleced (True) or ignored.") matchOptn.add_argument("--test", default=None, type=bool, help="test maps must be seleced (True) or ignored.") matchOptn.add_argument( "--year", default=None, type=int, help="the calendar year the ladder season occurred.") matchOptn.add_argument( "--season", default=None, type=int, choices=[1, 2, 3, 4], help="the specific ladder season within a calendar year.") matchOptn.add_argument("--mode", default=None, choices=["1v1", "2v2", "3v3", "4v4"], help="the official ladder category to play.") options = parser.parse_args() params = {k:v for k,v in options._get_kwargs()\ if v!=None and k not in c.EXCLUDED_KEYS} if options.list or options.details: specifiedMaps = filterMapNames(options.mapname, records=filterMapAttrs(**params), excludeRegex=options.exclude, closestMatch=options.best) if specifiedMaps: for v in specifiedMaps: if options.details: v.display() else: print(v) print("Found %d maps that match given criteria." % (len(specifiedMaps))) else: print("No matching maps found.") else: specifiedMaps = selectMap(options.mapname, excludeName=options.exclude, closestMatch=options.best, **params) if not isinstance(specifiedMaps, list): specifiedMaps = [specifiedMaps] for m in specifiedMaps: if options.path: print(m.path) else: print(m.name)
def main(): ALLOWED_PLAYERS = list(getKnownPlayers()) ALLOWED_LADDERS = list(getKnownLadders()) ALLOWED_MAPS = filterMapNames("", closestMatch=False) description = "PURPOSE: front-end interface to easily and reliably match against opponents and run Starcraft2 opponents." parser = ArgumentParser(description=description, epilog="version: %s" % __version__) gameOptions = parser.add_argument_group('game lobby actions') gameOptions.add_argument( "--nogui", action="store_true", help= "launch game directly using command-line arguments formatted as key=value." ) gameOptions.add_argument( "--search", default="", help= "retrieve player information from the ladder (comma separated names)", metavar="PLAYERS") gameOptions.add_argument( "--history", action="store_true", help="include match history when using the --search option.") startOption = parser.add_argument_group('sc2 game client gameplay options') startOption.add_argument( "-l", "--ladder", default="localhost", choices=ALLOWED_LADDERS, help="the ladder where the game is run. Allowed values: " + ", ".join(ALLOWED_LADDERS), metavar='') startOption.add_argument( "-p", "--player", default="defaulthuman", choices=ALLOWED_PLAYERS, help= "the player profile the ladder identifies you with. Allowed values: " + ", ".join(ALLOWED_PLAYERS), metavar='') startOption.add_argument("-v", "--version", type=int, help="the specific game version to play.", metavar='') startOption.add_argument( "-e", "--exp", default="lotv", choices=c.EXPO_SELECT.keys(), metavar='', help="the specific game expansion version to play. Allowed values: " + ", ".join(c.EXPO_SELECT.keys())) startOption.add_argument("-r", "--race", default=c.RANDOM, choices=t.SelectRaces.ALLOWED_TYPES, metavar='', help="selected race to play. Allowed values: " + ", ".join(t.SelectRaces.ALLOWED_TYPES)) startOption.add_argument("-m", "--mode", default=c.MODE_1V1, choices=t.GameModes.ALLOWED_TYPES, metavar='', help="game mode to play. DEFAULT: %s" % c.MODE_1V1) startOption.add_argument( "-o", "--obs", default=0, type=int, help= "the number of observers that will watch this match for this player", metavar='int') startOption.add_argument("--observe", action="store_true", help="be a match observer, not a participant.") localOption = parser.add_argument_group( "this individual sc2 client's options") localOption.add_argument( "--windowed", action="store_true", help="launch client in windowed mode (default: full screen).") localOption.add_argument( "--replay", action="store_true", help="store a replay file after the match finishes.") noLadderOpt = parser.add_argument_group( 'mandate a non-ladder (custom) match') noLadderOpt.add_argument( "--opponents", default="", help="specify specific opponent(s), comma separated.", metavar='LIST') noLadderOpt.add_argument("--nofog", action="store_true", help="disable fog of war.") noLadderOpt.add_argument("--map", default=None, help="play on a specific map.", metavar='MAPNAME') noLadderOpt.add_argument( "--step", default=0, type=int, help= "the number of steps between step() actions. A zero value means that the game runs in realtime (default)", metavar='int') aiBotOption = parser.add_argument_group( "observation response contents for AI / bots") aiBotOption.add_argument("--raw", action="store_true", help="return raw data in observations") aiBotOption.add_argument("--feature", action="store_true", help="return feature data in observations.") aiBotOption.add_argument( "--rendered", action="store_true", help="return fully rendered data in observations.") aiBotOption.add_argument("--score", action="store_true", help="return current score data in observations.") aiBotOption.add_argument( "--resolution", default="", help="resolution that the feature/rendered data is returned in.", metavar='AxB') aiBotOption.add_argument( "--minimap", default="", help= "resolution that the feature/rendered minimap data is returned in.", metavar='AxB') aiBotOption.add_argument( "--layerwidth", type=int, default=24, help="the mapping of number of pixels to game grid coordinates.", metavar='int') # TODO -- add all other options versionOpts = parser.add_argument_group('sc2 game client version handling') versionOpts.add_argument("--update", type=str, default="", help="update an existing version.", metavar='<label>,<version>,<base-version>') versionOpts.add_argument("--add", type=str, default="", help="add a new version.", metavar='<label>,<version>,<base-version>') versionOpts.add_argument("--versions", action="store_true", help="display known Starcraft 2 public versions.") options = parser.parse_args() sys.argv = sys.argv[: 1] # remove all arguments to avoid problems with absl FLAGS :( launcher.run(options)
def optionsParser(passedParser=None): if passedParser == None: parser = argparse.ArgumentParser( #usage="python %s"%__file__, description=__doc__, epilog="version: %s" % __version__) else: parser = passedParser ALLOWED_PLAYERS = list(getKnownPlayers()) ALLOWED_LADDERS = list(getKnownLadders()) ALLOWED_MAPS = filterMapNames("", closestMatch=False) gameOptions = parser.add_argument_group('game lobby actions') gameOptions.add_argument( "--nogui", action="store_true", help= "launch game directly using command-line arguments formatted as key=value." ) gameOptions.add_argument( "--search", default="", help= "retrieve player information from the ladder (comma separated names)", metavar="PLAYERS") gameOptions.add_argument( "--history", action="store_true", help="include match history when using the --search option.") startOption = parser.add_argument_group('sc2 game client gameplay options') startOption.add_argument( "-l", "--ladder", default="versentiedge", choices=ALLOWED_LADDERS, help="the ladder where the game is run. Allowed values: " + ", ".join(ALLOWED_LADDERS), metavar='') startOption.add_argument( "-p", "--player", default="defaulthuman", choices=ALLOWED_PLAYERS, help= "the player profile the ladder identifies you with. Allowed values: " + ", ".join(ALLOWED_PLAYERS), metavar='') startOption.add_argument("-v", "--version", type=int, help="the specific game version to play.", metavar='') startOption.add_argument( "-e", "--exp", default="lotv", choices=c.EXPO_SELECT.keys(), metavar='', help="the specific game expansion version to play. Allowed values: " + ", ".join(c.EXPO_SELECT.keys())) startOption.add_argument("-r", "--race", default=c.RANDOM, choices=t.SelectRaces.ALLOWED_TYPES, metavar='', help="selected race to play. Allowed values: " + ", ".join(t.SelectRaces.ALLOWED_TYPES)) startOption.add_argument("-m", "--mode", default=c.MODE_1V1, choices=t.GameModes.ALLOWED_TYPES, metavar='', help="game mode to play. DEFAULT: %s" % c.MODE_1V1) startOption.add_argument( "-o", "--obs", default=0, type=int, help= "the number of observers that will watch this match for this player", metavar='INT') localOption = parser.add_argument_group( "this individual sc2 client's options") localOption.add_argument("--observe", action="store_true", help="be a match observer, not a participant.") #localOption.add_argument("--replay" , default="" , help="reference a replay file as input.", metavar="FILE") localOption.add_argument( "--savereplay", default="", help= "store a replay as the name (and/or path) of the output replay file after the match finishes.", metavar="NAME") #localOption.add_argument("--simulate" , default="" , help="simulation setup files for the players to play", metavar="FILE_LIST") localOption.add_argument( "--windowed", action="store_true", help="launch client in windowed mode (default: full screen).") noLadderOpt = parser.add_argument_group( 'mandate a non-ladder (custom) match') noLadderOpt.add_argument( "--opponents", default="", help="specify specific opponent(s), comma separated.", metavar='LIST') noLadderOpt.add_argument("--nofog", action="store_true", help="disable fog of war.") noLadderOpt.add_argument("--map", default=None, help="play on a specific map.", metavar='MAPNAME') noLadderOpt.add_argument( "--step", default=0, type=int, help= "the number of steps between step() actions. A zero value means that the game runs in realtime (default)", metavar='INT') aiBotOption = parser.add_argument_group( "observation response contents for AI / bots") aiBotOption.add_argument("--raw", action="store_true", help="return raw data in observations") aiBotOption.add_argument("--feature", action="store_true", help="return feature data in observations.") aiBotOption.add_argument( "--rendered", action="store_true", help="return fully rendered data in observations.") aiBotOption.add_argument("--score", action="store_true", help="return current score data in observations.") aiBotOption.add_argument( "--resolution", default="", help="resolution that the feature/rendered data is returned in.", metavar='AxB') aiBotOption.add_argument( "--minimap", default="", help= "resolution that the feature/rendered minimap data is returned in.", metavar='AxB') aiBotOption.add_argument( "--layerwidth", type=int, default=24, help="the mapping of number of pixels to game grid coordinates.", metavar='INT') versionOpts = parser.add_argument_group('sc2 game client version handling') versionOpts.add_argument("--update", type=str, default="", help="update an existing version.", metavar='<label>,<version>,<base-version>') versionOpts.add_argument("--add", type=str, default="", help="add a new version.", metavar='<label>,<version>,<base-version>') versionOpts.add_argument("--versions", action="store_true", help="display known Starcraft 2 public versions.") return parser