Skip to content

Instantly share code, notes, and snippets.

@vihar
Created November 24, 2018 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vihar/971cfaa94b882ecb32b84defca81ab3e to your computer and use it in GitHub Desktop.
Save vihar/971cfaa94b882ecb32b84defca81ab3e to your computer and use it in GitHub Desktop.
import gym
from time import sleep
# Creating thr env
env = gym.make("Taxi-v2").env
env.s = 328
# Setting the number of iterations, penalties and reward to zero,
epochs = 0
penalties, reward = 0, 0
frames = []
done = False
while not done:
action = env.action_space.sample()
state, reward, done, info = env.step(action)
if reward == -10:
penalties += 1
# Put each rendered frame into the dictionary for animation
frames.append({
'frame': env.render(mode='ansi'),
'state': state,
'action': action,
'reward': reward
}
)
epochs += 1
print("Timesteps taken: {}".format(epochs))
print("Penalties incurred: {}".format(penalties))
# Printing all the possible actions, states, rewards.
def frames(frames):
for i, frame in enumerate(frames):
clear_output(wait=True)
print(frame['frame'].getvalue())
print(f"Timestep: {i + 1}")
print(f"State: {frame['state']}")
print(f"Action: {frame['action']}")
print(f"Reward: {frame['reward']}")
sleep(.1)
frames(frames)
@DarshanPankajMehta
Copy link

print(frame['frame'].getvalue())
AttributeError: 'str' object has no attribute 'getvalue'

@hidara2000
Copy link

print(frame['frame'])
should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment