在用基于openAI-Gym的google's football simulator模拟足球比赛的时候,我试着录下屏幕。我目前的代码是:
import gfootball.env as football_env
env = football_env.create_environment(env_name='11_vs_11_stochastic', render=True)
env.reset()
done = False
while not done:
action = env.action_space.sample()
observation, reward, done, info = env.step(action)它显示了游戏,但我不知道如何记录它。任何帮助都将不胜感激。
发布于 2020-12-07 19:05:23
如果其他人想知道,这里有一个很好的文档here。您需要做的就是将write_video = True添加到环境配置中。我的代码现在看起来像这样,并且可以工作:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from absl import app
from absl import flags
from absl import logging
from gfootball.env import config
from gfootball.env import football_env
FLAGS = flags.FLAGS
flags.DEFINE_string('players', 'keyboard:left_players=1',
'Semicolon separated list of players, single keyboard '
'player on the left by default')
flags.DEFINE_string('level', '', 'Level to play')
flags.DEFINE_enum('action_set', 'default', ['default', 'full'], 'Action set')
flags.DEFINE_bool('real_time', True,
'If true, environment will slow down so humans can play.')
flags.DEFINE_bool('render', True, 'Whether to do game rendering.')
def main(_):
players = FLAGS.players.split(';') if FLAGS.players else ''
assert not (any(['agent' in player for player in players])
), ('Player type \'agent\' can not be used with play_game.')
cfg = config.Config({
'action_set': FLAGS.action_set,
'dump_full_episodes': True,
'players': players,
'real_time': FLAGS.real_time,
'dump_full_episodes': True,
'tracesdir': 'path/to/dir',
'write_video': True,
'render': True
})
if FLAGS.level:
cfg['level'] = FLAGS.level
env = football_env.FootballEnv(cfg)
if FLAGS.render:
env.render()
env.reset()
try:
while True:
_, _, done, _ = env.step([])
if done:
env.reset()
except KeyboardInterrupt:
logging.warning('Game stopped, writing dump...')
env.write_dump('shutdown')
exit(1)
if __name__ == '__main__':
app.run(main)请注意,我刚刚向file in official github repo添加了一些配置。
https://stackoverflow.com/questions/65168978
复制相似问题