官术网_书友最值得收藏!

How it works...

Using Gym, we can easily create an environment instance by calling the make() method with the name of the environment as the parameter.

As you may have noticed, the actions that the agent performs are randomly chosen using the sample() method.

Note that, normally, we would have a more sophisticated agent guided by reinforcement learning algorithms. Here, we just demonstrated how to simulate an environment, and how an agent takes actions regardless of the outcome.

Run this a few times and see what we get:

>>> env.action_space.sample()
0
>>> env.action_space.sample()
3
>>> env.action_space.sample()
0
>>> env.action_space.sample()
4
>>> env.action_space.sample()
2
>>> env.action_space.sample()
1
>>> env.action_space.sample()
4
>>> env.action_space.sample()
5
>>> env.action_space.sample()
1
>>> env.action_space.sample()
0

There are six possible actions in total. We can also see this by running the following command:

>>> env.action_space
Discrete(6)

Actions from 0 to 5 stand for No Operation, Fire, Up, Right, Left, and Down, respectively, which are all the moves the spaceship in the game can do.

The step() method will let the agent take the action that is specified as its parameter. The render() method will update the display window based on the latest observation of the environment.

The observation of the environment, new_state, is represented by a 210 x 160 x 3 matrix, as follows:

>>> print(new_state.shape)
(210, 160, 3)

This means that each frame of the display screen is an RGB image of size 210 x 160.

主站蜘蛛池模板: 文化| 山阴县| 和林格尔县| 清流县| 甘孜县| 青河县| 吴桥县| 沂南县| 米林县| 西青区| 辽源市| 赣州市| 京山县| 太谷县| 永宁县| 阿图什市| 红桥区| 托克逊县| 大庆市| 呼玛县| 杭锦后旗| 沈阳市| 岫岩| 湘阴县| 驻马店市| 平遥县| 攀枝花市| 六盘水市| 清原| 甘洛县| 天长市| 宁夏| 任丘市| 宁蒗| 大新县| 乌拉特后旗| 岚皋县| 衡阳县| 闵行区| 衡阳市| 阜新|