I'm having some problems with saving the progression of states in frozen lake. I can save the actions easily by appending them to a list, but am having an issue finding the combination of commands to save the state. Is this possible?
I found a solution for myself, posting here in case it is handy for future uses:
import gym
from copy import copyenv = gym.make('FrozenLake-v0')
observation = env.reset()actions = [] # lists to store
state = []for _ in range(1000):
render = env.render(mode='ansi') # set mode to 'ansi'
contents = render.getvalue() # use StringIO's .getvalue()
action = env.action_space.sample()
state.append(contents) # append state and action to list
actions.append(action)
env.step(action)print actions, state
Summarised, this outputs (which can be cleaned easily):
[0, 3, 1, 0, 3, 3, 3, 3, 1, 3, 1, 2, 0, 3, 2, 0, 0, 0, 2, 1, 2, 3, 3, 2, 0, 1, 1, 1, 1, 0, 1, 0, 3, 0, 3, 1, 2, 3, 3, 0, 2, 3, 0, 1, 3, 1, 3, 3, 2, 3, 0, 1, 1, 1, 3, 0, 3, 2, 0, 3, 3, 2, 3, 2, 3, 0, 2, 0, 0, 0, 1, 1, 2, 0, 0, 1, 3, 0, 1, 2, 2, 3, 0, 1, 1, 3, 1, 1, 3, 2, 3, 3, 2, 2, 3, 0, 2, 3, 1, 0, 1, 2, 0, 3, 0, 2, 0, 3, 3, 0, 3, 0, 0, 0, 0, 2, 3, 0, 3, 2, 3, 3, 1, 1, 1, 0, 1, 1, 1, 3, 0, 3, 1, 2, 0, 1, 2, 0, 2, 0, 1, 3, 2, 2, 1, 0, 3, 1, 1, 3, 0, 2, 2, 3, 2, 3, 3, 3, 2, 1, 2, 2, 3, 2, 3, 3, 2, 2, 3, 0, 1, 2, 3, 2,... ] [...(Down)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Right)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Left)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Down)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Right)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Down)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Right)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Down)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Up)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Right)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Up)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Down)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Right)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Up)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Right)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Right)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Right)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' (Left)\nSFFF\nF\x1b[41mH\x1b[0mFH\nFFFH\nHFFG\n', u' ]
This could be of potential use for future individuals, but if this is not an appropriate place just delete!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
I found a solution for myself, posting here in case it is handy for future uses:
Summarised, this outputs (which can be cleaned easily):
This could be of potential use for future individuals, but if this is not an appropriate place just delete!