Not proud for the quality of code but it was fun!
Creating a population of 1000 networks (check the repo) that start to play SnakeGame. Each network stops playing the game after 400 moves or if gameover occurs (whichever comes first).
100 out of those 1000 are the elite networks (the networks that achieved the best score).
Those elite networks get to live for one more generation and give birth to 900 new networks with some mutations, and those new networks replace the previous non-elite networks.
After training in a 10x10 grid for many generations the best network is able to play for a decent amount of time in a 40x25 grid.
Topology of the networks is {5, 4, 3}
Input
- Head to Food direction (2 nodes)
- Danger of hitting something in front, right, left of the head (3 nodes)
Output
- Don't turn, Turn right, Turn left (3 nodes)
Use Visual Studio Community 2019 to compile and run preferably in release mode.
I am using windows API for some console functions and GetAsyncKeyState for user input so this can run only on windows.
So... run the .exe let it train for as long as you like and then hit ESCAPE key to see how the best network performs.