AI Learns to play Snake! -

AI Learns to play Snake!

Views: 77790
Like: 3044
Using a Genetic Algorithm and Neural Network, a population of snakes are able to gradually learn to play the game with no prior knowledge!

Link to code:




  1. Lovely! make some more autoplay like flappy bird and mario Please

  2. Starting the ai in a small area was definitely the key to its success. I have seen a few of these snake ai’s and they always struggle with avoiding their own tail. By putting the ai in a small area, you’re forcing it to deal with the lack of space early on and it overcomes the problem much better.

  3. I wish the snakes were able to further develop themselves to be more efficient on using time

  4. The end was like watching a thrilling movie?

  5. How much time did you train these snakes from first to the last generation?

  6. Hi, I would know what software did u used. Nice video!

  7. try to change the fitness function givin reward inversely related the duration. like reward=(LENGTH-TIME), it should develop a more interesting behavior

  8. It's great! and you low code it of NN! too powerful!

  9. Awesome video!
    Thank you for your insights 😊

  10. Love this video OMG best A.I. snake explanation

  11. The PERFECT ONE I was looking for…😃😃😃😲😲😲😲😲

  12. how do I get the last generation population from the code

  13. Dude, this is just straight up awesome. I need to do more of this stuff on my channel. I don't get exactly how the binary sensing works though.

  14. Wow, man. You and your brilliant snake did well. make ai on more complex games!

  15. I think the snake should to be able to see the entire screen at once, just like we can when we play and not these 8 directions.

  16. the best ai learning video I have watched so far, nice job!
    darn those 2 dislikes :V

  17. That was great. Even i want to build something like this, can you please tell which frameworks you are using for NN and genetic algorithms

  18. This video was (or more will be, dont have the time today) so helpfull improving my NEAT. I only had a Highscore of about 4-5 in Generation 3300

    I thank you really much

  19. This is very impressive. Improvements that I would like would be that the neural network can 'explain' or 'formulate' somehow how to play snake. Ofcourse not in a conscious way and not in a normal human language. Just that it would give us the basic concepts of its success. I believe we could achieve this by letting us be inspired again by the human brain. Those connections are not meaningless calculations. Every connection has a small meaning and together they form a bigger meaning. We already know the meaning of the inputs of our artificial neural networks, and we know the meaning of the outputs. Let search for the meaning of what's in between them.

  20. Awesome! I think you should put a metric to decrease unnecessary movements, it will increase snake's efficiency.

  21. you can actually create a neural network with only 2 output nodes

  22. How did you achieve that the snakes are not running in trapes? Was this luck or was there a Plan?

  23. I'm trying to regenerate the same model but using library interface like Keras, however i am wondering why didn't you use that? @Chrispresso

  24. Analog outputs could simplifu and remove some stupid deterministic artefacts from early and mid-lengths movements.

  25. what is considered a step? is it the distance the snake travels or is it going up/down/right/left

  26. PLOT TWIST: he actually hacked a school computer and found footage of me and the boys playing snake over many school years of computer recess's and the a.i inputs are faked

  27. I wonder what's the purpose of the tail direction. The snake doesn't know where its tail is so how does it help to know where it is moving?

  28. It basically set a hamiltonian cycle for itself

  29. Anyone who reads this, don't just watch a video and forget about it, give the creator some support for once

  30. Excellent video. I can't get my snakes to avoid the wall. What am I missing? Do you use elitism as well?

  31. Well its been a year since i saw this and im happy to be your 999th subscriber

  32. can you explain how do you get that fitness function?(2:40) I try to understand the "main idea" vs the function but i dont get it. that power raise over the apples ….. men u kill me xD

  33. How did you make those visual representations?

  34. I just love these AI videos!! But may i request something? I notice a lot of people usually remake the games, and then trains an AI to it. And here it appeared as if you gave the snake eyes, but when humans play, they look at the whole map. So then, could you try sometime to make an learning AI to an original game, that reads the screen as a human but hopefully doesn't run too slow because of the image it has to process?
    Either way im definitelly looking forward to more videos in the future!

  35. AI is so cool, it's amazing how many applications it has and how easily accessible it is for people.

Leave a Reply

Your email address will not be published.