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:
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 ...