Skip to content

Instantly share code, notes, and snippets.

@starhopp3r
Created February 3, 2018 07:06
Show Gist options
  • Save starhopp3r/d4a21c8522ca67da58f1a4376706e079 to your computer and use it in GitHub Desktop.
Save starhopp3r/d4a21c8522ca67da58f1a4376706e079 to your computer and use it in GitHub Desktop.
import numpy as np
import gym
# Pong env
env = gym.make('Pong-ram-v0')
# Reset env
env.reset()
# Initialize previous obs
prev_obs = np.zeros((128,))
# Render and test
while True:
# Render
env.render()
# Sample an action from action space [0-5]
action = env.action_space.sample()
# Take an action
observation, reward, done, info = env.step(action)
# Difference between previous obs and current obs
move = prev_obs - observation
# Current obs will become the previous obs
prev_obs = observation
# Break once done
if done:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment