Created
April 18, 2018 19:26
-
-
Save dnk8n/bee6ad732628c3c5d7c9379936c89124 to your computer and use it in GitHub Desktop.
A more readable simplification of the random agent example found at https://github.com/openai/retro/blob/master/examples/random_agent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import retro | |
env = retro.make(game='SonicTheHedgehog-Genesis', state='GreenHillZone.Act1', record=True) | |
env.reset() | |
time = 0 | |
total_reward = 0 | |
while True: | |
action = env.action_space.sample() | |
observation, reward, done, info = env.step(action) | |
time += 1 | |
if time % 10 == 0: | |
if info: | |
info_content = {key: value for key, value in info.items()} | |
print(f'time={time}, info: {info_content}') | |
env.render() | |
total_reward += reward | |
if reward > 0: | |
print(f'time: {time}, reward: {reward}, current_reward: {total_reward}') | |
if reward < 0: | |
print(f'time: {time}, penalty: {reward}, current_reward: {total_reward}') | |
if done: | |
# This happens both, when time and lives are up, and when game is completed | |
env.render() | |
print('done!') | |
break | |
print(f'time: {time}, total_reward: {total_reward}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment