def agent(): """Run the agent, connecting to a (remote) host started independently.""" agent_module, agent_name = FLAGS.agent.rsplit(".", 1) agent_cls = getattr(importlib.import_module(agent_module), agent_name) logging.info("Starting agent:") with lan_sc2_env.LanSC2Env( host=FLAGS.host, config_port=FLAGS.config_port, race=sc2_env.Race[FLAGS.agent_race], step_mul=FLAGS.step_mul, agent_interface_format=sc2_env.parse_agent_interface_format( feature_screen=FLAGS.feature_screen_size, feature_minimap=FLAGS.feature_minimap_size, rgb_screen=FLAGS.rgb_screen_size, rgb_minimap=FLAGS.rgb_minimap_size, action_space=FLAGS.action_space, use_feature_units=FLAGS.use_feature_units, use_raw_units=FLAGS.use_raw_units), visualize=FLAGS.render) as env: agents = [agent_cls(env)] logging.info("Connected, starting run_loop.") try: run_loop.run_loop(agents, env) except lan_sc2_env.RestartException: pass logging.info("Done.")
def agent(Config config): """Run the agent, connecting to a (remote) host started independently.""" agent_module, agent_name = FLAGS.agent.rsplit(".", 1) agent_cls = getattr(importlib.import_module(agent_module), agent_name) logging.info("Starting agent:") with lan_sc2_env.LanSC2Env( host=FLAGS.host, config_port=FLAGS.config_port, race=sc2_env.Race[FLAGS.agent_race], step_mul=FLAGS.step_mul, agent_interface_format=sc2_env.parse_agent_interface_format( feature_screen=FLAGS.feature_screen_size, feature_minimap=FLAGS.feature_minimap_size, rgb_screen=FLAGS.rgb_screen_size, rgb_minimap=FLAGS.rgb_minimap_size, action_space=FLAGS.action_space, use_feature_units=FLAGS.use_feature_units), visualize=FLAGS.render) as env: env = EnvWrapper(env, config) # 创建环境,封装一层 agents = [agent_cls()] logging.info("Connected, starting run_loop.") try: # run_loop.run_loop(agents, env) runner = Runner(envs, agent, args.steps) # 创建进程 runner.run(args.updates, False) # 开始运行 except lan_sc2_env.RestartException: pass logging.info("Done.")
def client(): """Run the agent, connecting to a (remote) host started independently.""" agent_module, agent_name = FLAGS.agent.rsplit(".", 1) agent_cls = getattr(importlib.import_module(agent_module), agent_name) logging.info("Starting agent:") with lan_sc2_env.LanSC2Env( host=FLAGS.host, config_port=FLAGS.port0, race=sc2_env.Race[FLAGS.agent_race], step_mul=FLAGS.step_mul, agent_interface_format=sc2_env.parse_agent_interface_format( feature_screen=FLAGS.feature_screen_size, feature_minimap=FLAGS.feature_minimap_size, rgb_screen=FLAGS.rgb_screen_size, rgb_minimap=FLAGS.rgb_minimap_size, action_space=FLAGS.action_space, use_feature_units=FLAGS.use_feature_units), visualize=False) as env: agent_kwargs = {} if FLAGS.agent_config: agent_kwargs['config_path'] = FLAGS.agent_config agents = [agent_cls(**agent_kwargs)] logging.info("Connected, starting run_loop.") try: run_loop(agents, env, FLAGS.max_steps) except lan_sc2_env.RestartException: pass if FLAGS.save_replay: env.save_replay(agent_cls.__name__) logging.info("Done.")
def __init__(self, host, config_port, agent_race, step_mul=8, resolution=32, visualize_feature_map=False): agent_interface_format=sc2_env.parse_agent_interface_format( feature_screen=resolution, feature_minimap=resolution) self._sc2_env = lan_sc2_env.LanSC2Env( host=host, config_port=config_port, race=sc2_env.Race[agent_race], step_mul=step_mul, agent_interface_format=agent_interface_format, visualize=visualize_feature_map) self.observation_space = PySC2RawObservation(self._sc2_env.observation_spec) self.action_space = PySC2RawAction() self._reseted = False
def agent(): """Run the agent, connecting to a (remote) host started independently.""" agent_module, agent_name = FLAGS.agent.rsplit(".", 1) agent_cls = getattr(importlib.import_module(agent_module), agent_name) logging.info("Starting agent:") with lan_sc2_env.LanSC2Env( host=FLAGS.host, config_port=FLAGS.config_port, race=sc2_env.Race[FLAGS.agent_race], step_mul=FLAGS.step_mul, realtime=FLAGS.realtime, agent_interface_format=sc2_env.parse_agent_interface_format( feature_screen=FLAGS.feature_screen_size, feature_minimap=FLAGS.feature_minimap_size, rgb_screen=FLAGS.rgb_screen_size, rgb_minimap=FLAGS.rgb_minimap_size, action_space=FLAGS.action_space, use_unit_counts=True, use_camera_position=True, show_cloaked=True, show_burrowed_shadows=True, show_placeholders=True, send_observation_proto=True, crop_to_playable_area=True, raw_crop_to_playable_area=True, allow_cheating_layers=True, add_cargo_to_units=True, use_feature_units=FLAGS.use_feature_units), visualize=FLAGS.render) as env: agents = [agent_cls()] logging.info("Connected, starting run_loop.") try: run_loop.run_loop(agents, env) except lan_sc2_env.RestartError: pass logging.info("Done.")