# Path: pysc2/env/sc2_env.py
# class Race(enum.IntEnum):
# class Difficulty(enum.IntEnum):
# class BotBuild(enum.IntEnum):
# class Agent(collections.namedtuple("Agent", ["race", "name"])):
# class Bot(collections.namedtuple("Bot", ["race", "difficulty", "build"])):
# class SC2Env(environment.Base):
# def to_list(arg):
# def get_default(a, b):
#   def __new__(cls, race, name=None):
#   def __new__(cls, race, difficulty, build=None):
#   def __init__(self,  # pylint: disable=invalid-name
#                _only_use_kwargs=None,
#                map_name=None,
#                battle_net_map=False,
#                players=None,
#                agent_interface_format=None,
#                discount=1.,
#                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):
#   def _finalize(self, visualize):
#   def _get_interface(agent_interface_format, require_raw):
#   def _launch_game(self):
#   def _create_join(self):
#   def map_name(self):
#   def game_info(self):
#   def static_data(self):
#   def observation_spec(self):
#   def action_spec(self):
#   def action_delays(self):
#   def _restart(self):
#   def reset(self):
#   def step(self, actions, step_mul=None):
#   def _step(self, step_mul=None):
#   def _apply_action_delays(self, actions):
#   def _send_delayed_actions(self, up_to_game_loop, current_game_loop):
#   def _step_to(self, game_loop, current_game_loop):
#   def _get_observations(self, target_game_loop):
#     def parallel_observe(c, f):
#   def _observe(self, target_game_loop):
#     def zero_on_first_step(value):
#   def send_chat_messages(self, messages, broadcast=True):
#   def save_replay(self, replay_dir, prefix=None):
#   def close(self):
# def crop_and_deduplicate_names(names):
# REALTIME_GAME_LOOP_SECONDS = 1 / 22.4
# MAX_STEP_COUNT = 524000  # The game fails above 2^19=524288 steps.
# NUM_ACTION_DELAY_BUCKETS = 10


from absl.testing import absltest
from absl.testing import parameterized
from pysc2.env import sc2_env




class TestNameCroppingAndDeduplication(parameterized.TestCase):

  @parameterized.named_parameters(
      ("empty", [], []),
      ("single_no_crop", ["agent_1"], ["agent_1"]),
      ("single_cropped",
       ["very_long_agent_name_experimental_1"],
       ["very_long_agent_name_experimenta"]),
      ("no_dupes_no_crop",
       ["agent_1", "agent_2"],
       ["agent_1", "agent_2"]),
      ("no_dupes_cropped",
       ["a_very_long_agent_name_experimental",
        "b_very_long_agent_name_experimental"],
       ["a_very_long_agent_name_experimen",
        "b_very_long_agent_name_experimen"]),
      ("dupes_no_crop",
       ["agent_1", "agent_1"],
       ["(1) agent_1", "(2) agent_1"]),
      ("dupes_cropped",
       ["very_long_agent_name_experimental_c123",
        "very_long_agent_name_experimental_c456"],
       ["(1) very_long_agent_name_experim",
        "(2) very_long_agent_name_experim"]),
  )
  def test(self, names, expected_output):

# Path: pysc2/env/sc2_env.py
# class Race(enum.IntEnum):
# class Difficulty(enum.IntEnum):
# class BotBuild(enum.IntEnum):
# class Agent(collections.namedtuple("Agent", ["race", "name"])):
# class Bot(collections.namedtuple("Bot", ["race", "difficulty", "build"])):
# class SC2Env(environment.Base):
# def to_list(arg):
# def get_default(a, b):
#   def __new__(cls, race, name=None):
#   def __new__(cls, race, difficulty, build=None):
#   def __init__(self,  # pylint: disable=invalid-name
#                _only_use_kwargs=None,
#                map_name=None,
#                battle_net_map=False,
#                players=None,
#                agent_interface_format=None,
#                discount=1.,
#                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):
#   def _finalize(self, visualize):
#   def _get_interface(agent_interface_format, require_raw):
#   def _launch_game(self):
#   def _create_join(self):
#   def map_name(self):
#   def game_info(self):
#   def static_data(self):
#   def observation_spec(self):
#   def action_spec(self):
#   def action_delays(self):
#   def _restart(self):
#   def reset(self):
#   def step(self, actions, step_mul=None):
#   def _step(self, step_mul=None):
#   def _apply_action_delays(self, actions):
#   def _send_delayed_actions(self, up_to_game_loop, current_game_loop):
#   def _step_to(self, game_loop, current_game_loop):
#   def _get_observations(self, target_game_loop):
#     def parallel_observe(c, f):
#   def _observe(self, target_game_loop):
#     def zero_on_first_step(value):
#   def send_chat_messages(self, messages, broadcast=True):
#   def save_replay(self, replay_dir, prefix=None):
#   def close(self):
# def crop_and_deduplicate_names(names):
# REALTIME_GAME_LOOP_SECONDS = 1 / 22.4
# MAX_STEP_COUNT = 524000  # The game fails above 2^19=524288 steps.
# NUM_ACTION_DELAY_BUCKETS = 10


# Path: pysc2/env/sc2_env_test.py
from absl.testing import absltest
from absl.testing import parameterized
from pysc2.env import sc2_env





class TestNameCroppingAndDeduplication(parameterized.TestCase):

  @parameterized.named_parameters(
      ("empty", [], []),
      ("single_no_crop", ["agent_1"], ["agent_1"]),
      ("single_cropped",
       ["very_long_agent_name_experimental_1"],
       ["very_long_agent_name_experimenta"]),
      ("no_dupes_no_crop",
       ["agent_1", "agent_2"],
       ["agent_1", "agent_2"]),
      ("no_dupes_cropped",
       ["a_very_long_agent_name_experimental",
        "b_very_long_agent_name_experimental"],
       ["a_very_long_agent_name_experimen",
        "b_very_long_agent_name_experimen"]),
      ("dupes_no_crop",
       ["agent_1", "agent_1"],
       ["(1) agent_1", "(2) agent_1"]),
      ("dupes_cropped",
       ["very_long_agent_name_experimental_c123",
        "very_long_agent_name_experimental_c456"],
       ["(1) very_long_agent_name_experim",
        "(2) very_long_agent_name_experim"]),
  )
  def test(self, names, expected_output):

    self.assertEqual(sc2_env.crop_and_deduplicate_names(names), expected_output)