Any gym environment can be initialized and run by using a simple interface. Let's start by importing the gym library, as follows:
- First we import the gym library:
- Next, create an environment by passing an argument to gym.make. In the following code, CartPole is used as an example:
environment = gym.make('CartPole-v0')
- Next, reset the environment:
- Then, start an iteration and render the environment, as follows:
for dummy in range(100): environment.render() environment.step(environment.action_space.sample())
Also, change the action space at every step, to see CartPole moving. Running the preceding program should produce a visualization. The scene should start with a visualization, ...