Last active
November 26, 2019 13:30
-
-
Save pythonlessons/bf36981ddfb4dd3b857d734a249469f7 to your computer and use it in GitHub Desktop.
1_Cartpole_DQN_cartpole_random.py
This file contains hidden or 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
import gym | |
import random | |
env = gym.make("CartPole-v1") | |
def Random_games(): | |
# Each of this episode is its own game. | |
for episode in range(10): | |
env.reset() | |
# this is each frame, up to 500...but we wont make it that far with random. | |
for t in range(500): | |
# This will display the environment | |
# Only display if you really want to see it. | |
# Takes much longer to display it. | |
env.render() | |
# This will just create a sample action in any environment. | |
# In this environment, the action can be 0 or 1, which is left or right | |
action = env.action_space.sample() | |
# this executes the environment with an action, | |
# and returns the observation of the environment, | |
# the reward, if the env is over, and other info. | |
next_state, reward, done, info = env.step(action) | |
# lets print everything in one line: | |
print(t, next_state, reward, done, info, action) | |
if done: | |
break | |
Random_games() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment