AI Learns to Play Snake - Q Learning Explanation
Tech Tribe
I use a Q Learning algorithm in Python to train an agent to play the classic snake game 🐍. The goal of the game is to direct the snake toward eating apples, which allow the snake to grow longer. The snake also must avoid walls and its own body - crashing into these ends the game.
While it is easy for a human to play this game fairly well, I wanted to see how good of a snake AI we can train using Q Learning. I begin the video by presenting the viewers with a Q learning explanation. Specifically, I explain what a Q value is, explain how the bellman equation works, go over the features & rewards of this game, explain exploration vs. exploitation, and justify my choice of using vanilla Q learning over deep Q learning.
Afterwards, I show how well the snake game bot does after 10, 100, 200, 400, and 7,500 episodes of training. As expected, the agent starts out being terrible at the game but continuously improves as the Q table gets filled up with more and more accurate Q values.
By the end of the video, the snake game AI ends up getting a score over 100 (meaning it ate more than 100 apples in one run before dying), which is very good given the limited set of features that the agent had to work with.
In a future video, I will explore how Deep Q Learning can be applied to this game and give the agent many more features to work with, hopefully resulting in an improvement over the existing performance.
If you enjoyed the video, consider subscribing to the channel!
More about Q Learning: https://towardsdatascience.com/a-beginners-guide-to-q-learning-c3e2a30a653c Code: https://github.com/techtribeyt/snake-q-learning
#snakegame #coding #programming ... https://www.youtube.com/watch?v=je0DdS0oIZk
35186567 Bytes