Creating the PERFECT Connect 4 A.I.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Yooo I love code bullet.

👍︎︎ 3 👤︎︎ u/Beefy2606 📅︎︎ May 04 2022 🗫︎ replies
Captions
ladies and gentlemen today will be a day for the history books humanity has achieved great things for putting men on the moon to turn in the frickin frogs gay for today we're making an ai for the most intense high octane frog gay-a-fying badass game in existence today we are doing good x4 [Music] oh [ __ ] [Music] [Applause] [Music] so yeah connect4 i'm sure you know it i'm sure you love it it's the game that truly separates the men from the little baby [ __ ] boys and today i don't plan on being a little baby [ __ ] boy so let's get right into it actually no [ __ ] that let's explain some [ __ ] first all right what the [ __ ] are we actually doing here there's an online connect for community which plays on paper games dot io and the plan is to create an ai to make little baby [ __ ] boys of even the best of players this is episode 2 of my bullying nerd series which is now actually a series susan please don't hurt me it's a joke last time i took the lunch money from everyone in the tetris community but uh oh looks like my wallet's empty again and there is a ripper bake sale going on so we must strike once more okay intro done protagonist motivations are established now let's get into the action and by action i mean programming which is very synonymous okay let's go first off i need to recreate connect four well i mean i don't need to but it'll help a lot with testing and [ __ ] i know i mean come on it's connect four it's not that hard i mean action testosterone explosion oh hell yeah we got a white window next one me yeah now let's add some connects four to that window wow squares wow circles wow red circles could this game get any more interesting now we need to make the player up [ __ ] off norton now we just need to make the player after circles oh [ __ ] [Music] hey isaac hey what's up apple apple apple apple apple apple and apple apple apple yeah baby now just add math and [ __ ] to check if either player got a connect four and uh uh uh we're done steamed on and i'm gonna sell the [ __ ] down because i wasn't gonna have a heart attack before i finish the video okay the game is done now it's time to talk ai connect four is a solved game which means that given any board it is possible to mathematically calculate the best possible move this is done using an algorithm called the minimax algorithm oh i know very impressive okay explanation time disclaimer the explanation you're about to hear is not very good and should not be used as educational content under any circumstances if erection lasts longer than four hours sigmatical attention okay here we go say we've got this board position how do we calculate the best move in this situation oh i have an idea let's generate all the possible moves we could make like this well what now oh i know for each of these moves let's generate all the possible moves the opponent can make like like this okay very good and then for each of those boards we can generate all possible moves we can make okay and then for those pods we can generate all the possible moves we can make okay i think i'm set to get pat and then for each of those boards we could generate all the possible moves we could make and i'm just gonna mute him okay are you starting a pattern yet so basically i just give this board to the computer and then the computer goes okay that's programmed up let's see how that goes [ __ ] all right so the problem is this is gonna take forever because it's calculating so many different board positions so the name of the game is optimization and guess who knows a lot about optimization not me uh so guess what time it is plagiarism time okay so this guy is called pascal ponz and he's written a guide to everything you need to know if you want to make it connect for ai which is very convenient if it wasn't for this guy i wouldn't be able to do this because i'm not very good at optimization or programming or connect four so yeah thanks pascal you do good work okay so the first pleasure i mean optimization is mini max with alpha beta pruning oh which is essentially like normal mini max but a bit [ __ ] and once again this explanation is really bad and probably false so just you know heads up essentially there are some moves which are just so obviously bad that there's no way the player will make that move and if they do they're [ __ ] anyway so it doesn't matter this means that we can take the search tree here she is and just cut off a large amount of the branches because those were the moves that there's nowhere the ai will make okay that's coded up let's check on the computer okay still need some work okay pascal what do you have for us you beautiful bastard i would kiss you but i have no lips let me just rest my screen on your face i could get lost in those eyes okay optimization number two is a transposition table wow avenue's big fancy word i don't really know what it means but i do know it's [ __ ] amazing this one i can explain a bit better okay so when we do the whole generate all possible moves for each player thing it's pretty common for the same board configuration to show up more than once for example these are two ways of getting to the same board state okay so this board state and this one are identical which means that when we generate all possible moves we can reach from these positions we're calculating the same moves twice which is a waste of time so to save the day we simply have a big ass table which saved the results from each position and before we generate all possible moves from a position we check the table to see if we've already done it and if we have then we can say [ __ ] you to this position and just grab it from the table all right we have coded that bad boy and whooped up let's check in on our computer [Music] oh we did it [Applause] but i limited the search to only look 12 moves into the future which is pretty far but not nearly far enough so yeah you know what this goal is for more optimization yeah all right let's speed through this optimization speed round change the order in which we look at moves based on how good they are represent each board state using binary to speed up all the calculations add multi-processing so my computer can calculate 16 things at once stop exploring moves we know will kill us immediately stop it fixing like major bugs in all my other optimizations okay let me explain how i'm struggling even though i have like a tutorial that i'm following i'm writing this in python because that's what i'm familiar with and honestly i didn't think too much about the implications the problem with python is that while it's easy to learn it's got a lot of useful libraries it's also slow as [ __ ] pascal was a smart boy and he used c plus plus to code which is known as one of the speediest of boys by the computer science community so c plus plus good python bad it could also be true that i [ __ ] up my implementations of these optimizations and that's also like partially to blame but you know i find that unlikely okay so i've outlined the problem now time for a pop quiz let's see how well you know me to a a rewrite all the code in c plus to give us a massive boost do i be continuating optimizations in python and hoping eventually it will get fast enough to reach the point where we've solved connect four or do c i cheat okay click which option you think i chose [Music] if you clicked option a or b then congratulations [ __ ] you just paused the video and also you don't know me very well do you which means you must be new here which means i probably won't be getting many new subs in this video on the account that i just called you all [ __ ] yeah not my best play uh if you did click c then uh still a video so nice uh and also that's a little insulting uh but you got it you're right so yeah i cheated just a little bit just a little trick depends on your definitions really i was this close to giving up but i had an idea for how i could get the results i want without putting in the work it requires and if you think that i do not take that option in a heartbeat then you actually must be new here and uh hello uh please subscribe this epiphany was reached when i was praying late at night like i always do i asked what would pascal do and then it hit me pascal has a website where he's showing off his algorithm so i just programmed my algorithm to play against his and save all the moves his ai makes then i run that bad boy all weekend and uh booga you got a list of 15 000 optimized moves fantastic now small problem very small it's not huge uh there are 4 trillion 531 billion 985 million 219 092 different possible board configurations in connect four so 15 000 doesn't seem all that impressive and if you give me a random board position the chances of it being in the 15 000 are like 0.00004 percent or something i might have [ __ ] up the number of zeros there but you get the point it's it's low so mathematically speaking i'm [ __ ] but the one thing your boy knows how to do right is true just ask my what i was gonna make a wife joke but we all know that's not a thing okay moving on so i didn't just have my ai play full games against pascal until he racks me no no no i only had games last for six moves and then they would reset this means that the dictionary of 15 000 optimized moves are only for the early game and since there are less discs in play the number of possible combinations are way lower so the chance of a match is way higher this boost or cheat if you will is massive and it can almost always find a move from the library or calculate the best possible move using my ai so the perfect ish connect four algorithm is now complete time for blood okay are you ready the action is about to begin three two one let's go [Music] [Applause] [Music] [Music] [Applause] [Music] [Applause] we did it the most exciting connect 4 montage probably i didn't look it up but that seems likely so yeah some of you might think i cheated a bit in this video and you're probably right and by probably i mean definitely but one thing you don't want to cheat on is a child's education and there's no substitute for hands-on experience and that is where this week's sponsor comes in cuico makes exposing kids to the concepts of science technology engineering and math super simple each monthly crate is designed by experts and tested by kids to teach them a new theme through hands-on learning and fun and is a fantastic resource for learning at home kiwico offers eight subscription lines for different age groups and topics and each box comes with all the supplies you need for that monthly project so no need to run to the store or leave your house at all which is definitely something i could appreciate kiwi guys sent me two crates from the tinkerline and even as a grown man i found them really fun the first one was a walking robot which taught you all about robotics and motors oh yeah oh the second one they sent me was just so cool it's a double pendulum which are famous for producing really chaotic and interesting movement this movement is captured using an led and glow-in-the-dark paint and the result is actually ridiculously cool like i spent way too long playing with this one kilco crates are also a great option for holiday gifts and that's a gift that keeps on giving it's like getting christmas presents every single month which is just fantastic so if you want to support this channel and get an awesome crate every single month then go to code bullet and get 50 off the first month of any crate line you choose thanks again to kiriko for sponsoring this video okay so that that happened that was a video god damn oh my god that was the the [ __ ] about me giving up that was real that was i was so close for this video not being a video like i was like i got like 80 of the way through the program again i'm like what i like i like ran it for the first time and it's like this is not interesting like once you've seen one game of connect four you've seen them all like they all pretty much end the same way and it's not like i can like speed it up because i'm waiting for the other people to play so it's not like the tetris one which can be fast as [ __ ] and that's sort of the entertainment value of it this one's just like yeah so yeah that was a struggle but i just like i was i did a fallacy of sunk costs i was too far into it to back out and so yeah here we are you're welcome we have a video yeah i thought this one would be like a week or something like i thought it would take like a couple of days to program that's why i committed to this and then i'm like three weeks in and i'm like wait a second this is taking [ __ ] ages and it's still just connect four uh so i hope i made the video somewhat interesting i tried to like make it a bit shorter because i honestly couldn't be bothered explaining all the boring [ __ ] behind the ai because i mean it was it was kind of interesting but it was a lot of effort and i couldn't be [ __ ] i was more into the explosions and special effects that was fun but yeah so um next video will be a bit more ambitious and interesting i swear i don't know what i was thinking i'm interested to see what you guys think about it because god damn as soon as i saw the footage it was like ah brah this is gonna be such an uphill battle but we'll be fine i was supposed to do a flight simulator and unity that's what i was planning on doing and then i was like oh i could just do this connect 4 idea that i've had for a while um and i figured it would be like really quick and simple to program because i didn't i didn't think i had to do all the [ __ ] optimizations i thought just like bass mini max which i voted in a couple of days would be enough but whatever here's what it is um yeah so i'll probably do the flight tim i'll probably actually commit to doing the fight soon which i think would be actually really fun and interesting and the result will actually be cool and not just somebody [ __ ] playing connect whatever living life oh i hope you guys enjoyed it if you didn't i'm sorry i promise more interesting stuff next time uh i hope to get a video done i don't know i'm not gonna commit to any plans probably next month but who knows i hope you guys are doing well and staying healthy and all that i don't know okay i'm not really saying anything anymore i'm just kind of rambling so that's all i have to say talk to you later bye i just i just said that like i was hanging up um yeah all right see you see you in the next video this is not a phone call it's a youtube video god damn i gotta stop rambling
Info
Channel: Code Bullet
Views: 4,042,422
Rating: undefined out of 5
Keywords: artificial, intelligence, coding, processing, java, machine, learning, genetic, algorithm, evolution, computer, science, programming, comedy, educational
Id: XRVA5PMSKKE
Channel Id: undefined
Length: 14min 59sec (899 seconds)
Published: Wed Oct 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.