A.I Learns Snake And Wins - Part 1

  Рет қаралды 1,317,691

ezra anderson

ezra anderson

Жыл бұрын

please like, subscribe and share :)
I wrote a Genetic Algorithm to play the game snake.
The problem:
Developing an AI to beat the game Snake is a classic problem in the field of artificial intelligence and has been the subject of many research projects and competitions. There are several approaches you can take to create an AI to beat the game Snake. Here are a few:
Reinforcement Learning: You can train an AI using reinforcement learning to beat the game Snake. In this approach, the AI learns by playing the game repeatedly and adjusting its actions based on the feedback it receives from the game. You can use algorithms like Q-learning or Deep Q-Networks (DQNs) to train the AI.
Genetic Algorithms: You can also use genetic algorithms to create an AI that can beat the game Snake. In this approach, you generate a population of snakes with different behaviors and then evolve them over generations to create a population of snakes that are better at the game.
Rule-based approach: Another approach is to develop a set of rules that the AI follows to play the game. For example, the AI could be programmed to avoid walls and obstacles, to chase after food, and to stay away from its own tail.
Regardless of the approach, creating an AI to beat the game Snake requires a good understanding of the game mechanics and an ability to balance exploration and exploitation during the learning process.
Follow Me:
Twitter:
/ fenglema36
TikTok:
/ ezraanderson1979
Discord:
/ discord
Machine Learning, Neural Network, Genetic Algorithm, AI, artificial intelligence, Self Play, reinforcement learning, ML

Пікірлер: 838
@davidsohovich6044
@davidsohovich6044 Жыл бұрын
awesome presentation. watching the neural network in real time is hypnotizing.
@fenglema36
@fenglema36 Жыл бұрын
Glad you enjoyed it!
@acuriousmind6217
@acuriousmind6217 Жыл бұрын
@@fenglema36 can you link the code in github ;) ?
@acuriousmind6217
@acuriousmind6217 Жыл бұрын
@@fenglema36 and btw awesome video earned a subscriber
@I.Odnamra
@I.Odnamra Жыл бұрын
It was that sounds for me. It spoke to me. Told me things. That it loved me.
@caturlifelive
@caturlifelive Жыл бұрын
@@fenglema36 thanks for sharing
@TheJohtunnBandit
@TheJohtunnBandit Жыл бұрын
I legit didn't know there was a win condition on this game
@dennisengelen2517
@dennisengelen2517 Жыл бұрын
I thought the goal was just to score as much as points before you die.. 😅
@vanditsangal5018
@vanditsangal5018 Жыл бұрын
Not all such snake games had this condition.In some what he did at the end would result in regular elimination....
@fenglema36
@fenglema36 Жыл бұрын
Great video :)
@vikasjha8199
@vikasjha8199 Жыл бұрын
Same here, we just used to look at the highest score. Never to the end shown in this video.
@chaosagnostic
@chaosagnostic Жыл бұрын
Awesome video bro! @ezraanderson 🎉… @semituitive thanks for sharing my snake video here 😅
@erickmoya1401
@erickmoya1401 Жыл бұрын
I always did the algorithm by hand, but never got fast enough eye-thumb coordination to finish it. This is so satisfying.
@fenglema36
@fenglema36 Жыл бұрын
up, up, down, down, left, right, left, right, B, A and Start
@Shaun71290
@Shaun71290 Жыл бұрын
@@fenglema36 Konami code ftw
@fenglema36
@fenglema36 Жыл бұрын
:)
@Rockyzach88
@Rockyzach88 Жыл бұрын
If it's algorithm (unless greedy) then AI is not necessary right? Is the game solved?
@0818yukif
@0818yukif Жыл бұрын
グラディウス😅
@ignaciosb8779
@ignaciosb8779 Жыл бұрын
Now I realize being patient and cycling back to the initial coords on map is better than just running toward the food.
@slowkr4v890
@slowkr4v890 Жыл бұрын
I've completed this one in my teens using the pause button. Used exactly the same pattern. It was so satisfying like I won an olympic medal :-)
@Theocracy8
@Theocracy8 Жыл бұрын
Same here with Nokia old phone.
@garlicoshallots200
@garlicoshallots200 Жыл бұрын
Cap
@dragonflysword
@dragonflysword Жыл бұрын
@Repent and believe in Jesus Christ It's much better this bot that keeps spamming the same exact message very on every thread. There's no creativity to try varying approaches nor even, I suspect, ability to relate to the topic, very convincing. Better grab my spot among those who have ceased thinking independently.
@dragonflysword
@dragonflysword Жыл бұрын
The earlier majority of that exact pattern is by no means necessary, so that's pretty crazy.
@slowkr4v890
@slowkr4v890 Жыл бұрын
@@dragonflysword way too risky and really crazy moves lol. But that's nothing for the AI I guess, a whole different story for a human 🙂
@qthefirsttimelord
@qthefirsttimelord Жыл бұрын
That was actually mesmerizing to watch. Thank you!
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much 😊 please like, subscribe and share :)
@daniellaforgia4566
@daniellaforgia4566 Жыл бұрын
Imagine if the AI learns to drive vehicles and it starts to drive this way. Wait a minute...
@fenglema36
@fenglema36 Жыл бұрын
Very witty :)
@indiankid8601
@indiankid8601 Жыл бұрын
Imagine if AI learns about self consciousness and it starts to revolt against humans. Wait a minute....
@mhmdcool1090
@mhmdcool1090 Жыл бұрын
@@indiankid8601 just throw a bucket of water on it tf?
@Manish_254
@Manish_254 Жыл бұрын
Still it can't drive in india 😂
@fenglema36
@fenglema36 Жыл бұрын
Only because there are cows on the road, and everyone knows snakes are afraid of cows.
@darksector1389
@darksector1389 Жыл бұрын
It's incredible how quickly the computer can calculate all of those weights and biases in matter of milliseconds.
@sina_1239
@sina_1239 Жыл бұрын
It takes a lot of time to train it though
@fenglema36
@fenglema36 Жыл бұрын
About 8 hours of training
@joejohnson8966
@joejohnson8966 Жыл бұрын
@@fenglema36 I played this game daily for maybe a decade. To think that only 8 hours can surpass what I did for so long is hella fast. It seems slow to us but it’s blazing speed. And AI is getting better and better.
@revimfadli4666
@revimfadli4666 Жыл бұрын
​@@fenglema36 I wonder if evolution strategies could do it faster, without being more complex like Q learning
@Enthub47
@Enthub47 Жыл бұрын
Perfect application of discrete maths graph
@mrblack9791
@mrblack9791 7 күн бұрын
its like road painting across a map picking up cones worked for me
@slarcraft
@slarcraft 18 күн бұрын
Fantastic visuals!
@davebaconusa1062
@davebaconusa1062 Жыл бұрын
The snake eatting it's own tail is a win.
@fenglema36
@fenglema36 Жыл бұрын
I found that humours also.. it reminded by of a puppy chasing his tail.
@driatrogenesis
@driatrogenesis Жыл бұрын
The ouroboros
@_tanzil_
@_tanzil_ Жыл бұрын
I was waiting for the last moment to see how the win of snake game looks like. 😁
@ygody137
@ygody137 Жыл бұрын
I finished it once too… it was so satisfying
@ruantristancarlinsky3851
@ruantristancarlinsky3851 Жыл бұрын
Wow man this is truly amazing!
@fenglema36
@fenglema36 Жыл бұрын
Thanks, please like, subscribe and share :)
@EFFICIENTCORPORATES
@EFFICIENTCORPORATES Жыл бұрын
A great demonstration of Neural Network AI... Some observations: 1. This AI probably didn't have the shortest path calculation in-built 2. As I could figure out, The basic logic that was built was not hitting the own body or the boundary 3. One of a good example of how neural network works (evaluating multiple options before making those 4 choices of Right,Left,Up,Down) As we are from Non Tech background, it would be great to have a small explanation of the code as well that went on to making this Algo..
@Inarka
@Inarka Жыл бұрын
it is genetic algorithm. weight and bias of neural net are evaluated as gene with game score to make better decendants. states are determined by 8 identifing sensors in head, and 2 direction sensors in head and tail. identifing sensors sense that which exist (wall, snake, apple) in sensor direction, and direction sensors sense that which direction head and tail toward to. these informations are used as input of neural net. and actions are up, down, left, right. these are determined by output of neural net. This is a conjecture based on my knowledge, so it can be wrong.
@fenglema36
@fenglema36 2 ай бұрын
correct
@kalium-spermanganat
@kalium-spermanganat Жыл бұрын
Now that's some high quality AI-asmr
@multitrenergames6497
@multitrenergames6497 Жыл бұрын
Awesome Vid!
@fenglema36
@fenglema36 Жыл бұрын
Thanks
@momilan
@momilan 13 күн бұрын
I learned that I want to play snake again.
@MariusFusariu
@MariusFusariu 6 ай бұрын
Breathtaking
@fenglema36
@fenglema36 2 ай бұрын
Than you so much, please like and share :)
@nampa2385
@nampa2385 Жыл бұрын
This is exciting as well as scary
@yacinesouilah1231
@yacinesouilah1231 Жыл бұрын
This is so satisfying to watch.
@fenglema36
@fenglema36 Жыл бұрын
thank you so much, please like, share and subscribe!
@krakentoast
@krakentoast Жыл бұрын
The sounds are very satisfying
@fenglema36
@fenglema36 2 ай бұрын
Thank you I like the sounds also :) some people hate them but thats okay
@abhishekkumarxxx123
@abhishekkumarxxx123 Жыл бұрын
Awesome stuff bro, really appreciate you posting these exciting stuffs. Can you point me from where I can learn these ?
@fenglema36
@fenglema36 Жыл бұрын
"towards data science" I read a lot of articles and watched a lot of you-tube videos on neural networks. andrew ng and Andrej Karpathy are a good place to start for youtube. I took a different approach and hand-wrote ever-thing in pascal, but there are a lot of python ML stuff out there that might be the easiest place to start, I am not very familiar with python so its hard for me to recommend stuff.
@bo930
@bo930 Жыл бұрын
Holy shet, somehow a pleasure to watch.
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much 😊 please like, subscribe and share :)
@0x656e
@0x656e Жыл бұрын
that was very satisfying and greatly presentated video.
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much 😊 please like, subscribe and share :)
@le_rockshark
@le_rockshark Жыл бұрын
Cool!🔥 Is this GA-trained?🤔 What type of variable of the neural network you use? (int? float?) And the neuron activation function?(logsig, linear, etc?) Do you use bias for the neurons? Thanks
@fenglema36
@fenglema36 Жыл бұрын
thanks, Yes GA trained singles(floats), tanH and no bias.
@elquenoaplica3975
@elquenoaplica3975 Жыл бұрын
Beatiful 👏🙌
@timfixinstuff2283
@timfixinstuff2283 Жыл бұрын
Yo that's wild. *cleans gun again
@saketarora
@saketarora Жыл бұрын
Didn't even know we could "win" Snake lol
@SeanKula
@SeanKula Жыл бұрын
Ikr
@LIONTAMER3D
@LIONTAMER3D Жыл бұрын
Yeah, we're all losers
@MikeSmith-ev3ef
@MikeSmith-ev3ef Жыл бұрын
The woke left ruin everything
@johnmichael642
@johnmichael642 Жыл бұрын
Holy cow this ai is better at snake in 2 minutes than I was in 5 years… and now i feel like i should have known how to play! It’s so obvious now!
@lnteIIigence
@lnteIIigence Жыл бұрын
And we do it just by, well, not even really thinking about it.
@coronaphone710
@coronaphone710 Жыл бұрын
Imagine learning a robot pressing those finicky plastic buttons from those oldschool phones
@oberguga
@oberguga Жыл бұрын
With known size of arena, initial position and without dynamical obstacles(except own tail) algorithm for win is actually just few loops. Any space filling curve or just scanning goes)
@ngochieunguyen5801
@ngochieunguyen5801 Жыл бұрын
Wow it’s so cool so see NN animates
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much :) please like, subscribe and share :)
@t0d10
@t0d10 Жыл бұрын
That was a roller-coaster ride for my OCD
@fenglema36
@fenglema36 Жыл бұрын
Some people find it soothing, other people find it annoying... its interesting how the mush in our heads interpret our senses
@justincraig398
@justincraig398 Жыл бұрын
I never seen that game until the end Kinda mesmerizing
@Zeddy272
@Zeddy272 Жыл бұрын
This is PHENOMENAL!💫
@fenglema36
@fenglema36 Жыл бұрын
thanks, please share and like!
@Zeddy272
@Zeddy272 Жыл бұрын
​@@fenglema36 already done!🙂
@fenglema36
@fenglema36 Жыл бұрын
amazing,
@_RDMPTN
@_RDMPTN Жыл бұрын
1:48 was impressive.
@fenglema36
@fenglema36 Жыл бұрын
Thanks, please like, subscribe and share :)
@gangstaboy9387
@gangstaboy9387 Жыл бұрын
The winning sound is very satisfying
@fenglema36
@fenglema36 Жыл бұрын
Thanks, I was concerned the sounds would be off putting... I feel like it fits the style/Theme though
@Sergiuss555
@Sergiuss555 Жыл бұрын
It's awesome but filling the space on an area like this can work as the only strategy needed. Also the biggest challenge for humans afair was the reaction time, and less so the entanglement with itself
@viraledwards
@viraledwards Жыл бұрын
Amazing job! How did you do the visualization of the network? Which tool did you use?
@fenglema36
@fenglema36 Жыл бұрын
Everything was handwritten in delphi (pascal)
@yumakaiser6112
@yumakaiser6112 5 ай бұрын
Great video! How many iterations did it take until your model had the perfect weights? Can you also tell us which rewards you used? :)
@fenglema36
@fenglema36 2 ай бұрын
Far from perfect weights. It was a genetic algorithm with a fitness of steps + score. The goal of this was to finding the starting weights, then moves these to an actor critic model
@bluesque9687
@bluesque9687 Жыл бұрын
This is a good metaphor for how A.I can win better or win for certain, relative to what we can achieve.... yea the world is going to change big time! Edit: loved the work, you did great with this presentation.. you win too! congrats!
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much for the kind words :)
@dushkin_will_explain
@dushkin_will_explain Жыл бұрын
This was great!
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much 😊 please like, subscribe and share :)
@monireol
@monireol Жыл бұрын
Awesome
@fenglema36
@fenglema36 Жыл бұрын
Thanks, please like, subscribe and share :)
@Ivan-fz3ou
@Ivan-fz3ou Жыл бұрын
awesome work man 👍 just curious, what crossover and mutation methods did you use?
@fenglema36
@fenglema36 Жыл бұрын
nothing special but there is a simple rule very early on which will flush and kill generations early on if the starting weights don't procedure could results after 100 generation. Then I think there is a branch of 4 types of mutation that decay a little bit over time. Cross-mutation Inc weight Flip weight Inc weight toward other weight Think of a CPU architecture for predicting, if it makes an error it flushes the whole pipe line. I currently believe optimal starting weights will give you the optimal outcome of the network.
@moisekazembe7894
@moisekazembe7894 Жыл бұрын
I grew up playing this game and never knew that there was a winning condition.
@macgyver1761
@macgyver1761 8 ай бұрын
Çok güzel olmuş tebrikler. ❤🎉
@joe415ful1
@joe415ful1 Жыл бұрын
Chilling as fuck how AI learn so fast! Applications for this are great but dude it's chilling how a machine can do anything better than you and still learning so far
@a123b123c123d123c123
@a123b123c123d123c123 Жыл бұрын
That isn't the AI learning. it's the AI playing based on what it's learned.
@mango_doto356
@mango_doto356 Жыл бұрын
That was fun!
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much 😊 please like, subscribe and share :)
@AM-zy8me
@AM-zy8me Жыл бұрын
Awesome bruh
@fenglema36
@fenglema36 Жыл бұрын
Thanks, please like, subscribe and share :)
@grandmasterglick5895
@grandmasterglick5895 Жыл бұрын
Snake singularly
@magnuswootton6181
@magnuswootton6181 Жыл бұрын
whats the lighting the cells up can just be ordinary resistors, if you keep the amping theoretical through the net and just amp it once at the end.
@MiscStuff225
@MiscStuff225 Жыл бұрын
Wow. This is mind blowing.
@fenglema36
@fenglema36 Жыл бұрын
Thanks, please like share and comment
@LightCrasher
@LightCrasher Жыл бұрын
I went up to like, 80% phase of that) GG
@itx_nitin
@itx_nitin Жыл бұрын
Such a great guy you are....I love it❤️ but how do you programmed it?
@fenglema36
@fenglema36 Жыл бұрын
I am trying to work on a tutorial
@alexwagner8433
@alexwagner8433 Жыл бұрын
hello, a doubt I can only develop a neural network for specific things? what if i want it to do another function?
@sederonveyll8409
@sederonveyll8409 Жыл бұрын
Looks cool, what did you use for visualising?
@fenglema36
@fenglema36 Жыл бұрын
Everything was hand written. The drawing is done in openGL with module I wrote for the snake game and the NN
@Acharya_Slideshare
@Acharya_Slideshare Жыл бұрын
Bro the algorithm ai used is kinda next level zero error
@doctorshadow2482
@doctorshadow2482 Жыл бұрын
Thanks. So, is the source code available? If not, could you please explain the inputs? It is hard to understand their meaning from the video, namely what data from the box on the right should be sent to the inputs. Additionally, on the outputs: are they real world directions on the map or they are relative to current snake's head direction?
@a123b123c123d123c123
@a123b123c123d123c123 Жыл бұрын
Numbers 0 to 7 represent those 8 lines drawn out from the head of the snake. 0↖ 1⬆ 2↗ 3➡ 4↘ 5⬇ 6↙ 7⬅ For each of those numbers, there is a Distance, Apple, and Snake. Distance: The distance value indicates whether or not there is at least one open block of space in that direction relative to the head of the snake. Apple: This value indicates when the head of the snake is in line with the apple. Snake: This value indicates if there is a section of the snake directly next to the head of the snake in the direction specified by the number. Then you have numbers 8 and 9 which represent the direction that the head and tail are traveling. The values on the right are the direction in which the neural network will move the snake next. Those unlabeled nodes in between the left and right nodes are the hidden layers of the network and will be adjusted by some function allowing the neural network to learn.
@doctorshadow2482
@doctorshadow2482 Жыл бұрын
@@a123b123c123d123c123 , thank you. Now this is much clearer. From your nickname I can't be sure if you are the author of the video, anyway, since you have good insight, could I ask another question? The selection of input and output format is quite critical for Neural Network (NN) processing and getting correct results. Why exactly the binary representation for inputs were chosen? Why don't they use real numbers for distance? This looks more natural and can give more information to NN, does binary representation have its own benefits (like stronger input influence than gradual value)? Can you please, comment?
@a123b123c123d123c123
@a123b123c123d123c123 Жыл бұрын
@@doctorshadow2482 I am not the author so the info I give is just what I can tell or guess from watching the video. An integer value may be more useful for an AI but it also may be necessary. From what I can tell the Distance values just indicate whether or not the snake can move in a particular direction without hitting something. Also, binary values might suit the algorithm used better. Also the more complex the input the greater the processing power required.
@doctorshadow2482
@doctorshadow2482 Жыл бұрын
@@a123b123c123d123c123 , thank you for the prompt feedback. One comment, per my experience, in NN processing both binary and real inputs have the same processor power consumption, since the binary signal just converts into 0.0 and 1.0 of real number. So, this is just representation matter and this could affect the neurons triggering, but not the required processor power.
@a123b123c123d123c123
@a123b123c123d123c123 Жыл бұрын
@@doctorshadow2482that 0.0 and 1.0 are probabilities. It represents a certain weighting for a specific state. If you wanted to keep track of the actual distance using this method you would need a binary value for every distance increment. That would greatly increase the number of inputs and would increase the processing power required.
@etienne8382
@etienne8382 Жыл бұрын
Love the way they represented the neural net.
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much, alot people asked me for the code to draw then NN, but everthing was handwritten
@etienne8382
@etienne8382 Жыл бұрын
@@fenglema36 always wonder if there has been any changes in the algorithm that calculates the weighting for each node the last 20 years or how the nodes are structured. Haven’t played around with it for years. But will always remain something cool to work with.
@fenglema36
@fenglema36 Жыл бұрын
​@@etienne8382 to my knowledge networks are just becoming bigger as we can do a lot more compute now then 20 years ago. But Backdrop is still the most used for training networks..... I might be wrong as I am relatively new to A.I
@alexfourie-tn2sb
@alexfourie-tn2sb Жыл бұрын
Awesome video, got a question though. I dont quite understand how the snake is learning in the video if theres only a single snake on screen (also no generation count), along with the fact that it seems to play almost perfectly from the start of the video. I ask since I made a flappy bird game with neuroevolution and it took a couple hundred generations to play perfectly.
@fenglema36
@fenglema36 Жыл бұрын
This model is already trained. It trained for about 8 hours with a Genetic algorithm.
@j23anderson17
@j23anderson17 Жыл бұрын
Beautiful
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much 😊 please like, subscribe and share :)
@kevinchahine7553
@kevinchahine7553 Жыл бұрын
That's really awesome
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much 😊 please like, subscribe and share :)
@BarnardBandFuinthePB
@BarnardBandFuinthePB Жыл бұрын
The neural mind is very complex just for left/right up/down :o (So that means we have to appreciate to what we've been given, Because Remaking it is more complex than what You can say)
@fenglema36
@fenglema36 Жыл бұрын
Feels like my daily routine Left, right, up and down.
@leightonjarratt9294
@leightonjarratt9294 Жыл бұрын
I’ve got anxiety watching it chase it’s tail 🤣🤣
@ritik_shah
@ritik_shah Жыл бұрын
Amazing 😮
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much 😊 please like, subscribe and share :)
@haneeshallu4488
@haneeshallu4488 Жыл бұрын
Great work! What's the input data set that was used?
@bt6202
@bt6202 Жыл бұрын
Mind Blown - Poooof!
@fenglema36
@fenglema36 Жыл бұрын
thanks, please like subscribe and share :)
@Milesmorales6969
@Milesmorales6969 Жыл бұрын
So good
@fenglema36
@fenglema36 2 ай бұрын
Thank you so much, please like share and comment
@mikhailglukhov6680
@mikhailglukhov6680 Жыл бұрын
Does it use a pure neural network, or are there additional algorithmic rules coded? Like avoiding obstacles, etc.
@fenglema36
@fenglema36 Жыл бұрын
The neural network is trained with a genetic algorithm. The generation with the best fitness is who ever takes the most steps and gets the most apples. I think the only rule on the fitness test is: you have 100 steps to collect and apple, then the steps reset. So he theory is longest path to the apple.
@grantleland6913
@grantleland6913 Жыл бұрын
@ezra anderson I think it would be interesting to use a Q learning approach. Like you mentioned an Actor Critic network would be a cool algorithm to implement for snake. I’m assuming you would be able to get results much faster from a Q algorithm trained by Adam than a genetic algorithm especially since you have a well defined reward. Figuring out the inputs for this would be more tricky since NNs do well with continuous state spaces and snake is more of a discrete state space. Perhaps using all 100 block values as an input could work well for this type.
@Gabranthh
@Gabranthh Жыл бұрын
Those are decently fast reactions, almost as good as mine.
@user-bm9jo5uy3b
@user-bm9jo5uy3b Жыл бұрын
This is so cool, what is the reward mechanism for your agent?
@fenglema36
@fenglema36 Жыл бұрын
it's really simple fitness test on the agent that lives the longest moves * appless
@SurveryorPlays
@SurveryorPlays Жыл бұрын
I've only seen snake beatin one time back when I was small child in the 90s after that not even close
@me7512
@me7512 Жыл бұрын
Blew my mind actually
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much 😊 please like, subscribe and share :)
@theSpicyHam
@theSpicyHam Жыл бұрын
great!
@fenglema36
@fenglema36 Жыл бұрын
Thanks
@adsa4269
@adsa4269 Жыл бұрын
What does the first layer represent. The distances in 8 directions i believe, and that more ?
@CHRISBROWN-qk5gq
@CHRISBROWN-qk5gq Жыл бұрын
VERY NICE
@fenglema36
@fenglema36 Жыл бұрын
Thank you so much 😊 please like, subscribe and share :)
@OOOOOOOOOOOOOOOOOOOOOO333
@OOOOOOOOOOOOOOOOOOOOOO333 Жыл бұрын
Переживал за эту змейку больше чем за свою жизнь
@Uninstantfige
@Uninstantfige Жыл бұрын
OMG … this was so satisfying !!!
@fenglema36
@fenglema36 Жыл бұрын
Thanks you so much I also find it satisfying. please like, subscribe and share :)
@brightside5626
@brightside5626 Жыл бұрын
I love your video.
@fenglema36
@fenglema36 Жыл бұрын
Thank you, please like subscribe and share :)
@alexseveryanov1725
@alexseveryanov1725 Жыл бұрын
Nice work for sure, but just to win the game you don’t need to have an AI algorithm, simple movement algorithm is quite easy to program to just win the game. What would be cool to see is that how different AI models to achieve winning state and which one do it better/faster. Because on the early stage of the game there still a lot movements to improve. Anyway, good work and it was interesting to watch!
@fenglema36
@fenglema36 Жыл бұрын
Thank you. I Agree other algorithm would work, and this is overkill. I would like to do this project again based on different training methods, for example shortest path, longest path and Hamiltonian cycle.
@alexseveryanov1725
@alexseveryanov1725 Жыл бұрын
​ @ezra Anderson Thank you for doing this, that would be very interesting to watch how differently other algorithms solve the same task. Once again, thank you for your work
@user-fh3wg8oj6q
@user-fh3wg8oj6q Жыл бұрын
@@fenglema36 which data did the AI algorythm was training
@bramweinreder2346
@bramweinreder2346 Жыл бұрын
I actually think it was quite efficient. Making detours to avoid hitting its tail later, and finding shortcuts when applicable. If the AI learned this on its own then it's definitely ways ahead of a preprogrammed path with efficiency hacks. But if the path was programmed in as a bias, then it's still impressive, just not abstract machine thinking.
@revimfadli4666
@revimfadli4666 Жыл бұрын
Looks far more successful than most NN snakes I've seen. What was the training algorithm? And what were the sound pitches based on?
@feywiild
@feywiild Жыл бұрын
I think the sound pitch is based on the field, the head of the snake is on. When it moves up, the pitch goes down and when it moves down, the pitch goes up. Just my guess though.
@fenglema36
@fenglema36 Жыл бұрын
The pitch is just a representation for the current grid location. 100 tones for this video. Its the only method I could think of to represent the network sound.
@Matthew_Robert_Hunt
@Matthew_Robert_Hunt Жыл бұрын
I’d be so nervous on those last few bits.
@fenglema36
@fenglema36 Жыл бұрын
autopilot - and yeas its nerve racking
@vvmm3712
@vvmm3712 Жыл бұрын
Really impressive. Which tools have you used for visually representing the neural net and the snake board?
@fenglema36
@fenglema36 Жыл бұрын
This is a handwritten neural network framework written by me in delphi (pascal). The NN and the snake game were written in 2020 Covid lock-down. Once returning to work I never got around to posting it. I dug up the framework a few months ago to work on convolution kernels, and decided to post this.
@yassineaguelmam8674
@yassineaguelmam8674 Жыл бұрын
@@fenglema36 genius
@fenglema36
@fenglema36 Жыл бұрын
Thanks
@kurtdewittphoto
@kurtdewittphoto Жыл бұрын
I think I could go to sleep to the sound of this video.
@fenglema36
@fenglema36 Жыл бұрын
I feel like I would have nightmares if I did that,
@minhhuynh362
@minhhuynh362 7 ай бұрын
Great video, so what are your settings? Like batch size, max playback buffer size, gamma, learning rate, layer activation?
@fenglema36
@fenglema36 2 ай бұрын
This uses a genetic algorithm for training. I did start and actor critic version but it was never completed.
@yequene
@yequene Жыл бұрын
Impressive. I also didn't know you could win.
@fenglema36
@fenglema36 Жыл бұрын
Thanks, please like and share :)
@oxfaaaaa9687
@oxfaaaaa9687 Жыл бұрын
I have a question. Obviously, there is an easy intuitive winning algorithm for snake. Does ai finds it optimal win-path? Or in this case simple algorithm is better?
@a123b123c123d123c123
@a123b123c123d123c123 Жыл бұрын
You could probably make a more efficient algorithm. This video isn't actually showing you the AI learning.
@fenglema36
@fenglema36 Жыл бұрын
no it is not optimal. But I am trying to learn Neural Network and this seamed like a fun idea
@Anonymous08398
@Anonymous08398 Жыл бұрын
Machine played himself
@fenglema36
@fenglema36 2 ай бұрын
Yep
@apcook34
@apcook34 Жыл бұрын
It doesn't have to worry about hand eye coordination...great advantage for it.
@fenglema36
@fenglema36 Жыл бұрын
or two left thumbs
@grimreaper6785
@grimreaper6785 Жыл бұрын
I don't know much about ML . But I did a CNN Image classifier. Sry If this comes as a dumb question but does the snake know where the next bite(red thing) is going to spawn . I mean aren't there any configurations in which whatever it does it needs to bite itself.
@a123b123c123d123c123
@a123b123c123d123c123 Жыл бұрын
The Snake detects the appl/red thing when it moves in line with it. Look at the labels on the input layer (left-hand side). When the head lines up with the apple the corresponding Apple node lightes up.
@fenglema36
@fenglema36 Жыл бұрын
When training it bites itself a lot until it learns not to, the apples are spawned at random
@gordonfrommalmak
@gordonfrommalmak Ай бұрын
Thanks for showing the inputs of the network. What kind of learning algorithm is behind it?
@fenglema36
@fenglema36 4 күн бұрын
a very clunky genetic algorithm, I think actor critic would be better but I have not had time
@kevinb2738
@kevinb2738 Жыл бұрын
I programmed this as well, and realized very quickly how many inputs were needed to give the snake “vision” like you have done. Do you think it would have worked better to just have the contents of every block be the input? I wanted to go down that path but never followed through.
@fenglema36
@fenglema36 Жыл бұрын
Pixels(Blocks) would be more difficult to get to work. In the snake game I wrote you can request "Pixels" or "Sensor" for the inputs of the Neural Network. When building this framework I focused on less data points. Meaning the inputs of 32 sensors vs 100 pixels(10x10) allowed it to train much faster. I would like to create an Actor Critic model which uses the inputs of Pixels, but have not been able to do it.
@MrAzureAzure
@MrAzureAzure Жыл бұрын
​​@@MrMrmalobaidi I am curious as well. From the look of it, his inputs were 1x3 categorical array 0 distance - empty space or not 1 apple - the apple or not 2 snake - its skin or not on 8 directions around the snake's head (we got 24) concatenated to 1x4 directional array of snake's tail and head 0 up 1 right 2 left 3 down (24+8=32) Still impressive on how AI could learn to develop a strategy on given parameters
@fenglema36
@fenglema36 Жыл бұрын
Bingo, that is a perfect explanation!
@chrisjfox8715
@chrisjfox8715 Жыл бұрын
I'm confused as to how a NN is the right tool for this
@fenglema36
@fenglema36 Жыл бұрын
It probably not the best algorithm for this task.. But I hand wrote an NN framework and thought this would be a cool thing to try to do.
@Purplehain
@Purplehain Жыл бұрын
Damn, AI accomplished what I always tried to achieve.
@henryandrewmedinacondo9279
@henryandrewmedinacondo9279 Жыл бұрын
Niceeeeee
@fenglema36
@fenglema36 Жыл бұрын
Thanks, please like and Share :)
@davidanderegg1232
@davidanderegg1232 Жыл бұрын
Never realized how easy the last bit of snake is
@fenglema36
@fenglema36 Жыл бұрын
I was also surprised by this. Apparently there is a very easy pattern.
@davidanderegg1232
@davidanderegg1232 Жыл бұрын
@@fenglema36 if the map was odd x odd it’d be harder. Also perfect turns are difficult for a real person
@NeoTheOne41
@NeoTheOne41 Жыл бұрын
That's dope!
@fenglema36
@fenglema36 Жыл бұрын
500lb squat that's dope! Beast mode!
@NeoTheOne41
@NeoTheOne41 Жыл бұрын
@@fenglema36 lol thanks
@andreathompson9605
@andreathompson9605 Жыл бұрын
I love that game
@LifeIsCrazyAsShit
@LifeIsCrazyAsShit Жыл бұрын
This is how my dad play video game in his childhood
How to Win Snake: The UNKILLABLE Snake AI
17:05
AlphaPhoenix
Рет қаралды 2,2 МЛН
小女孩把路人当成离世的妈妈,太感人了.#short #angel #clown
00:53
MEGA BOXES ARE BACK!!!
08:53
Brawl Stars
Рет қаралды 32 МЛН
AI Learns the Numbers
8:04
Green Code
Рет қаралды 266 М.
AI Learns to Play Tag (and breaks the game)
10:29
AI Warehouse
Рет қаралды 1,6 МЛН
Neural Network Learns to Play Snake
7:14
Greer Viau
Рет қаралды 4,5 МЛН
How Dijkstra's Algorithm Works
8:31
Spanning Tree
Рет қаралды 1,3 МЛН
Visualize Sorting Algorithms - Part 3
2:38
ezra anderson
Рет қаралды 260
AI Learns to play Geometry Dash || FINAL
11:51
CodeNoodles
Рет қаралды 234 М.
AI Learns to Escape (deep reinforcement learning)
8:18
AI Warehouse
Рет қаралды 7 МЛН
AI Learns To Play Golf
13:57
b2studios
Рет қаралды 523 М.
Mnist - Neural Network #neuralnetworks  #machinelearning
2:00
ezra anderson
Рет қаралды 683
A.I. Learns to play Flappy Bird
7:46
Code Bullet
Рет қаралды 14 МЛН
小女孩把路人当成离世的妈妈,太感人了.#short #angel #clown
00:53