class_docstr: A Starcraft II environment.
  
  The implementation details of the action and observation specs are in
  lib/features.py
docstr: Create a SC2 Env.
  
  You must pass a resolution that you want to play at. You can send either
  feature layer resolution or rgb resolution or both. If you send both you
  must also choose which to use as your action space. Regardless of which you
  choose you must send both the screen and minimap resolutions.
  
  For each of the 4 resolutions, either specify size or both width and
  height. If you specify size then both width and height will take that value.
  
  Args:
    map_name: Name of a SC2 map. Run bin/map_list to get the full list of
        known maps. Alternatively, pass a Map instance. Take a look at the
        docs in maps/README.md for more information on available maps. Can
        also be a list of map names or instances, in which case one will be
        chosen at random per episode.
    battle_net_map: Whether to use the battle.net versions of the map(s).
    players: A list of Agent and Bot instances that specify who will play.
    agent_interface_format: A sequence containing one AgentInterfaceFormat per
        agent, matching the order of agents specified in the players list. Or
        a single AgentInterfaceFormat to be used for all agents. Note that
        InterfaceOptions may be supplied in place of AgentInterfaceFormat, in
        which case no action or observation processing will be carried out by
        PySC2. The sc_pb.ResponseObservation proto will be returned as the
        observation for the agent and passed actions must be instances of
        sc_pb.Action. This is intended for agents which use custom environment
        conversion code.
    discount: Returned as part of the observation.
    discount_zero_after_timeout: If True, the discount will be zero
        after the `game_steps_per_episode` timeout.
    visualize: Whether to pop up a window showing the camera and feature
        layers. This won't work without access to a window manager.
    step_mul: How many game steps per agent step (action/observation). None
        means use the map default.
    realtime: Whether to use realtime mode. In this mode the game simulation
        automatically advances (at 22.4 gameloops per second) rather than
        being stepped manually. The number of game loops advanced with each
        call to step() won't necessarily match the step_mul specified. The
        environment will attempt to honour step_mul, returning observations
        with that spacing as closely as possible. Game loops will be skipped
        if they cannot be retrieved and processed quickly enough.
    save_replay_episodes: Save a replay after this many episodes. Default of 0
        means don't save replays.
    replay_dir: Directory to save replays. Required with save_replay_episodes.
    replay_prefix: An optional prefix to use when saving replays.
    game_steps_per_episode: Game steps per episode, independent of the
        step_mul. 0 means no limit. None means use the map default.
    score_index: -1 means use the win/loss reward, >=0 is the index into the
        score_cumulative with 0 being the curriculum score. None means use
        the map default.
    score_multiplier: How much to multiply the score by. Useful for negating.
    random_seed: Random number seed to use when initializing the game. This
        lets you run repeatable games/tests.
    disable_fog: Whether to disable fog of war.
    ensure_available_actions: Whether to throw an exception when an
        unavailable action is passed to step().
    version: The version of SC2 to use, defaults to the latest.
  
  Raises:
    ValueError: if no map is specified.
    ValueError: if wrong number of players are requested for a map.
    ValueError: if the resolutions aren't specified correctly.
docstr_tok: ["Create","a","SC2","Env",".","You","must","pass","a","resolution","that","you","want","to","play","at",".","You","can","send","either","feature","layer","resolution","or","rgb","resolution","or","both",".","If","you","send","both","you","must","also","choose","which","to","use","as","your","action","space",".","Regardless","of","which","you","choose","you","must","send","both","the","screen","and","minimap","resolutions",".","For","each","of","the","4","resolutions",",","either","specify","size","or","both","width","and","height",".","If","you","specify","size","then","both","width","and","height","will","take","that","value",".","Args",":","map_name",":","Name","of","a","SC2","map",".","Run","bin\/map_list","to","get","the","full","list","of","known","maps",".","Alternatively",",","pass","a","Map","instance",".","Take","a","look","at","the","docs","in","maps\/README.md","for","more","information","on","available","maps",".","Can","also","be","a","list","of","map","names","or","instances",",","in","which","case","one","will","be","chosen","at","random","per","episode",".","battle_net_map",":","Whether","to","use","the","battle.net","versions","of","the","map","(","s",")",".","players",":","A","list","of","Agent","and","Bot","instances","that","specify","who","will","play",".","agent_interface_format",":","A","sequence","containing","one","AgentInterfaceFormat","per","agent",",","matching","the","order","of","agents","specified","in","the","players","list",".","Or","a","single","AgentInterfaceFormat","to","be","used","for","all","agents",".","Note","that","InterfaceOptions","may","be","supplied","in","place","of","AgentInterfaceFormat",",","in","which","case","no","action","or","observation","processing","will","be","carried","out","by","PySC2",".","The","sc_pb.ResponseObservation","proto","will","be","returned","as","the","observation","for","the","agent","and","passed","actions","must","be","instances","of","sc_pb.Action",".","This","is","intended","for","agents","which","use","custom","environment","conversion","code",".","discount",":","Returned","as","part","of","the","observation",".","discount_zero_after_timeout",":","If","True",",","the","discount","will","be","zero","after","the","`","game_steps_per_episode","`","timeout",".","visualize",":","Whether","to","pop","up","a","window","showing","the","camera","and","feature","layers",".","This","wo","n't","work","without","access","to","a","window","manager",".","step_mul",":","How","many","game","steps","per","agent","step","(","action\/observation",")",".","None","means","use","the","map","default",".","realtime",":","Whether","to","use","realtime","mode",".","In","this","mode","the","game","simulation","automatically","advances","(","at","22.4","gameloops","per","second",")","rather","than","being","stepped","manually",".","The","number","of","game","loops","advanced","with","each","call","to","step","(",")","wo","n't","necessarily","match","the","step_mul","specified",".","The","environment","will","attempt","to","honour","step_mul",",","returning","observations","with","that","spacing","as","closely","as","possible",".","Game","loops","will","be","skipped","if","they","can","not","be","retrieved","and","processed","quickly","enough",".","save_replay_episodes",":","Save","a","replay","after","this","many","episodes",".","Default","of","0","means","do","n't","save","replays",".","replay_dir",":","Directory","to","save","replays",".","Required","with","save_replay_episodes",".","replay_prefix",":","An","optional","prefix","to","use","when","saving","replays",".","game_steps_per_episode",":","Game","steps","per","episode",",","independent","of","the","step_mul",".","0","means","no","limit",".","None","means","use","the","map","default",".","score_index",":","-1","means","use","the","win\/loss","reward",",",">","=0","is","the","index","into","the","score_cumulative","with","0","being","the","curriculum","score",".","None","means","use","the","map","default",".","score_multiplier",":","How","much","to","multiply","the","score","by",".","Useful","for","negating",".","random_seed",":","Random","number","seed","to","use","when","initializing","the","game",".","This","lets","you","run","repeatable","games\/tests",".","disable_fog",":","Whether","to","disable","fog","of","war",".","ensure_available_actions",":","Whether","to","throw","an","exception","when","an","unavailable","action","is","passed","to","step","(",")",".","version",":","The","version","of","SC2","to","use",",","defaults","to","the","latest",".","Raises",":","ValueError",":","if","no","map","is","specified",".","ValueError",":","if","wrong","number","of","players","are","requested","for","a","map",".","ValueError",":","if","the","resolutions","are","n't","specified","correctly","."]
code: def __init__(
      self,
      *,
      map_name=None,
      battle_net_map=False,
      players=None,
      agent_interface_format=None,
      discount=1.0,
      discount_zero_after_timeout=False,
      visualize=False,
      step_mul=None,
      realtime=False,
      save_replay_episodes=0,
      replay_dir=None,
      replay_prefix=None,
      game_steps_per_episode=None,
      score_index=None,
      score_multiplier=None,
      random_seed=None,
      disable_fog=False,
      ensure_available_actions=True,
      version=None,
  ):
      """Create a SC2 Env.
  
      You must pass a resolution that you want to play at. You can send either
      feature layer resolution or rgb resolution or both. If you send both you
      must also choose which to use as your action space. Regardless of which you
      choose you must send both the screen and minimap resolutions.
  
      For each of the 4 resolutions, either specify size or both width and
      height. If you specify size then both width and height will take that value.
  
      Args:
        map_name: Name of a SC2 map. Run bin/map_list to get the full list of
            known maps. Alternatively, pass a Map instance. Take a look at the
            docs in maps/README.md for more information on available maps. Can
            also be a list of map names or instances, in which case one will be
            chosen at random per episode.
        battle_net_map: Whether to use the battle.net versions of the map(s).
        players: A list of Agent and Bot instances that specify who will play.
        agent_interface_format: A sequence containing one AgentInterfaceFormat per
            agent, matching the order of agents specified in the players list. Or
            a single AgentInterfaceFormat to be used for all agents. Note that
            InterfaceOptions may be supplied in place of AgentInterfaceFormat, in
            which case no action or observation processing will be carried out by
            PySC2. The sc_pb.ResponseObservation proto will be returned as the
            observation for the agent and passed actions must be instances of
            sc_pb.Action. This is intended for agents which use custom environment
            conversion code.
        discount: Returned as part of the observation.
        discount_zero_after_timeout: If True, the discount will be zero
            after the `game_steps_per_episode` timeout.
        visualize: Whether to pop up a window showing the camera and feature
            layers. This won't work without access to a window manager.
        step_mul: How many game steps per agent step (action/observation). None
            means use the map default.
        realtime: Whether to use realtime mode. In this mode the game simulation
            automatically advances (at 22.4 gameloops per second) rather than
            being stepped manually. The number of game loops advanced with each
            call to step() won't necessarily match the step_mul specified. The
            environment will attempt to honour step_mul, returning observations
            with that spacing as closely as possible. Game loops will be skipped
            if they cannot be retrieved and processed quickly enough.
        save_replay_episodes: Save a replay after this many episodes. Default of 0
            means don't save replays.
        replay_dir: Directory to save replays. Required with save_replay_episodes.
        replay_prefix: An optional prefix to use when saving replays.
        game_steps_per_episode: Game steps per episode, independent of the
            step_mul. 0 means no limit. None means use the map default.
        score_index: -1 means use the win/loss reward, >=0 is the index into the
            score_cumulative with 0 being the curriculum score. None means use
            the map default.
        score_multiplier: How much to multiply the score by. Useful for negating.
        random_seed: Random number seed to use when initializing the game. This
            lets you run repeatable games/tests.
        disable_fog: Whether to disable fog of war.
        ensure_available_actions: Whether to throw an exception when an
            unavailable action is passed to step().
        version: The version of SC2 to use, defaults to the latest.
  
      Raises:
        ValueError: if no map is specified.
        ValueError: if wrong number of players are requested for a map.
        ValueError: if the resolutions aren't specified correctly.
      """
      if not players:
          raise ValueError("You must specify the list of players.")
  
      for p in players:
          if not isinstance(p, (Agent, Bot)):
              raise ValueError(
                  "Expected players to be of type Agent or Bot. Got: %s."
                  % p
              )
  
      num_players = len(players)
      self._num_agents = sum(1 for p in players if isinstance(p, Agent))
      self._players = players
  
      if not 1 <= num_players <= 2 or not self._num_agents:
          raise ValueError(
              "Only 1 or 2 players with at least one agent is "
              "supported at the moment."
          )
  
      if not map_name:
          raise ValueError("Missing a map name.")
  
      self._battle_net_map = battle_net_map
      self._maps = [maps.get(name) for name in to_list(map_name)]
      min_players = min(m.players for m in self._maps)
      max_players = max(m.players for m in self._maps)
      if self._battle_net_map:
          for m in self._maps:
              if not m.battle_net:
                  raise ValueError(
                      "%s isn't known on Battle.net" % m.name
                  )
  
      if max_players == 1:
          if self._num_agents != 1:
              raise ValueError(
                  "Single player maps require exactly one Agent."
              )
      elif not 2 <= num_players <= min_players:
          raise ValueError(
              "Maps support 2 - %s players, but trying to join with %s"
              % (min_players, num_players)
          )
  
      if save_replay_episodes and not replay_dir:
          raise ValueError("Missing replay_dir")
  
      self._realtime = realtime
      self._last_step_time = None
      self._save_replay_episodes = save_replay_episodes
      self._replay_dir = replay_dir
      self._replay_prefix = replay_prefix
      self._random_seed = random_seed
      self._disable_fog = disable_fog
      self._ensure_available_actions = ensure_available_actions
      self._discount = discount
      self._discount_zero_after_timeout = discount_zero_after_timeout
      self._default_step_mul = step_mul
      self._default_score_index = score_index
      self._default_score_multiplier = score_multiplier
      self._default_episode_length = game_steps_per_episode
  
      self._run_config = run_configs.get(version=version)
      self._parallel = (
          run_parallel.RunParallel()
      )  # Needed for multiplayer.
      self._game_info = None
      self._requested_races = None
  
      if agent_interface_format is None:
          raise ValueError("Please specify agent_interface_format.")
  
      if isinstance(
          agent_interface_format,
          (AgentInterfaceFormat, sc_pb.InterfaceOptions),
      ):
          agent_interface_format = [
              agent_interface_format
          ] * self._num_agents
  
      if len(agent_interface_format) != self._num_agents:
          raise ValueError(
              "The number of entries in agent_interface_format should "
              "correspond 1-1 with the number of agents."
          )
  
      self._action_delay_fns = [
          aif.action_delay_fn
          if isinstance(aif, AgentInterfaceFormat)
          else None
          for aif in agent_interface_format
      ]
      self._interface_formats = agent_interface_format
      self._interface_options = [
          self._get_interface(
              interface_format, require_raw=visualize and i == 0
          )
          for i, interface_format in enumerate(agent_interface_format)
      ]
  
      self._launch_game()
      self._create_join()
  
      self._finalize(visualize)
  
imports: import collections
  import copy
  import random
  import time
  from absl import logging
  from pysc2 import maps
  from pysc2 import run_configs
  from pysc2.env import enums
  from pysc2.env import environment
  from pysc2.lib import actions
  from pysc2.lib import features
  from pysc2.lib import metrics
  from pysc2.lib import portspicker
  from pysc2.lib import renderer_human
  from pysc2.lib import run_parallel
  from pysc2.lib import stopwatch
  from s2clientprotocol import sc2api_pb2
label_desc: Use image node_id 1 to create a new SC2Env object from inherited base classes: environment with example: obj = SC2Env()