Collection of examples, links and slides for the tutorial "Building a Pong playing AI in just 1 hour(plus 4 days training...)" presented at PyDataLondon 2016
Switch branches/tags
Nothing to show
Clone or download
Latest commit 274af1f May 15, 2016

Building a Pong playing AI

This repository contains the resources needed for the tutorial, Building a Pong playing AI in just 1 hour(Plus 4 days training time). The full video for the tutorial is on youtube here.

Installation Guide for OS X

Tested on a Macbook Pro (late 2013) with El Capitan, unsure if GPU-support works.


Install some image libraries and a X framework for MacOS:

brew install sdl_image
brew install Caskroom/cask/xquartz

Clone the repo:

git clone
cd PyDataLondon2016/

Create a virtual environment for Python 2:

conda create --name pong-ai-27 python=2
source activate pong-ai-27

Install listed dependencies plus opencv:

conda install matplotlib numpy opencv

Install tensorflow and pygame:

conda install -c tensorflow
conda install -c pygame

Initialize submodules:

git submodule init
git submodule update

Symlink resources and common in folder examples:

cd examples/
ln -s ../resources/ 
ln -s ../common/ 

Run an example:


Linux Nvidea GPU installation Guide

Tensorflow requires an NVidia GPU and only runs on Linux/Mac so if you don't have these Theano is an option (see below). The examples are all in Tensorflow, but that translates very easily to Theano and we have an example Q-learning Theano implementation that can be extended to work with Pong.

Windows/non nvidia gpu


Either 2 or 3 is fine.


Download which ever version matches the version of Python you plan on using.


Match version

Theano Installation Guide for Windows

Download anaconda and install packages:

conda install mingw libpython numpy

Clone Theano repo:

git clone

Install theano package:

cd Theano
python develop

###Docker environment alternative

Docker build

Have a look at the Makefile, essentially this helps you setup an xquartz environment exposed to a docker container along with the required dependencies.
'make all' should in theory launch you into an environment capable of running th examples straight away.


PyGame Player

Used for running reinforcement learning agents against PyGame

PyGame Pong

PyGame implementation of pong

PyGame Half Pong

Even pong can be hard if you're just a machine. Half pong is a simplified version of pong, if you can believe it. The score and other bits of noise are removed from the game. There is only 1 bar and it is only 80x80 pixels which speeds up training and removes the need to downsize the screen