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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.