Developing an RL cycle

A basic RL cycle is shown in the following code block. This essentially makes the RL model play for 10 moves while rendering the game at each step:

import gym# create the environment env = gym.make("CartPole-v1")# reset the environment before startingenv.reset()# loop 10 timesfor i in range(10):    # take a random action    env.step(env.action_space.sample())    # render the game   env.render()# close the environmentenv.close()

This leads to the following output:

Figure 2.1: Rendering of CartPole

Let's take a closer look at the code. It starts by creating a new environment named CartPole-v1, a classic game used in control theory ...

Get Reinforcement Learning Algorithms with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.