Skip to content

Instantly share code, notes, and snippets.

@jojonki
Created January 2, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jojonki/4756f27244c32150faeb87139ff734f8 to your computer and use it in GitHub Desktop.
Save jojonki/4756f27244c32150faeb87139ff734f8 to your computer and use it in GitHub Desktop.
CartPole-v0 which is OpenAI's gym.
# -*- coding: utf-8 -*-
import gym
from gym import wrappers
env = gym.make("CartPole-v0")
env = wrappers.Monitor(env, './cartpole-experiment-1')
for i_episode in range(20):
observation = env.reset()
for t in range(100):
env.render()
# print(observation)
# action. 0: left, 1: right
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
print("Episode finished after {} timesteps".format(t+1))
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment