# Path: meltingpot/python/utils/substrates/builder.py
# def builder(
#     lab2d_settings: Settings,
#     prefab_overrides: Optional[Settings] = None,
#     env_seed: Optional[int] = None,
#     **settings) -> dmlab2d.Environment:
#   """Builds a Melting Pot environment.
# 
#   Args:
#     lab2d_settings: a dict of environment designation args.
#     prefab_overrides: overrides for prefabs.
#     env_seed: the seed to pass to the environment.
#     **settings: Other settings which are not used by Melting Pot but can still
#       be passed from the environment builder.
# 
#   Returns:
#     A multi-player Melting Pot environment.
#   """
#   del settings  #  Not currently used by DMLab2D.
# 
#   assert "simulation" in lab2d_settings
# 
#   # Copy config, so as not to modify it.
#   lab2d_settings = config_dict.ConfigDict(
#       copy.deepcopy(lab2d_settings)).unlock()
# 
#   apply_prefab_overrides(lab2d_settings, prefab_overrides)
#   maybe_build_and_add_avatar_objects(lab2d_settings)
#   locate_and_overwrite_level_directory(lab2d_settings)
# 
#   # Convert settings from python to Lua format.
#   lab2d_settings_dict = parse_python_settings_for_dmlab2d(lab2d_settings)
# 
#   if env_seed is None:
#     # Select a long seed different than zero.
#     env_seed = random.randint(1, _MAX_SEED)
#   env_seeds = (seed % (_MAX_SEED + 1) for seed in itertools.count(env_seed))
# 
#   def build_environment():
#     seed = next(env_seeds)
#     lab2d_settings_dict["env_seed"] = str(seed)  # Sets the Lua seed.
#     env_raw = dmlab2d.Lab2d(_DMLAB2D_ROOT, lab2d_settings_dict)
#     observation_names = env_raw.observation_names()
#     return dmlab2d.Environment(
#         env=env_raw,
#         observation_names=observation_names,
#         seed=seed)
# 
#   # Add a wrapper that rebuilds the environment when reset is called.
#   env = reset_wrapper.ResetWrapper(build_environment)
# 
#   return env


import collections
import enum
import dm_env
import numpy as np
import pygame
import dmlab2d
from typing import Any, Callable, Dict, Mapping, Optional, Sequence, Tuple
from ml_collections import config_dict
from meltingpot.python.utils.substrates import builder
    assert isinstance(self._action_spec, dict)
    self._action_names = set()
    for action_key in self._action_spec.keys():
      _, action_name = _split_key(action_key)
      self._action_names.add(action_name)

  def step(self, player_index: int) -> Sequence[Sequence[Mapping[str, int]]]:
    """Update the actions of player `player_index`."""
    actions = {action_key: 0 for action_key in self._action_spec.keys()}
    for action_name in self._action_names:
      actions[f'{player_index + 1}.{action_name}'] = self._action_map[
          action_name]()
    return actions


def run_episode(
    render_observation: str,
    config_overrides: Dict[str, Any],
    action_map: ActionMap,
    full_config: config_dict.ConfigDict,
    interactive: RenderType = RenderType.PYGAME,
    screen_width: int = 800,
    screen_height: int = 600,
    fps: int = 8,
    verbose_fn: Optional[Callable[[dm_env.TimeStep, int], None]] = None,
    text_display_fn: Optional[Callable[[dm_env.TimeStep, int], str]] = None,
    text_font_size: int = 36,
    text_x_pos: int = 20,
    text_y_pos: int = 20,
    text_color: Tuple[int, ...] = WHITE,

# Path: meltingpot/python/utils/substrates/builder.py
# def builder(
#     lab2d_settings: Settings,
#     prefab_overrides: Optional[Settings] = None,
#     env_seed: Optional[int] = None,
#     **settings) -> dmlab2d.Environment:
#   """Builds a Melting Pot environment.
# 
#   Args:
#     lab2d_settings: a dict of environment designation args.
#     prefab_overrides: overrides for prefabs.
#     env_seed: the seed to pass to the environment.
#     **settings: Other settings which are not used by Melting Pot but can still
#       be passed from the environment builder.
# 
#   Returns:
#     A multi-player Melting Pot environment.
#   """
#   del settings  #  Not currently used by DMLab2D.
# 
#   assert "simulation" in lab2d_settings
# 
#   # Copy config, so as not to modify it.
#   lab2d_settings = config_dict.ConfigDict(
#       copy.deepcopy(lab2d_settings)).unlock()
# 
#   apply_prefab_overrides(lab2d_settings, prefab_overrides)
#   maybe_build_and_add_avatar_objects(lab2d_settings)
#   locate_and_overwrite_level_directory(lab2d_settings)
# 
#   # Convert settings from python to Lua format.
#   lab2d_settings_dict = parse_python_settings_for_dmlab2d(lab2d_settings)
# 
#   if env_seed is None:
#     # Select a long seed different than zero.
#     env_seed = random.randint(1, _MAX_SEED)
#   env_seeds = (seed % (_MAX_SEED + 1) for seed in itertools.count(env_seed))
# 
#   def build_environment():
#     seed = next(env_seeds)
#     lab2d_settings_dict["env_seed"] = str(seed)  # Sets the Lua seed.
#     env_raw = dmlab2d.Lab2d(_DMLAB2D_ROOT, lab2d_settings_dict)
#     observation_names = env_raw.observation_names()
#     return dmlab2d.Environment(
#         env=env_raw,
#         observation_names=observation_names,
#         seed=seed)
# 
#   # Add a wrapper that rebuilds the environment when reset is called.
#   env = reset_wrapper.ResetWrapper(build_environment)
# 
#   return env


# Path: meltingpot/python/human_players/level_playing_utils.py
import collections
import enum
import dm_env
import numpy as np
import pygame
import dmlab2d
from typing import Any, Callable, Dict, Mapping, Optional, Sequence, Tuple
from ml_collections import config_dict
from meltingpot.python.utils.substrates import builder

    assert isinstance(self._action_spec, dict)
    self._action_names = set()
    for action_key in self._action_spec.keys():
      _, action_name = _split_key(action_key)
      self._action_names.add(action_name)

  def step(self, player_index: int) -> Sequence[Sequence[Mapping[str, int]]]:
    """Update the actions of player `player_index`."""
    actions = {action_key: 0 for action_key in self._action_spec.keys()}
    for action_name in self._action_names:
      actions[f'{player_index + 1}.{action_name}'] = self._action_map[
          action_name]()
    return actions


def run_episode(
    render_observation: str,
    config_overrides: Dict[str, Any],
    action_map: ActionMap,
    full_config: config_dict.ConfigDict,
    interactive: RenderType = RenderType.PYGAME,
    screen_width: int = 800,
    screen_height: int = 600,
    fps: int = 8,
    verbose_fn: Optional[Callable[[dm_env.TimeStep, int], None]] = None,
    text_display_fn: Optional[Callable[[dm_env.TimeStep, int], str]] = None,
    text_font_size: int = 36,
    text_x_pos: int = 20,
    text_y_pos: int = 20,
    text_color: Tuple[int, ...] = WHITE,

    env_builder: EnvBuilder = builder.builder,