コード例 #1
0
def make_sonic_env(game,
                   state,
                   num_env,
                   seed,
                   scale_rew=True,
                   start_index=0,
                   render=False,
                   wrapper_kwargs=None):
    """
    Create a wrapped, monitored SubprocVecEnv for Atari.
    """

    # if wrapper_kwargs is None: wrapper_kwargs = {}
    def env_id_decorator(rank, scale_rew, render):  # pylint: disable=C0111
        def _thunk():
            return make_env(game=game,
                            state=state,
                            seed=rank,
                            scale_rew=scale_rew,
                            render=render)

        return _thunk

    set_global_seeds(seed)
    return subproc_vec_env.SubprocVecEnv([
        env_id_decorator(i + start_index, scale_rew=scale_rew, render=render)
        for i in range(num_env)
    ])
コード例 #2
0
ファイル: sonic_util.py プロジェクト: oeclint/glf
    def __init__(self, env_fns, nstack, spaces=None):
        import baselines.common.vec_env.subproc_vec_env as VecEnv

        def worker(remote, parent_remote, env_fn_wrapper):
            parent_remote.close()
            env = env_fn_wrapper.x()
            while True:
                cmd, data = remote.recv()
                if cmd == 'step':
                    ob, reward, done, info = env.step(data)
                    if done:
                        ob = env.reset()
                    remote.send((ob, reward, done, info))
                elif cmd == 'reset':
                    ob = env.reset()
                    remote.send(ob)
                elif cmd == 'render':
                    remote.send(env.render(mode='rgb_array'))
                elif cmd == 'close':
                    remote.close()
                    break
                elif cmd == 'get_spaces':
                    remote.send((env.observation_space, env.action_space))
                elif cmd == 'is_human':
                    remote.send(env.unwrapped.is_human)
                elif cmd == 'get_game_state':
                    remote.send(env.unwrapped.game_state)
                else:
                    raise NotImplementedError

        VecEnv.worker = worker
        venv = VecEnv.SubprocVecEnv(env_fns, spaces)
        venv = VecFrameStack(venv, nstack)
        VecEnvWrapper.__init__(self, venv)