@Small network
11 inputs, one hidden layer of 256 neurons and 3 outputs: go straight, turn right, turn left.
<!-- A neural network trained with Q-learning that plays Snake. -->
This is a Snake game with an AI that learns to play it by itself. I made the game with Pygame, then I added the agent with PyTorch.
The AI does not see the screen. At each step it gets 11 values: if there is danger straight, to the right or to the left, the direction the snake is going (4 values), and where the food is compared to the head (4 values). The network is small: 11 inputs, one hidden layer of 256 neurons and 3 outputs, which are go straight, turn right and turn left.
It learns with Q-learning. After each move the agent trains on what just happened, and at the end of each game it trains on a random batch of 1000 moves taken from a memory of the last 100 000. The reward is +10 when the snake eats and -10 when it dies. At the start it plays a lot of random moves, and less and less as the number of games goes up.
After each game it saves the model, the scores and the graph, so I can stop the training and start it again later.
11 inputs, one hidden layer of 256 neurons and 3 outputs: go straight, turn right, turn left.
After each game it trains on a random batch of 1000 moves taken from the last 100 000.
The model, the scores and the graph are saved after each game, so I can stop and start again later.