I am trying to build a network able to play snake game. This is my very first attempt to do such stuff. Unfortunately, I've stuck and even have no idea how to reason about the problem.
I use reinforcement neural network approach (q-leaning). My network is built on top of Keras. I use 6 input neurons for my snake:
- 1 - is any collision directly behind
- 2 - is any collision directly on the right
- 3 - is any collision directly on the left
- 4 - is snack up front (no matter how far)
- 5 - is a snack on the right side (no matter how far)
- 6 - is a snack on the left side (no matter how far)
the output has 3 neurons:
- 1 - do nothing (go ahead)
- 2 - turn right
- 3 - turn left
I believe this is a sufficient set of information to make proper decisions. But the snake seems to not even grasp the concept of not hitting the wall - which results with instant death.
I use the following rewards table:
- 100 for getting the snack
- -100 for hitting wall/tail
- 1 for staying alive (each step)
Snake tends to run randomly no matter how many training iterations it gets.
The code is available on my github: https://github.com/ayeo/snake/blob/master/main.py