code: def main(unused_argv):
      """Run SC2 to play a game or a replay."""
      if FLAGS.trace:
          stopwatch.sw.trace()
      elif FLAGS.profile:
          stopwatch.sw.enable()
  
      if (FLAGS.map and FLAGS.replay) or (
          not FLAGS.map and not FLAGS.replay
      ):
          sys.exit("Must supply either a map or replay.")
  
      if FLAGS.replay and not FLAGS.replay.lower().endswith(
          "sc2replay"
      ):
          sys.exit("Replay must end in .SC2Replay.")
  
      if FLAGS.realtime and FLAGS.replay:
          # TODO(tewalds): Support realtime in replays once the game supports it.
          sys.exit("realtime isn't possible for replays yet.")
  
      if FLAGS.render and (FLAGS.realtime or FLAGS.full_screen):
          sys.exit(
              "disable pygame rendering if you want realtime or full_screen."
          )
  
      if platform.system() == "Linux" and (
          FLAGS.realtime or FLAGS.full_screen
      ):
          sys.exit(
              "realtime and full_screen only make sense on Windows/MacOS."
          )
  
      if not FLAGS.render and FLAGS.render_sync:
          sys.exit(
              "render_sync only makes sense with pygame rendering on."
          )
  
      run_config = run_configs.get()
  
      interface = sc_pb.InterfaceOptions()
      interface.raw = FLAGS.render
      interface.raw_affects_selection = True
      interface.raw_crop_to_playable_area = True
      interface.score = True
      interface.show_cloaked = True
      interface.show_burrowed_shadows = True
      interface.show_placeholders = True
      if FLAGS.feature_screen_size and FLAGS.feature_minimap_size:
          interface.feature_layer.width = FLAGS.feature_camera_width
          FLAGS.feature_screen_size.assign_to(
              interface.feature_layer.resolution
          )
          FLAGS.feature_minimap_size.assign_to(
              interface.feature_layer.minimap_resolution
          )
          interface.feature_layer.crop_to_playable_area = True
          interface.feature_layer.allow_cheating_layers = True
      if (
          FLAGS.render
          and FLAGS.rgb_screen_size
          and FLAGS.rgb_minimap_size
      ):
          FLAGS.rgb_screen_size.assign_to(interface.render.resolution)
          FLAGS.rgb_minimap_size.assign_to(
              interface.render.minimap_resolution
          )
  
      max_episode_steps = FLAGS.max_episode_steps
  
      if FLAGS.map:
          create = sc_pb.RequestCreateGame(
              realtime=FLAGS.realtime, disable_fog=FLAGS.disable_fog
          )
          try:
              map_inst = maps.get(FLAGS.map)
          except maps.lib.NoMapError:
              if FLAGS.battle_net_map:
                  create.battlenet_map_name = FLAGS.map
              else:
                  raise
          else:
              if map_inst.game_steps_per_episode:
                  max_episode_steps = map_inst.game_steps_per_episode
              if FLAGS.battle_net_map:
                  create.battlenet_map_name = map_inst.battle_net
              else:
                  create.local_map.map_path = map_inst.path
                  create.local_map.map_data = map_inst.data(run_config)
  
          create.player_setup.add(type=sc_pb.Participant)
          create.player_setup.add(
              type=sc_pb.Computer,
              race=sc2_env.Race[FLAGS.bot_race],
              difficulty=sc2_env.Difficulty[FLAGS.difficulty],
              ai_build=sc2_env.BotBuild[FLAGS.bot_build],
          )
          join = sc_pb.RequestJoinGame(
              options=interface,
              race=sc2_env.Race[FLAGS.user_race],
              player_name=FLAGS.user_name,
          )
          version = None
      else:
          replay_data = run_config.replay_data(FLAGS.replay)
          start_replay = sc_pb.RequestStartReplay(
              replay_data=replay_data,
              options=interface,
              disable_fog=FLAGS.disable_fog,
              observed_player_id=FLAGS.observed_player,
          )
          version = replay.get_replay_version(replay_data)
          run_config = run_configs.get(
              version=version
          )  # Replace the run config.
  
      with run_config.start(
          full_screen=FLAGS.full_screen,
          window_size=FLAGS.window_size,
          want_rgb=interface.HasField("render"),
      ) as controller:
          if FLAGS.map:
              controller.create_game(create)
              controller.join_game(join)
          else:
              info = controller.replay_info(replay_data)
              print(" Replay info ".center(60, "-"))
              print(info)
              print("-" * 60)
              map_path = FLAGS.map_path or info.local_map_path
              if map_path:
                  start_replay.map_data = run_config.map_data(
                      map_path, len(info.player_info)
                  )
              controller.start_replay(start_replay)
  
          if FLAGS.render:
              renderer = renderer_human.RendererHuman(
                  fps=FLAGS.fps,
                  step_mul=FLAGS.step_mul,
                  render_sync=FLAGS.render_sync,
                  video=FLAGS.video,
              )
              renderer.run(
                  run_config,
                  controller,
                  max_game_steps=FLAGS.max_game_steps,
                  game_steps_per_episode=max_episode_steps,
                  save_replay=FLAGS.save_replay,
              )
          else:  # Still step forward so the Mac/Windows renderer works.
              try:
                  while True:
                      frame_start_time = time.time()
                      if not FLAGS.realtime:
                          controller.step(FLAGS.step_mul)
                      obs = controller.observe()
  
                      if obs.player_result:
                          break
                      time.sleep(
                          max(
                              0,
                              frame_start_time
                              + 1 / FLAGS.fps
                              - time.time(),
                          )
                      )
              except KeyboardInterrupt:
                  pass
              print("Score: ", obs.observation.score.score)
              print("Result: ", obs.player_result)
              if FLAGS.map and FLAGS.save_replay:
                  replay_save_loc = run_config.save_replay(
                      controller.save_replay(), "local", FLAGS.map
                  )
                  print("Replay saved to:", replay_save_loc)
                  # Save scores so we know how the human player did.
                  with open(
                      replay_save_loc.replace("SC2Replay", "txt"), "w"
                  ) as f:
                      f.write(
                          "{}\n".format(obs.observation.score.score)
                      )
  
      if FLAGS.profile:
          print(stopwatch.sw)
  
file_path: pysc2/pysc2/bin/play.py
imports: import getpass
  import platform
  import sys
  import time
  from absl import app
  from absl import flags
  from pysc2 import maps
  from pysc2 import run_configs
  from pysc2.env import sc2_env
  from pysc2.lib import point_flag
  from pysc2.lib import renderer_human
  from pysc2.lib import replay
  from pysc2.lib import stopwatch
  from s2clientprotocol import sc2api_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: main(unused_argv) without return types