Skip to content

Instantly share code, notes, and snippets.

@vihar
Created November 24, 2018 12:29
Show Gist options
  • 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)
@clebrw
Copy link

clebrw commented Mar 5, 2019

subsr97 - You must add in line 3 of your code
from IPython.display import clear_output

@UrbanListings
Copy link

Looks like Author has not defined the Solution on How to resolve the TypeError: function object is not iterable.
If message thread is Open then please provide the response on the Error Resolution. Appreciation in advance!

@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