Loading the Game

Let's load the CartPole-v1 game from the gym module. It's very simple. All you have to do is feed gym.make() function the name of the game.  In our case the game is CartPole-v1. Gym then loads the game into your workspace.

env = gym.make('CartPole-v1')

 

It is important that you set seed for reproducibility.

# Set seed for reproducibility
seed_val = 456
np.random.seed(seed_val)
env.seed(seed_val)
random.seed(seed_val)

 

Let's explore how many variables we have in the Cart-Pole game.

states = env.observation_space.shape[0]
print('Number of states/variables in the cartpole environment', states)

We see that the Cart-Pole has 4 variables and these are namely the position(x), velocity(x_dot), angular position(theta) and the angular velocity(theta_dot). 

 

Let's explore how many possible responses we have in this game.

actions = env.action_space.n
print('Number of responses/classes in the cartpole environment', actions)

We see that the Cart-Pole environment has two possible responses/buttons namely the move left and move right.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.199.184