Skip to main content

Teach a computer to play air hockey

I'm always looking for an excuse to build something fun... So it was only a matter of time before I got the idea to create a virtual air hockey game, and then train a neural network to play it.

Check it out: https://github.com/wybiral/air-hockey

The idea is pretty simple. First setup some basic physics for controlling the puck and paddles. Instead of writing a new physics engine I decided to go with matter.js (it's easy to use and supports everything I needed here). The neural network is a basic multilayer perceptron handled using synaptic.js (another great library that works well here). It's trained to recreate the actions of a human player given the position of the objects as inputs.

I've also been using this mini-project to track my development process using releases so if you're curious how this was put together you can look at each step along the way here: https://github.com/wybiral/air-hockey/releases

The next step will probably be to add export/import capabilities for the neural networks (that way we can train two different networks differently and then watch them go head-to-head).


Comments

Popular posts from this blog

Procedural music with PyAudio and NumPy

Combining two of my favorite pastimes, programming and music... This is the hacky "reduced to it's basic components" version of a library I've been working on for generating music and dealing with music theory.

Tweaking the harmonics by changing the shape of the harmonic components and ratios can produce some interesting sounds. This one only uses sine waveforms, but a square / saw generator is trivial with numpy.

It takes a second to generate, so don't turn your volume up too loud in anticipation (it may be loud).

import math
import numpy
import pyaudio
import itertools
from scipy import interpolate
from operator import itemgetter


class Note:

NOTES = ['c','c#','d','d#','e','f','f#','g','g#','a','a#','b']

def __init__(self, note, octave=4):
self.octave = octave
if isinstance(note, int):
self.index = note
self.note = Note.NOTES[note]
elif isinstance(note, st…

Build a Feed Reader in Python (Parts 7-9)

Part 07 Adding Jinja2 templates to a flask web application.

 Part 08 Adding static files so we can serve some CSS to style our app.

Part 09 Adding a background task to continuously update the articles while the application is running.

Write a Feed Reader in Python

I just started a new video tutorial series. This time it'll cover the entire process of writing an RSS feed reader in Python from start to finish using the feedparser module, flask, and SQLAlchemy. Expect to see about 3-4 new videos a week until this thing is finished!
Click to watch