• Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    Python
  • Created over 7 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flappy Bird AI using Evolution Strategies

Playing Flappy Bird using Evolution Strategies

After reading Evolution Strategies as a Scalable Alternative to Reinforcement Learning, I wanted to experiment something using Evolution Strategies, and Flappy Bird has always been one of my favorites when it comes to Game experiments. A simple yet challenging game.

The model learns to play very well after 3000 epochs, but not completely flawless and it rarely loses in difficult cases (high difference between two wall entrances). Training process is pretty fast as there is no backpropagation, and is not very costy in terms of memory as there is no need to record actions as in policy gradients.

Here is a demonstration of the model after 3000 epochs (~5 minutes on an Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz):

after training

Before training:

Before training

There is also a a web version available for ease of access.

For each frame the bird stays alive, +0.1 score is given to him. For each wall he passes, +10 score is given.

Demonstration of rewards for individuals and the mean reward over time (y axis is logarithmic): reward chart

Try it yourself

You need python3.5 and pip for installing and running the code.

First, install dependencies (you might want to create a virtualenv):

pip install -r requirements

The pretrained parameters are in a file named load.npy and will be loaded when you run train.py or demo.py.

train.py will train the model, saving the parameters to saves/<TIMESTAMP>/save-<ITERATION>.

demo.py shows the game in a GTK window so you can see how the AI actually plays (like the GIF above).

play.py if you feel like playing the game yourself, space: jump, once lost, press enter to play again. 😁

pro tip: reach 100 score and you will become THUG FOR LIFE 🚬

Notes

It seems training past a maximum point reduces performance, learning rate decay might help with that. My interpretation is that after finding a local maximum for accumulated reward and being able to receive high rewards, the updates become pretty large and will pull the model too much to sides, thus the model will enter a state of oscillation.

To try it yourself, there is a long.npy file, rename it to load.npy (backup load.npy before doing so) and run demo.py, you will see the bird failing more often than not. long.py was trained for only 100 more epochs than load.npy.

More Repositories

1

awesome-lite-websites

A list of awesome lightweight websites without all the bloat
1,413
star
2

node-telegram-api

A simple API to create and control Telegram bots
JavaScript
121
star
3

node-games

Node.js console games
JavaScript
53
star
4

hapi-sequelize-crud

Hapi plugin that automatically generates RESTful API for CRUD
JavaScript
42
star
5

harmony-algorithms

Some algorithms and data-structures written in ES6, for education purposes.
JavaScript
41
star
6

Equation

Solve Math expressions, create equations, define operators and constants
JavaScript
38
star
7

sibe

Experimental Haskell machine learning library
Haskell
35
star
8

super-snake

Simple, fast-paced snake game with extra fun! Powered by LibGDX
Java
34
star
9

Mickey.js

[DEPRECATED] Mouses are smarter these days! A handy tool to make it easy to play with mouses.
JavaScript
13
star
10

Hawk

The missing Firefox OS file manager
JavaScript
13
star
11

mahdi.blog

Personal blog
SCSS
12
star
12

picedit

simple set of functions and cli for image manipulation
Haskell
12
star
13

rust-shell

Simple shell written in Rust. For education purposes.
Rust
11
star
14

web-scraper

simple web scraping: extract texts and links as CSV, and save images of multiple websites
Python
10
star
15

slackbot-api

Simple, consistent Slack bot API
JavaScript
10
star
16

mathexpr

parse and evaluate math expressions
Haskell
9
star
17

webdevrobot

The code powering @webdevrobot
JavaScript
9
star
18

slope-field

visualize slope field of mathematical functions
Haskell
9
star
19

Sketchy

Free sketch/paint app -- Firefox OS and Web
CSS
7
star
20

ipsum

http://ipsum.ir
CSS
7
star
21

termcolor

Composable terminal colors
Haskell
6
star
22

CSS-Filter-Tooltip

CSS Filter Tooltip for Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=1055181)
JavaScript
5
star
23

serverman

simple service installation, configuration and monitoring of linux servers
Haskell
5
star
24

mahdi-os

An experimental OS written in Rust, just for learning!
Rust
5
star
25

pyhumandate

Parse human-readable dates
Python
5
star
26

pack

Dead-simple self-hosted cloud storage
Ruby
4
star
27

weekly-achievements

My weekly achievements
4
star
28

tlsproxy

A TLS man-in-the-middle proxy that can replace byte sequences of same length in outbound requests
Rust
4
star
29

evolution-presentation-persian

A presentation on Evolution
JavaScript
3
star
30

autocomplete-trie

Autocompletion system using Tries
JavaScript
3
star
31

rust-memory-playground

Rust
3
star
32

notMNIST

notMNIST small without empty files
2
star
33

rtcdemo

A simple WebRTC Demo which allows you to have a video + voice + text chat with your friends, without a backend
CSS
2
star
34

array-vs-generator

Example comparison between operating on arrays and generators (lazy iterables)
JavaScript
2
star
35

RingRangRong

Web Audio API Demo
JavaScript
2
star
36

snaphash

Preview video frames on <img> elements with ease
JavaScript
2
star
37

teamline-trello

Sync Teamline with Trello
JavaScript
2
star
38

hs-huffman

Huffman coding implementation in Haskell - I'm just learning Haskell
Haskell
1
star
39

note

Simplest note taking app ever, in browser, no fuss.
HTML
1
star
40

grunt-configurator

A grunt configuration builder CLI to kickstart your projects without wasting time
JavaScript
1
star
41

sentiment-analysis-data

Sentiment Analysis Data - Large Movies Review Database
1
star
42

newrelic-api

Connect to newrelic.com API v2
JavaScript
1
star
43

simple-sddm-theme

Simple sddm theme
QML
1
star
44

TicTacToe

PhoneGap test
JavaScript
1
star
45

button-progress

Simple progress indicator for buttons
CSS
1
star
46

bolt-engine

[WIP] A particle-based 3D physics engine, written in ES6, compiled using Traceur
JavaScript
1
star