Excelling at games
In the remainder of this chapter, we will use Q-games with the gym
package. It offers a standard API for playing different types of games, so it's the perfect test case for what we want to show you.
A small example
Anaconda doesn't ship this package, so it has to be installed though pip
:
>>> pip install gym[atari]
Note
We won't use the Atari part of the gym
, but it will be required for the breakout game.
From this package, we can create an environment for different games, like this:
env = gym.make('FrozenLake-v0')
This creates a new environment for the text game FrozenLake
. It consists of four four-character strings, starting with S
and ending up at G
, the goal. But there are holes (H
) on the way to this goal, and ending up there makes you lose the game:
SFFF
FHFH
FFFH
HFFG
From the environment, we can get the size of the observation space, env.observation_space.n
, which is 16
here (where the player is located) and the size of the action space env.action_space.n
, which is...