r/iOSProgramming • • May 31 '20

Article Flappy Bird AI with 30 seconds of genetic learning and couple hours of development will beat anybody.

242 Upvotes

16 comments sorted by

45

u/_sroik_ May 31 '20

In case someone interested in source code

https://github.com/sroik/flappy-bird

0

u/[deleted] May 31 '20

[deleted]

4

u/_sroik_ May 31 '20

Yes, but what is the 'fitness' function ?

0

u/[deleted] May 31 '20

[deleted]

5

u/_sroik_ May 31 '20

I have property evolutionSize https://github.com/sroik/flappy-bird/blob/master/FlappyBird/Sources/GeneticLearning/GeneticEvolver.swift#L72 - it is the number of leader birds (the one who lived longer) who will remain unchanged in the next episode. All other birds are changing their gens https://github.com/sroik/flappy-bird/blob/master/FlappyBird/Sources/GeneticLearning/BirdAgent.swift#L75

1

u/AsidK Jun 01 '20

It looks like their fitness function is just how far each thing goes

12

u/tommys234 May 31 '20

Why.... why stop at 998?

13

u/_sroik_ May 31 '20

It went for an hour without losing. You can run the project yourself and learn some ML basics

10

u/danhoang1 May 31 '20

Think they were asking why not get 2 more so you're at 1000

16

u/_sroik_ May 31 '20

Then you wouldn’t ask this questions 😉

1

u/homiej420 May 31 '20

The real one did and just killed ya so its on point

5

u/Rudy69 May 31 '20

The gates are too close to the last one. When you fast forward it looks more like a hallway than flappy bird

1

u/glowhunter Jun 01 '20

It might be that Flappy Bird is a very simple game and most of the human performance difference is due to variation in reflexes?

0

u/_sroik_ Jun 01 '20

With Q-learning you can build AI almost for every game (simple). I mean mario, some car racing games, etc. Pretty simple and powerful algorithm

0

u/Fellhuhn Jun 01 '20

Translating the game state into something the AI can understand is another difficulty. If the AI has access to the internal state it has a huge advantage. If it has to parse the generated image/screen as every human has to it then most games are still quite complex for AIs.

3

u/yesthisisjoe Jun 01 '20

Nice. Inspired by Code Bullet?

4

u/gormster May 31 '20

This game looks a million times easier than flappy bird. Virtually all the gates are directly in line with each other.

3

u/PrayForTech May 31 '20

That’s sick! Well done dude