Skip to Main Content
Hands-On Reinforcement Learning with Python
book

Hands-On Reinforcement Learning with Python

by Sudharsan Ravichandiran
June 2018
Intermediate to advanced content levelIntermediate to advanced
318 pages
9h 24m
English
Packt Publishing
Content preview from Hands-On Reinforcement Learning with Python

Building a video game bot

Let's learn how to build a video game bot which plays a car racing game. Our objective is that the car has to move forward without getting stuck on any obstacles or hitting other cars.

First, we import the necessary libraries:

import gymimport universe # register universe environmentimport random

Then we simulate our car racing environment using the make function:

env = gym.make('flashgames.NeonRace-v0')env.configure(remotes=1) #automatically creates a local docker container

Let's create the variables for moving the car:

# Move leftleft = [('KeyEvent', 'ArrowUp', True), ('KeyEvent', 'ArrowLeft', True),        ('KeyEvent', 'ArrowRight', False)]#Move rightright = [('KeyEvent', 'ArrowUp', True), ('KeyEvent', 'ArrowLeft', False), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Deep Learning with Python

Advanced Deep Learning with Python

Ivan Vasilev

Publisher Resources

ISBN: 9781788836524Supplemental Content