Videos

Python + PyTorch + Pygame Reinforcement Learning – Train an AI to Play Snake



freeCodeCamp.org

In this Python Reinforcement Learning course you will learn how to teach an AI to play Snake! We build everything from scratch using Pygame and PyTorch.

💻 Code: https://github.com/python-engineer/snake-ai-pytorch

✏️ Course developed by Python Engineer. Check out his YouTube channel: https://www.youtube.com/channel/UCbXgNpp0jedKWcQiULLbDTA

🎨 Art by Rachel: http://rachel.likespizza.com/

⭐️ Course Contents ⭐️
⌨️ (0:00:00) Part 1: Basics of Reinforcement Learning and Deep Q Learning
⌨️ (0:17:22) Part 2: Setup environment and implement snake game
⌨️ (0:40:07) Part 3: Implement agent to control game
⌨️ (1:10:59) Part 4: Create and train neural network

🎉 Thanks to our Champion and Sponsor supporters:
👾 Raymond Odero
👾 Agustín Kussrow
👾 aldo ferretti
👾 Otis Morgan
👾 DeezMaster

Learn to code for free and get a developer job: https://www.freecodecamp.org

Read hundreds of articles on programming: https://freecodecamp.org/news

Source

Similar Posts

42 thoughts on “Python + PyTorch + Pygame Reinforcement Learning – Train an AI to Play Snake
  1. Very interesting topic, but a very bad teacher.
    He doesn't explain almost anything and the little he explains he talks about them very briefly like we already know all of those things and we make a revision.

  2. Very interesting tutorial. I was familiar with Snake code implementations, Tensorflow basics and RL principles and I could follow along. For some reason the plot doesn't appear, and I only get a small blank window where the plot should be. Probably some bug while typing the code down.
    Other than that everything works for me.
    Thank you very much!

  3. 38:13 "It has to be [0,0,1]" <— What about [0,0,0]? I think you should have explicitly checked for [0,0,1].
    (Or other weird states. 1,1,0 or 1,0,1 or etc…)

  4. Thanks for the video it was great but I have only one question if u can help after I run the agent and after a few try like 3rd game the game stuck and in the console suddenly start to count the number of game without the game really play

  5. Thank you so much for this tutorial. I have always wanted to introduce snake with ML. and now looking forward to learning more about pytorch

  6. Is there a limit to when it stops learning? I mean the quality of the intelligence will stay the same at some point, or will it improve even more and more after those 12 minutes? Thanks.

  7. nice algo, but how to solve a problem with self destroy, when the closest cell to move is "inside body circle". I think a state must be all field with each body part,head, food etc, but its endless states and all of them unique and it will never learns or may be i wrong?

  8. Thank you for your great work. I couldn’t understand the equation you created in the video about the simplified Bellman equation, Q_new = reward + gamma * torch.max(model(next_state)). In this equation, model(nextstate) gives us a probabilistic action prediction. I couldn’t understand why we added one of the action probabilities to the reward. This is totaly different than the Bellman Equation. I would be very happy if someone could explain how the original Bellman equation was simplified in this way. Thanks in advance to everyone.

  9. Been confused for a while with line 59 in model.py -> "torch.argmax(action)".
    This is wrong, but your model still learning?) Dunno how that works, but in repo this looks like "torch.argmax(action[idx])"

  10. Hello! Is there a way to save the state of the neural model? So I can load later a trained enemy AI, ready for being the player opponent? Thank you for the video!

  11. Theres no need of waiting a lot of time to train, on the game script you can just change the varaible from 30 to 1000 so snake goes much more fast and trains intself on less time.

  12. I think handing the fundamental flaw in the design to others as "homework" is a bit stiff…
    You're asking a neural network to solve an NP-Hard problem.

Comments are closed.

WP2Social Auto Publish Powered By : XYZScripts.com