April 2019
Intermediate to advanced
212 pages
5h 34m
English
Let's get an instance of CartPole-v1 running.
We import the necessary package and build the environment with the call to gym.make(), as shown in the following code snippet:
import gymenv = gym.make('CartPole-v1')env.reset()done = Falsewhile not done: env.render() # Take a random action observation, reward, done, info = env.step(env.action_space.sample())
We run a loop that renders the environment for a maximum of 1,000 steps. It takes random actions at each timestep using env.step().
Here's the output displaying the CartPole-v1 environment:

You should see a small window pop up with the CartPole environment ...
Read now
Unlock full access