SmartSnake
A deep Q-learning agent that teaches itself to play Snake. It starts from random weights and trains live in your browser; this is a TensorFlow.js port of the original PyTorch agent.
How it works
- What it sees
- Eleven yes-or-no inputs: whether there is danger straight ahead, to the right, or to the left; which way it is moving; and which way the food is.
- The network
- Eleven inputs, one hidden layer of 256 ReLU units, and three outputs: the predicted value (Q) of going straight, turning right, or turning left. It takes the highest.
- How it learns
- After every move it trains on that step, pushing the chosen action's Q-value toward the reward plus 0.9 times the best Q-value of the next state. After each game it also trains on 1,000 moves sampled from a memory of the last 100,000. Food is worth +10 and dying costs 10.
- Exploring
- To find out what works, it moves at random 40% of the time in its first game, falling to never by game 80.