Skip to content

Instantly share code, notes, and snippets.

@pythonlessons
Last active November 26, 2019 13:30
Show Gist options
  • Save pythonlessons/bf36981ddfb4dd3b857d734a249469f7 to your computer and use it in GitHub Desktop.
Save pythonlessons/bf36981ddfb4dd3b857d734a249469f7 to your computer and use it in GitHub Desktop.
1_Cartpole_DQN_cartpole_random.py
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