This is a snake game developed using pygame. The classic snake game had only one consumable, apple. I've added two more consumables; ice, and chili. The ice and chili each have different effects. The ice, once consumed, will slow down the snake, and the chili will increase snake's speed. The apple will also increase the snake's speed, but at a lower rate.
Implementing NEAT:
The inputs of the neural netwerks generated by NEAT are as follows: the location of the apple relative to the snake's head (6 different possible states), whether the snake is moving towards the apple, in what direction lies danger (since the snake can either continue to go forward, or turn left or right, there are 3 distinct possiblities), the normalized distance between snake's head and the apple, the normalized absolute difference between the apple's and snake's head x coordinate, and the normalized absolute difference between the apple's and snake's head y coordinate. In conclustion, there are 13 inputs for each neural network.
The snake is rewarded for staying alive, but this is limited until the snake has reached a score of 15 (eaten 15 apples). This is implemented to inhibit the snake from learning to just stay alive and end up avoiding eating the apple. The model (snake) is also encouraged when moving towards the apple and eating an apple.
On the other hand, the model is punished (discouraged) when colliding with itself or the boundaries of the game (losing). In addition, the snake is punished when it takes to long to eat an apple and also when it keeps rotating around itself.
The model has 3 outputs, which each represent the 3 possible actions that the snake can take at each frame: continue going forward, turning left, turning right.