Using genetic algorithm and neural networks to teach AI to play flappy bird. Inspired by this project and this paper. The dashboard in the html page is inspired by this website.
You can try this project in this page.
The TypeScript version is committed mainly by @javatlacati. Check it out.
- Make a flappy bird game
- Construct neural networks
- Construct genetic algorithms
- Teach the networks to play flappy bird
- Make the animation more fancy :)
- Make a little controller in the html page
-
Finish the "compete with AI" functionToo complicated and will make my code messy (though it is already a mess now). I give up...
It seems that there are more cons than pros for the birds to foresee the next two pipes instead of one, so I add an option on the dashboard to let the user enable or disable this feature (disabled by default).
I didn't expect this repo to have so many stars (at least from my perspective) when I first wrote this litte project. I reviewed this project today and made some changes.
-
A few more activation functions are added and can be selected from the dashboard (inspired by the TypeScript version committed by @javatlacati).
-
The height of the next-next-coming pipe is also fed to the neural network. This will make the evolution a little harder, but it provides a better result when the map is scrolling faster. Check the pros and cons of this feature in this discussion.
Rewrite the whole project in a syntax which is easier(?) to read and add the "enable animation" function.
This problem is indeed too easy for neural networks to solve. We just need to use this strategy: If the y-coordinate of the bird is larger than the next pipe, then fly. Otherwise just do nothing. This strategy can make the bird fly almost forever (I once reduce MOVE_SPEED to 2 and the bird is still flying after passing 10,000 pipes).
Anyhow, this is my first neural network program. Although the problem is very easy, it's still very interesting :) I'll try more games afterwards.
I discovered that there were some bugs in my previous code. After solving them the birds seems to evolve well :) They can now fly through hundreds of pipes within 100 generations.
Actually, their neural network is not very complicated, even for the best individual. There are only about 1 or 2 nodes in the hidden layer of the network, so I think this problem might be too easy for a neural network to solve. I'll try some more interesting games later.
I've created the basic parts of this project and it can be tested now. But my birds are not evolving well :( Generation after generation, they just can't fly through the pipe. Maybe the "NEAT" method doesn't work very well on this problem. I'll consider this problem later.