Created
October 15, 2022 10:44
-
-
Save SolClover/79761956bf9df19648591a77731f4476 to your computer and use it in GitHub Desktop.
Agent performing random actions around the environment
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
# Reset environment to initial state | |
state, info = env.reset() | |
# Cycle through 30 random steps redering and displaying the agent inside the environment each time | |
for _ in range(30): | |
# Render and display current state of the environment | |
plt.imshow(env.render()) # render current state and pass to pyplot | |
plt.axis('off') | |
display.display(plt.gcf()) # get current figure and display | |
display.clear_output(wait=True) # clear output before showing the next frame | |
# Sample a random action from the entire action space | |
random_action = env.action_space.sample() | |
# Pass the random action into the step function | |
state, reward, done, _, info = env.step(random_action) | |
# Reset environment when done=True, i.e., when the agent falls into a Hole (H) or reaches the Goal (G) | |
if done: | |
# Render and display current state of the environment | |
plt.imshow(env.render()) # render current state and pass to pyplot | |
plt.axis('off') | |
display.display(plt.gcf()) # get current figure and display | |
display.clear_output(wait=True) # clear output before showing the next frame | |
# Reset environment | |
state, info = env.reset() | |
# Close environment | |
env.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment