Implementation of the Atari emulator

We are now ready to build a simple Atari emulator using gym. As with other computer games, the keyboard input used to control Atari games is as shown here:

w
a
s
d
space
UP
LEFT
DOWN
RIGHT
FIRE

 

To detect the keyboard inputs, we use the pynput.keyboard package, which allows us to control and monitor the keyboard (http://pythonhosted.org/pynput/). If the pynput package is not installed, run the following:

pip install pynput

pynput.keyboard provides a keyboard listener used to capture keyboard events. Before creating a keyboard listener, the Listener class should be imported:

import gymimport queue, threading, timefrom pynput.keyboard import Key, Listener

Besides the Listener ...

Get Python Reinforcement Learning Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.