Snake Game : Neural Evolution
Code:
https://github.com/PIgglyPoof/NeuralEvolution-very-basic-/tree/master/snake_game
Just a basic implementation of neural network + genetic algorithm
The program generates 2000 snakes but only the snake with the highest score is shown on screen.
After all, snakes are dead, I sort them according to fitness and make 10 copies of top 10 snakes and overwrite them on snakes with the lowest value. I also make a globalBest snake so that in case the snake becomes worse during mutation and crossover I won't lose the data.
After that, crossover/mutation takes place and process repeats.
Every snake works independently.
The program uses 26 input parameters, about 20 hidden and 4 outputs. Initially, I made only 4 inputs describing the position of food using co-ordinate geometry but it didn't work out well. Then I did some research on google/youtube and found a working method and used that one. I added 2 additional inputs to that one cause that one also had some flaws. Well, no one is perfect.
I rushed this project cause my college is opening soon. It can be definitely improved,
Also, Java is not my primary language and I couldn't figure out how to save my snake object array data :(. If anyone knows how to do it please mention in the comment. but I don't think anyone will read it.