# Path: pysc2/env/host_remote_agent.py
# class VsAgent(object):
# class VsBot(object):
#   def __init__(self):
#   def __enter__(self):
#   def __exit__(self, exception_type, exception_value, traceback):
#   def __del__(self):
#   def create_game(self, map_name):
#   def _disconnect(self):
#   def _reconnect(self, **kwargs):
#   def save_replay(self, replay_dir, replay_name):
#   def hosts(self):
#   def host_ports(self):
#   def lan_ports(self):
#   def close(self):
#   def __init__(self):
#   def __enter__(self):
#   def __exit__(self, exception_type, exception_value, traceback):
#   def __del__(self):
#   def create_game(
#       self,
#       map_name,
#       bot_difficulty=sc_pb.VeryEasy,
#       bot_race=sc_common.Random,
#       bot_first=False):
#   def _disconnect(self):
#   def _reconnect(self, **kwargs):
#   def save_replay(self, replay_dir, replay_name):
#   def host(self):
#   def host_port(self):
#   def close(self):
# 
# Path: pysc2/lib/remote_controller.py
# FLAGS = flags.FLAGS
# class ConnectError(Exception):
# class RequestError(Exception):
# class RemoteController(object):
#   def __init__(self, description, res):
# def check_error(res, error_enum):
# def decorate_check_error(error_enum):
#   def decorator(func):
#     def _check_error(*args, **kwargs):
# def skip_status(*skipped):
#   def decorator(func):
#     def _skip_status(self, *args, **kwargs):
# def valid_status(*valid):
#   def decorator(func):
#     def _valid_status(self, *args, **kwargs):
# def catch_game_end(func):
#   def _catch_game_end(self, *args, **kwargs):
#   def __init__(self, host, port, proc=None, timeout_seconds=None):
#   def _connect(self, host, port, proc, timeout_seconds):
#   def close(self):
#   def status_ended(self):
#   def create_game(self, req_create_game):
#   def save_map(self, map_path, map_data):
#   def join_game(self, req_join_game):
#   def restart(self):
#   def start_replay(self, req_start_replay):
#   def game_info(self):
#   def data_raw(self, ability_id=True, unit_type_id=True, upgrade_id=True,
#                buff_id=True, effect_id=True):
#   def data(self):
#   def observe(self, disable_fog=False, target_game_loop=0):
#   def available_maps(self):
#   def step(self, count=1):
#   def actions(self, req_action):
#   def act(self, action):
#   def observer_actions(self, req_observer_action):
#   def observer_act(self, action):
#   def chat(self, message, channel=sc_pb.ActionChat.Broadcast):
#   def leave(self):
#   def save_replay(self):
#   def debug(self, debug_commands):
#   def query(self, query):
#   def quit(self):
#   def ping(self):
#   def replay_info(self, replay_data):
#   def status(self):
# 
# Path: pysc2/lib/run_parallel.py
# class RunParallel(object):
#   def __init__(self, timeout=None):
#   def run(self, funcs):
#   def shutdown(self, wait=True):
#   def __del__(self):
# 
# Path: pysc2/tests/utils.py
# class TestCase(absltest.TestCase):
# class GameReplayTestCase(TestCase):
#   def setUp(self):
#   def tearDown(self):
# def get_units(obs, filter_fn=None, owner=None, unit_type=None, tag=None):
# def get_unit(*args, **kwargs):
# def xy_locs(mask):
# def only_in_game(func):
#   def decorator(self, *args, **kwargs):
#   def setup(**kwargs):
#     def decorator(func):  # pylint: disable=missing-docstring
#       def _setup(self):  # pylint: disable=missing-docstring
#         def test_in_game():
#         def test_in_replay():
#   def start_game(self, show_cloaked=True, disable_fog=False, players=2):
#   def start_replay(self):
#   def close(self):  # Instead of tearDown.
#   def step(self, count=4):
#   def observe(self, disable_fog=False):
#   def move_camera(self, x, y):
#   def raw_unit_command(self, player, ability_id, unit_tags, pos=None,
#                        target=None):
#   def debug(self, player=0, **kwargs):
#   def god(self):
#   def create_unit(self, unit_type, owner, pos, quantity=1):
#   def kill_unit(self, unit_tags):
#   def set_energy(self, tag, energy):
#   def assert_point(self, proto_pos, pos):
#   def assert_layers(self, layers, pos, **kwargs):
#   def assert_unit(self, unit, **kwargs):


from absl.testing import absltest
from pysc2.env import host_remote_agent
from pysc2.lib import remote_controller
from pysc2.lib import run_parallel
from pysc2.tests import utils
from s2clientprotocol import common_pb2 as sc_common
from s2clientprotocol import sc2api_pb2 as sc_pb
class TestHostRemoteAgent(utils.TestCase):

  def testVsBot(self):
    bot_first = True
    for _ in range(NUM_MATCHES):
      with host_remote_agent.VsBot() as game:
        game.create_game(
            map_name="Simple64",
            bot_difficulty=sc_pb.VeryHard,
            bot_first=bot_first)
        controller = remote_controller.RemoteController(
            host=game.host,
            port=game.host_port)

        join = sc_pb.RequestJoinGame(options=sc_pb.InterfaceOptions(raw=True))
        join.race = sc_common.Random
        controller.join_game(join)
        for _ in range(STEPS):
          controller.step()
          response_observation = controller.observe()
          if response_observation.player_result:
            break

        controller.leave()
        controller.close()
        bot_first = not bot_first

  def testVsAgent(self):
    parallel = run_parallel.RunParallel()
    for _ in range(NUM_MATCHES):

# Path: pysc2/env/host_remote_agent.py
# class VsAgent(object):
# class VsBot(object):
#   def __init__(self):
#   def __enter__(self):
#   def __exit__(self, exception_type, exception_value, traceback):
#   def __del__(self):
#   def create_game(self, map_name):
#   def _disconnect(self):
#   def _reconnect(self, **kwargs):
#   def save_replay(self, replay_dir, replay_name):
#   def hosts(self):
#   def host_ports(self):
#   def lan_ports(self):
#   def close(self):
#   def __init__(self):
#   def __enter__(self):
#   def __exit__(self, exception_type, exception_value, traceback):
#   def __del__(self):
#   def create_game(
#       self,
#       map_name,
#       bot_difficulty=sc_pb.VeryEasy,
#       bot_race=sc_common.Random,
#       bot_first=False):
#   def _disconnect(self):
#   def _reconnect(self, **kwargs):
#   def save_replay(self, replay_dir, replay_name):
#   def host(self):
#   def host_port(self):
#   def close(self):
# 
# Path: pysc2/lib/remote_controller.py
# FLAGS = flags.FLAGS
# class ConnectError(Exception):
# class RequestError(Exception):
# class RemoteController(object):
#   def __init__(self, description, res):
# def check_error(res, error_enum):
# def decorate_check_error(error_enum):
#   def decorator(func):
#     def _check_error(*args, **kwargs):
# def skip_status(*skipped):
#   def decorator(func):
#     def _skip_status(self, *args, **kwargs):
# def valid_status(*valid):
#   def decorator(func):
#     def _valid_status(self, *args, **kwargs):
# def catch_game_end(func):
#   def _catch_game_end(self, *args, **kwargs):
#   def __init__(self, host, port, proc=None, timeout_seconds=None):
#   def _connect(self, host, port, proc, timeout_seconds):
#   def close(self):
#   def status_ended(self):
#   def create_game(self, req_create_game):
#   def save_map(self, map_path, map_data):
#   def join_game(self, req_join_game):
#   def restart(self):
#   def start_replay(self, req_start_replay):
#   def game_info(self):
#   def data_raw(self, ability_id=True, unit_type_id=True, upgrade_id=True,
#                buff_id=True, effect_id=True):
#   def data(self):
#   def observe(self, disable_fog=False, target_game_loop=0):
#   def available_maps(self):
#   def step(self, count=1):
#   def actions(self, req_action):
#   def act(self, action):
#   def observer_actions(self, req_observer_action):
#   def observer_act(self, action):
#   def chat(self, message, channel=sc_pb.ActionChat.Broadcast):
#   def leave(self):
#   def save_replay(self):
#   def debug(self, debug_commands):
#   def query(self, query):
#   def quit(self):
#   def ping(self):
#   def replay_info(self, replay_data):
#   def status(self):
# 
# Path: pysc2/lib/run_parallel.py
# class RunParallel(object):
#   def __init__(self, timeout=None):
#   def run(self, funcs):
#   def shutdown(self, wait=True):
#   def __del__(self):
# 
# Path: pysc2/tests/utils.py
# class TestCase(absltest.TestCase):
# class GameReplayTestCase(TestCase):
#   def setUp(self):
#   def tearDown(self):
# def get_units(obs, filter_fn=None, owner=None, unit_type=None, tag=None):
# def get_unit(*args, **kwargs):
# def xy_locs(mask):
# def only_in_game(func):
#   def decorator(self, *args, **kwargs):
#   def setup(**kwargs):
#     def decorator(func):  # pylint: disable=missing-docstring
#       def _setup(self):  # pylint: disable=missing-docstring
#         def test_in_game():
#         def test_in_replay():
#   def start_game(self, show_cloaked=True, disable_fog=False, players=2):
#   def start_replay(self):
#   def close(self):  # Instead of tearDown.
#   def step(self, count=4):
#   def observe(self, disable_fog=False):
#   def move_camera(self, x, y):
#   def raw_unit_command(self, player, ability_id, unit_tags, pos=None,
#                        target=None):
#   def debug(self, player=0, **kwargs):
#   def god(self):
#   def create_unit(self, unit_type, owner, pos, quantity=1):
#   def kill_unit(self, unit_tags):
#   def set_energy(self, tag, energy):
#   def assert_point(self, proto_pos, pos):
#   def assert_layers(self, layers, pos, **kwargs):
#   def assert_unit(self, unit, **kwargs):


# Path: pysc2/tests/host_remote_agent_test.py
from absl.testing import absltest
from pysc2.env import host_remote_agent
from pysc2.lib import remote_controller
from pysc2.lib import run_parallel
from pysc2.tests import utils
from s2clientprotocol import common_pb2 as sc_common
from s2clientprotocol import sc2api_pb2 as sc_pb

class TestHostRemoteAgent(utils.TestCase):

  def testVsBot(self):
    bot_first = True
    for _ in range(NUM_MATCHES):
      with host_remote_agent.VsBot() as game:
        game.create_game(
            map_name="Simple64",
            bot_difficulty=sc_pb.VeryHard,
            bot_first=bot_first)
        controller = remote_controller.RemoteController(
            host=game.host,
            port=game.host_port)

        join = sc_pb.RequestJoinGame(options=sc_pb.InterfaceOptions(raw=True))
        join.race = sc_common.Random
        controller.join_game(join)
        for _ in range(STEPS):
          controller.step()
          response_observation = controller.observe()
          if response_observation.player_result:
            break

        controller.leave()
        controller.close()
        bot_first = not bot_first

  def testVsAgent(self):
    parallel = run_parallel.RunParallel()
    for _ in range(NUM_MATCHES):

      with host_remote_agent.VsAgent() as game: