本文整理汇总了Python中retro.make方法的典型用法代码示例。如果您正苦于以下问题:Python retro.make方法的具体用法?Python retro.make怎么用?Python retro.make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类retro
的用法示例。
在下文中一共展示了retro.make方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_playback
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def test_playback():
movie = retro.Movie('Airstriker-Genesis-Level1-000000.bk2')
movie.step()
env = retro.make(
game=movie.get_game(),
state=None,
# bk2s can contain any button presses, so allow everything
use_restricted_actions=retro.Actions.ALL,
players=movie.players,
)
env.initial_state = movie.get_state()
env.reset()
while movie.step():
keys = []
for p in range(movie.players):
for i in range(env.num_buttons):
keys.append(movie.get_key(i, p))
env.step(keys)
env.render()
示例2: make_retro
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def make_retro(*, game, state, max_episode_steps, **kwargs):
import retro
env = retro.make(game, state, **kwargs)
env = StochasticFrameSkip(env, n=4, stickprob=0.25)
if max_episode_steps is not None:
env = TimeLimit(env, max_episode_steps=max_episode_steps)
return env
示例3: __init__
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def __init__(self, screen_ratio=4, coords_ratio=4, use_color=True, use_rc_frame=True, stack=3, frame_skip=4, action_repeat=4, level='1.1'):
level = level.replace('.', '_')
game_state = 'mario_level_{}.state'.format(level)
print(game_state)
self.env = retro.make('SuperMarioAllStars-Snes', state=game_state)
# observations
self.screen_ratio = screen_ratio
self.original_height = 224
self.original_width = 256
self.screen_height = self.original_height // screen_ratio
self.screen_width = self.original_width // screen_ratio
self.screen_shape = (self.screen_height, self.screen_width)
self.use_color = use_color
self.use_rc_frame = use_rc_frame
self.stack = stack
self.frame_skip = frame_skip
n_frames = stack * (3 * use_color + 1 * (not use_color) + use_rc_frame)
self.frames = deque([], maxlen=(self.frame_skip * (self.stack - 1) + 1))
self.observation_space = spaces.Box(low=0, high=255, shape=(self.screen_height, self.screen_width, n_frames))
# coordinates
self.coords_ratio = coords_ratio
assert coords_ratio % screen_ratio == 0, (coords_ratio, screen_ratio)
self.coords_screen_ratio = coords_ratio // screen_ratio
self.coords_height = self.original_height // coords_ratio
self.coords_width = self.original_width // coords_ratio
self.coords_shape = (self.coords_height, self.coords_width)
# actions
self.action_names = ['JUMP+LEFT', 'JUMP', 'JUMP+RIGHT', 'LEFT', 'NOOP', 'RIGHT']
self.action_list = [actions[n] for n in self.action_names]
n_actions = len(self.action_list)
self.action_space = spaces.Discrete(n_actions)
self.action_repeat = action_repeat
# miscellaneous
frame_name = 'RGB' if use_color else 'G'
if use_rc_frame: frame_name += 'C'
self.name = 'CustomSuperMarioAllStars_{}_obs{}x{}x{}x{}_qframes{}x{}x{}_skip{}_repeat{}-v0'.format(
level, *self.screen_shape, frame_name, stack, *self.coords_shape, n_actions, frame_skip, action_repeat)
示例4: init_env
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def init_env(self):
env = retro.make(self.name, **self._env_kwargs).unwrapped
if self.wrappers is not None:
for wrap in self.wrappers:
env = wrap(env)
self._env = env
self.action_space = self._env.action_space
self.observation_space = (
self._env.observation_space
if self.observation_space is None
else self.observation_space
)
示例5: create_environment
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def create_environment():
env = retro.make(game='SpaceInvaders-Atari2600')
possible_actions = np.array(np.identity(env.action_space.n, dtype=np.int).tolist())
return env, possible_actions
示例6: test_record
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def test_record():
# env = retro.make(game='SpaceInvaders-Atari2600')
# env = retro.make(game='SonicTheHedgehog-Genesis', state='GreenHillZone.Act1', record='.')
env = retro.make(game='Airstriker-Genesis', record='.')
obs = env.reset()
done = False
while not done:
obs, rew, done, info = env.step(env.action_space.sample())
env.render()
env.close()
示例7: create_level
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def create_level(cls, level, max_episode_steps, reward_threshold, tags, **kwargs):
import retro
assert max_episode_steps is False and reward_threshold is None and tags is None
return retro.make(game=level, **kwargs), max_episode_steps
示例8: make
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def make(game, state, stack=True, scale_rew=True):
"""
Create an environment with some standard wrappers.
"""
env = retro.make(game, state)
env = SonicDiscretizer(env)
if scale_rew:
env = RewardScaler(env)
env = WarpFrame(env)
if stack:
env = FrameStack(env, 4)
return env
示例9: make_retro
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def make_retro(*, game, state=None, max_episode_steps=4500, **kwargs):
import retro
if state is None:
state = retro.State.DEFAULT
env = retro.make(game, state, **kwargs)
env = StochasticFrameSkip(env, n=4, stickprob=0.25)
if max_episode_steps is not None:
env = TimeLimit(env, max_episode_steps=max_episode_steps)
return env
示例10: init_env
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def init_env(self):
env = retro.make(self.name, **self._env_kwargs).unwrapped
if self.wrappers is not None:
for wrap in self.wrappers:
env = wrap(env)
self._env = env
self.action_space = self._env.action_space
self.observation_space = self._env.observation_space if self.observation_space is None \
else self.observation_space
示例11: make
# 需要导入模块: import retro [as 别名]
# 或者: from retro import make [as 别名]
def make(game, state=retro.State.DEFAULT, discrete_actions=False, bk2dir=None):
use_restricted_actions = retro.Actions.FILTERED
if discrete_actions:
use_restricted_actions = retro.Actions.DISCRETE
try:
env = retro.make(game, state, scenario='contest', use_restricted_actions=use_restricted_actions)
except Exception:
env = retro.make(game, state, use_restricted_actions=use_restricted_actions)
if bk2dir:
env.auto_record(bk2dir)
env = retro_contest.StochasticFrameSkip(env, n=4, stickprob=0.25)
env = gym.wrappers.TimeLimit(env, max_episode_steps=4500)
return env