class_docstr: A Starcraft II environment for playing vs humans over LAN.
  
  This owns a single instance, and expects to join a game hosted by some other
  script, likely play_vs_agent.py.
docstr: Create a SC2 Env that connects to a remote instance of the game.
  
  This assumes that the game is already up and running, and it only needs to
  join. You need some other script to launch the process and call
  RequestCreateGame. It also assumes that it's a multiplayer game, and that
  the ports are consecutive.
  
  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:
    host: Which ip to use. Either ipv4 or ipv6 localhost.
    config_port: Where to find the config port.
    race: Race for this agent.
    name: The name of this agent, for saving in the replay.
    agent_interface_format: AgentInterfaceFormat object describing the
        format of communication between the agent and the environment, else
        just InterfaceOptions to use passthrough.
    discount: Returned as part of the observation.
    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.
    replay_dir: Directory to save a replay.
    replay_prefix: An optional prefix to use when saving replays.
  
  Raises:
    ValueError: if the race is invalid.
    ValueError: if the resolutions aren't specified correctly.
    ValueError: if the host or port are invalid.
code: def __init__(
      self,
      *,
      host="127.0.0.1",
      config_port=None,
      race=None,
      name="<unknown>",
      agent_interface_format=None,
      discount=1.0,
      visualize=False,
      step_mul=None,
      realtime=False,
      replay_dir=None,
      replay_prefix=None,
  ):
      """Create a SC2 Env that connects to a remote instance of the game.
  
      This assumes that the game is already up and running, and it only needs to
      join. You need some other script to launch the process and call
      RequestCreateGame. It also assumes that it's a multiplayer game, and that
      the ports are consecutive.
  
      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:
        host: Which ip to use. Either ipv4 or ipv6 localhost.
        config_port: Where to find the config port.
        race: Race for this agent.
        name: The name of this agent, for saving in the replay.
        agent_interface_format: AgentInterfaceFormat object describing the
            format of communication between the agent and the environment, else
            just InterfaceOptions to use passthrough.
        discount: Returned as part of the observation.
        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.
        replay_dir: Directory to save a replay.
        replay_prefix: An optional prefix to use when saving replays.
  
      Raises:
        ValueError: if the race is invalid.
        ValueError: if the resolutions aren't specified correctly.
        ValueError: if the host or port are invalid.
      """
      if host not in ("127.0.0.1", "::1"):
          raise ValueError("Bad host arguments. Must be a localhost")
      if not config_port:
          raise ValueError("Must pass a config_port.")
  
      if agent_interface_format is None:
          raise ValueError("Please specify agent_interface_format.")
  
      if not race:
          race = sc2_env.Race.random
  
      self._num_agents = 1
      self._discount = discount
      self._step_mul = step_mul or 8
      self._realtime = realtime
      self._last_step_time = None
      self._save_replay_episodes = 1 if replay_dir else 0
      self._replay_dir = replay_dir
      self._replay_prefix = replay_prefix
  
      self._score_index = -1  # Win/loss only.
      self._score_multiplier = 1
      self._episode_length = sc2_env.MAX_STEP_COUNT
      self._ensure_available_actions = False
      self._discount_zero_after_timeout = False
      self._parallel = (
          run_parallel.RunParallel()
      )  # Needed for multiplayer.
      self._game_info = None
      self._action_delay_fns = [None]
  
      interface = self._get_interface(
          agent_interface_format=agent_interface_format,
          require_raw=visualize,
      )
  
      self._launch_remote(
          host,
          config_port,
          race,
          name,
          interface,
          agent_interface_format,
      )
  
      self._finalize(visualize)
  
imports: import binascii
  import collections
  import hashlib
  import json
  import os
  import shutil
  import socket
  import struct
  import subprocess
  import threading
  import time
  from absl import logging
  from pysc2 import run_configs
  from pysc2.env import sc2_env
  from pysc2.lib import features
  from pysc2.lib import run_parallel
  from s2clientprotocol import sc2api_pb2
label_desc: Use image node_id 1 to create a new LanSC2Env object from inherited base classes: sc2_env with example: obj = LanSC2Env()