Тёмный

AI Battle Royale of 100 SNAKES in C++ - SFML Gamedev - Devlog 

Kofybrek
Подписаться 10 тыс.
Просмотров 21 тыс.
50% 1

I made a genetic algorithm that learns to play the Snake game using C++ and SFML. Then I made 100 snake AIs fight with each other in Battle Royale.
Discord: / discord
Github: github.com/Kofybrek
Itch io: kofybrek.itch.io
Patreon: / kofybrek
Subreddit: / kofybrek
Twitter: / kofybrek
Code: github.com/Kofybrek/Snake-gam...
#code #coding #programming

Опубликовано:

 

1 июл 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 124   
@Kofybrek
@Kofybrek Год назад
Hope you enjoyed this video! if you did, please press that like button and subscribe for more content like this. It costs you nothing, but for me it's everything! Consider supporting this channel on Patreon for exclusive content as well as early access to future videos and projects: www.patreon.com/Kofybrek
@teriu
@teriu Год назад
Love it
@teriu
@teriu Год назад
Next video idea a street fighter clone
@imperatusmauser7096
@imperatusmauser7096 Год назад
@@teriu Agreed, I would love to see that
@revimfadli4666
@revimfadli4666 Год назад
I wonder how well would the snakes perform with 2 hidden layers(or a cascaded hidden layer where each node receives from all previous nodes in its layer, computed sequentially). I mean, Chrispresso and 1 other guy managed to completely win Snakes with it, so imagine having them in a battle royale...
@adamebadra3171
@adamebadra3171 Год назад
I just noticed that the video is new, I watched it about 2 Times and I recommend putting a path finding algorithm in one o the snakes than see the result😶
@soykiokin
@soykiokin Год назад
Ready for 14 minutes that will go by very quickly :(.
@agentkosticka17
@agentkosticka17 Год назад
Just 13 minutes and 15 seconds left :(
@aintNexus
@aintNexus Год назад
2:30 "i wish i had that button >:)" got me dying LOL
@Caal
@Caal Год назад
I love how Daniel killed himself immediately right after winning
@ChrisVideosGreek
@ChrisVideosGreek Год назад
l love how snakes managed to generate food at a point LMAO
@The_Dr_Fate
@The_Dr_Fate Год назад
where, when
@revimfadli4666
@revimfadli4666 Год назад
Lol I guess the heads shouldn't also convert into food, that way the number of food + body segments is conserved
@revimfadli4666
@revimfadli4666 Год назад
@@The_Dr_Fate when dying snakes were set to turn into food
@ChrisVideosGreek
@ChrisVideosGreek Год назад
@@revimfadli4666 l agree
@MEGAndreas925
@MEGAndreas925 Год назад
I have a feeling this was done in paint. And i love it. Earned my subscription
@soykiokin
@soykiokin Год назад
01:26 I love the snake face xD.
@Natural_Power
@Natural_Power Год назад
If the snakes had better vision they could probably evolve rather complex strategies If it's not too laggy make their vision like a 9×9 block (larger = better) of all the tiles around them, and differentiate between walls, themselves and other snakes
@Kofybrek
@Kofybrek Год назад
From my experience, increasing the number of inputs makes them perform worse. Maybe I'm wrong though.
@barni_7762
@barni_7762 Год назад
@@Kofybrek Because genetic algorithm can't handle it... (deep) Q-learning should do the trick though if you take the time to build an AI with it
@barni_7762
@barni_7762 Год назад
@@Kofybrek Also, one question about the genetic algorithm you used: did you actually set some weights to have new random values during mutation or did you add gaussian noise to them like a sane person?
@Kofybrek
@Kofybrek Год назад
@@barni_7762 ...I just set a new random value.
@barni_7762
@barni_7762 Год назад
@@Kofybrek Lol ok I'm surprised it converged that well... I'm not an expert at this topic but my reasoning is that you want your policy (ai) to converge to a good policy, and when your policy is already not too bad, adding some small random values to a few parameters might bring it closer to where those parameters should be, kind of like gradient descent except you generate random gradients and hope they're good... On the other hand, your parameters might already be close to where they should be but not quite there, and the right amount of noise would nudge them closer to there (if they should be increased, note there's a 50% chance of the noise value being positive, so pretty good), while setting it to any random value has a very low probability of getting it closer to where it should be if it already is close. That's just my reasoning though and I might be missing something, also reality sometimes doesnt like reasoning and instead prefers random bs like it does with the lion optimizer (which is better than adam, previous SOTA, but only uses the sign of the gradient to update, which is nuts)
@erichansen9669
@erichansen9669 Год назад
Keep up the content man, this was great! Informative but not dry in the least. Also, I'm sad James didn't win. :(
@olivierk4913
@olivierk4913 Год назад
Great video! Good balance of explanations, practical examples, creativity and fun :) Keep up!
@gorlix
@gorlix Год назад
i love this video, the way you explain how AI weights&mutation works is very cool, thank you
@Fulbion
@Fulbion Год назад
First I thought you were gonna use Network module from SFML... But the video is still really good! GG to Daniel who is the top 1 snake and the first one to win this tournament!
@cyberhax2480
@cyberhax2480 Год назад
I love this video omg its my favourite! You are so entertaining and i love your voice!
@DrEnzyme
@DrEnzyme Год назад
You are so underrated. This was an awesome video and now I want to go and build my own neural network generational thingy.
@cmdprmptexe
@cmdprmptexe Год назад
Eyo. As usual, great content! Looking forward for more :D
@twistedillusion-u4s
@twistedillusion-u4s Год назад
i think it would be better if you could make a sprite for the head, to make it easier to know the difference between the tail and the head
@Kofybrek
@Kofybrek Год назад
Yeah, you're right. For some reason, I forgot to do it.
@kenan2386
@kenan2386 Год назад
New video! Great as always
@ezranYT
@ezranYT Год назад
This was such a good video so you earned a sub
@C0playeR
@C0playeR Год назад
Very cool video 😎 I made a snake game myself (smfl ofc) It got tricky when i added bridges but it looks sick
@ThePenguinsKing
@ThePenguinsKing Год назад
I love the little character you use
@ZimmoYT
@ZimmoYT Год назад
So happy new vid is out :D
@omercengiz8507
@omercengiz8507 9 месяцев назад
I don't remember the last time I laughed at a coding video. Very successful video.
@WeirdInstrumentalGuy
@WeirdInstrumentalGuy 8 месяцев назад
This is a banger video
@4n0nym0u5
@4n0nym0u5 Год назад
Dude this shit is too funny I almost choked. HEY! THAT'S ENOUGH! *patting snake on the head* LOL
@KDovsky
@KDovsky Год назад
I love these videos
@Ktos877
@Ktos877 Год назад
Wow, awesome!
@Akbar-yr8lq
@Akbar-yr8lq Год назад
Amazing video. I bet for snake number 22, almost got the gold medal ❤
@AjinGixtas
@AjinGixtas Год назад
Can't believe you write bracket in a separate line. (Great video though)
@wenelol
@wenelol Год назад
These videos make me want to try making something with sfml once again
@Gonebyebye888
@Gonebyebye888 5 месяцев назад
'The code is super simple so I wont explain it to you' Me: wait how does it work 👁👄👁
@onemoremagistr
@onemoremagistr Год назад
The greatest!
@DeathAtYourDoorStep
@DeathAtYourDoorStep Год назад
good stuff
@TheSelfUnemployed
@TheSelfUnemployed Год назад
I made snake using SDL2 not too long ago and now I want to try and adding some AI to it.
@aronimo5800
@aronimo5800 Год назад
daaaamn, ai battle!
@otistically
@otistically Год назад
6:28 ✨ n a t u r a l s e l e c t i o n ✨
@ihavenoaura
@ihavenoaura Год назад
You should make a project using SFML and OpenGL
@legohistory8039
@legohistory8039 Год назад
Top!!!
@user-qh3nq8np5i
@user-qh3nq8np5i 11 месяцев назад
"i wished i had that button" lmao!!!
@a.j.outlaster1222
@a.j.outlaster1222 8 месяцев назад
Remember your raycaster? What about an fps with it's movement, So if we have like seven teams and they all shoot each other(In 2d) and then seeing which team does best, When only one remains, All teams are regenerated using the brains of the best two of their color(Like the snakes here) For extra flair, Perhaps the individual agent with the most kills could get a small section on the screen to render their view. 🙃
@aronimo5800
@aronimo5800 Год назад
i hope for an actuall 3d sometime, or a long series/video on some amazing clone like terraria/minecraft/dont starve
@_shadownotes_
@_shadownotes_ Год назад
I made a snake game using just text. All you have to do to prevent the snake from moving 180° is check to see if a snake body already occupys that cell.
@Kofybrek
@Kofybrek Год назад
But that won't work if the length of the snake is 1.
@_shadownotes_
@_shadownotes_ Год назад
​@Kofybrek to me that makes sense though, because the snake can't flip 180, cause the body is in the way. But if there's no body, it has freedom to move. Also if you attempted a 180 you would die... I don't remember if that's what my final product did. I'll have to check. Love your videos! I just found you and you have a new sub.
@mcools3278
@mcools3278 Год назад
Nice snacks
@Davi_Dash
@Davi_Dash Год назад
nice cometari
@Marvermoe
@Marvermoe Год назад
Y͛o͛u͛ make such good vids!
@VaibhavShewale
@VaibhavShewale Год назад
AI will took over the world but will not able to play snake game
@Kofybrek
@Kofybrek Год назад
Lol exactly!
@matthewkeen6281
@matthewkeen6281 Год назад
NIce
@otistically
@otistically Год назад
It's good that Kang Daniel had won the battle royale 😁😁😁
@jakub.kantner
@jakub.kantner Год назад
holly molly my snake won! :D
@aaravsethi6070
@aaravsethi6070 Год назад
2:46 real men make their own random system from scratch using atmospheric data
@devmarboy4045
@devmarboy4045 Год назад
wish I was this advanced wit c++ lol
@Eliotus10
@Eliotus10 Год назад
are you using aseprite to make some animations for your viedos ?🤔
@Kofybrek
@Kofybrek Год назад
Yes.
@vladimirtchuiev2218
@vladimirtchuiev2218 Год назад
Have you tried training the network via reinforcement learning (PPO for example)?
@Kofybrek
@Kofybrek Год назад
No, I haven't. Sounds interesting though.
@revimfadli4666
@revimfadli4666 Год назад
I think evolution strategies would be much easier to implement
@AYSMOKASHI
@AYSMOKASHI 7 месяцев назад
Snake 24 place 4 I had to look the position at leader board as i am color blind i cant diff between similar colors so i forgot which was mine but i knew the # So yea Les go😎😎
@irwe3514
@irwe3514 Год назад
it's not cool, but it's very interesting how it algimetrically works
@gaggix7095
@gaggix7095 Год назад
What activation function did you use instead of yours? Without the activation functions the neural network will have the same expressiveness of a single linear layer, adding more layers don't really do anything.
@Kofybrek
@Kofybrek Год назад
I didn't use any others. And I don't think using them is gonna change something.
@gaggix7095
@gaggix7095 Год назад
@@Kofybrek I mean there is usually a huge difference between a simple linear projection and an actual neural network. Add something simple like ReLU or remove the hidden layers because they don't actually do anything in this case.
@defini7
@defini7 Год назад
Hi! what does the i_ prefix in variable names mean?
@Kofybrek
@Kofybrek Год назад
it's short for "input".
@defini7
@defini7 Год назад
@@Kofybrek thank you, very useful prefix btw
@yahia1355
@yahia1355 Год назад
I do not know about you but WHY IN THE WORLD you put the constant value before the variable when comparing them in an if/while statement and prob in a for ?
@Kofybrek
@Kofybrek Год назад
It just looks better to me.
@Eren_Yeager_is_the_GOAT
@Eren_Yeager_is_the_GOAT Год назад
cool video, how did you learn to create AI in C++?
@Ezdiess
@Ezdiess Год назад
AI is not language deoendent. Its pure maths
@Eren_Yeager_is_the_GOAT
@Eren_Yeager_is_the_GOAT Год назад
@@Ezdiess alright then where did he learn those maths
@revimfadli4666
@revimfadli4666 Год назад
@@Eren_Yeager_is_the_GOAT my journey began with some genetic algorithms on RU-vid. Then I followed backprop tutorials online. Then learned about momentum and reinforcement learning I suggest starting with evolution strategies, it's super simple like genetic algorithm, yet can be more powerful than backpropagation
@Eren_Yeager_is_the_GOAT
@Eren_Yeager_is_the_GOAT Год назад
@@revimfadli4666 thanks 😊
@sootguy
@sootguy Год назад
no rectangle is not more efficient if you want to fill 800x600 window with 32x32 rectangles this will take around 470 iteration per second on other hand lines would take only 40 iteration :)
@codexity
@codexity Год назад
yeah exactly!
@Kofybrek
@Kofybrek Год назад
Damn, you're right! I didn't think about it that way.
@anon_y_mousse
@anon_y_mousse Год назад
Funny, but everyone knows that the first snake is supposed to be named Jake and the second one is Sammy.
@abdullah44925
@abdullah44925 6 месяцев назад
Whered you learn this
@Kofybrek
@Kofybrek 6 месяцев назад
On the internet mostly.
@TheSkepticSkwerl
@TheSkepticSkwerl Год назад
You are a smart smart man. But when I saw "if (50 == generation)" I nearly died. Who puts 50 first?!?!?! WHY!!
@Caal
@Caal Год назад
I believe its call "Yoda notation" it is useful to avoid some kind of unintended compilations which can result to bugs insanely hard to find if I remember correctly
@mstfmrt07
@mstfmrt07 Год назад
exactly!
@Kofybrek
@Kofybrek Год назад
Yeah, I'm weird.
@mizakira777
@mizakira777 10 месяцев назад
music plsssss
@ArThur_hara
@ArThur_hara 11 месяцев назад
6:19 😂😂😂😂😂😂
@SabeDoesThingsChannel
@SabeDoesThingsChannel Год назад
You should make something in raylib
@anubhavjha7704
@anubhavjha7704 3 месяца назад
My bet on snake #26 got 26th rank.
@Logicatube
@Logicatube Год назад
Ураа змейка против змейки, лол
@fuchsorsolya6722
@fuchsorsolya6722 2 месяца назад
Why does nobody realise that his voice is lower?
@Djellowman
@Djellowman Год назад
Why would they be better without an activation function? that's very weird..
@symynn2734
@symynn2734 Год назад
make 3d game in sfml pls
@asfaqahmedsiddique4811
@asfaqahmedsiddique4811 Год назад
Can you make tic tac toe ai?
@Kofybrek
@Kofybrek Год назад
You can use the Minimax algorithm to achieve it. It's very easy to do.
@asfaqahmedsiddique4811
@asfaqahmedsiddique4811 Год назад
@@Kofybrek Your videos are great. I like those very much. Most of the content creators are commercial instead of being aesthetic. Hope you do greater in the future.
@johnstorm589
@johnstorm589 Год назад
Bro
@lagunov-lev
@lagunov-lev Год назад
Было бы интереснее, если бы змеи могли размножаться
@hobrin4242
@hobrin4242 Год назад
wait why do real men use random?
@soykiokin
@soykiokin 9 месяцев назад
It's a joke, and "rand()" is less accurate than the random library.
@zefir8299
@zefir8299 Год назад
Жаль я не понимаю английский (
@space_nerd9456
@space_nerd9456 Год назад
LOL writing an ai in c++ instead of python BORING
@space_nerd9456
@space_nerd9456 Год назад
@@themightycxzeriallord Ohh... i mean you a right and i would love to keep my ribs pls.. xD
@anon_y_mousse
@anon_y_mousse Год назад
I would've preferred C, but not everyone is ready for that. However, Python would be the worst choice.
@space_nerd9456
@space_nerd9456 Год назад
@@anon_y_mousse python is actually the best choice when it comes to data sience and ai
Далее
Schoolboy - Часть 2
00:12
Просмотров 9 млн
I Built 3 SECRET Rooms In School!
33:34
Просмотров 18 млн
I simulated a Pokemon Battle Royale using AI
7:50
Просмотров 43 тыс.
AI Learns How To Play Doodle Jump
12:02
Просмотров 67 тыс.
Much bigger simulation, AIs learn Phalanx
29:13
Просмотров 2,7 млн
Making SPACE INVADERS in C++ - SFML Gamedev - Devlog
12:56