I Created An A.I. to DESTROY Tetris

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we're doing tetris baby oh right video my bad all right uh right yeah tetris let's do tetris if you're not familiar with my videos first we're gonna need to build the game so one two three let's go let's let's go and do some some uh like go go gadget coding yeah intro done that's a take it that's a background let's get some blocks going that's a block yeah it's happening baby we're almost there evan settle down all you've done is draw a square on a larger square oh really watch this so the block can move down yeah [ __ ] awesome whatever you say just let's move on [ __ ] hell what a time to be alive okay we got some blocks so now we're gonna need some shapes it was at this point that i realized that i had no idea what the [ __ ] i was doing and just gave up and started playing tetris i was actually testing how each shape span and while i could have just googled this i decided to reinvent the [ __ ] wheel and figure it out for myself okay let's cover some tetris facts fact one it's [ __ ] hard disgusting fact two you have pieces that be spinning oh that's pretty simple hey no you're stupid the problem is that the point where the piece rotates around changes for each piece for example the square piece rotates around its center like this wait oh wait oh yeah that makes sense but the line piece can't spin around its center because then it would be in a half position between blocks which is no good so each piece has a unique spin point which i found by just spamming the rotate key and [ __ ] eyeballing it even though i could have just googled tetris piece spin and wow would you look at that it's actually the first [ __ ] picture [ __ ] brilliant evan [ __ ] brilliant oh well mistakes were made but now you know how [ __ ] spins so you're welcome okay we are getting a little bit ahead of ourselves here since we currently only have a block which can move down okay back at it let's make some shapes sorry sorry thank you [Laughter] hmm okay shape's done and welcome to tetra's peace once a while let's introduce today's lucky bachelors our first bachelor is a chubby [ __ ] who doesn't like to speed its square piece next up we have the always reliable lps look at that angle i guess i don't know shut up i'm doing my best [Music] if you want a man who's tall thin and can complete your tetris if you know what i mean then this next contestant might be for you i'm talking about the one and only line oh my god you okay buddy no i i think it's a no oh yeah cut it cut the show can't be [ __ ] finishing this dumb bit anyway so just cut it back to the coating okay so the conclusion from the dumb bachelor thing was that we have shapes pretty much working but at the moment the game highly resembles your mama so we're gonna need to make some aesthetic changes there we go that's tons better okay so we got the bad boys fallen but we don't yet have them spinning so let's get that done this is probably where i should have done the whole explanation of where all the shapes rotate but you know what [ __ ] it this video's a [ __ ] anyway okay back to the code let's get them bad boys spinning [Music] okay that should do it let's see how well we did okay cool it's span and oh yeah sure just stay there that's that works that works all right i've seen enough of this i'm pretty sure i know what the problem is should be a quick fix ugh okay well that's embarrassing but here's what we're gonna do i have a plan here it is a little bit of audience participation here i'm gonna go ahead and fix that and you're not gonna insult my intelligence in the comments all right ready and go okay i got it and let's just say hit the beat okay [ __ ] this there's gonna be a long video if it's taken me this long to rotate a [ __ ] shape you said it not me man [ __ ] you what are you doing get out here [ __ ] l what a loser okay so shapes can spin and move down check let's actually get some sort of collision logic on the shape so we can you know play tetris if you're not following that that is what we're doing here that is the end goal if you're just joining us [ __ ] congrats on starting a video halfway through did you miss the whole it's tetris type that was like i started the video as aggressively as possible the collision logic is hella simple i've just got a grid which holds all the blocks which are currently stationary on the map we then just take the future position of the current piece and see if there are any blocks in that spot if there are then we can't move there if there's not then go nuts that's it simple [ __ ] okay you're ready and action oh yes yeah oh oh oh dear yeah that's uh that's a problem that didn't even happen yeah um okay i'll be back okay there we go that should fix it hey there we go baby yes yeah he's done it not bad evan not bad at all oh god um ignore that yeah that's not a problem i can never win okay let's see if we can get some horizontal movement happening yes very nice and i'm getting cocky let's add some rotation oh uh no no it's [ __ ] uh yeah definitely [ __ ] okay all right so we got the spinning shapes working and we are ready to party what's next well we're done no bad code bullet that's stupid you're stupid yeah i know [ __ ] you i hate you oh come on dude that's a bit far don't you think i hope you die in like in like a hole with at least three spiders in it which bully you for how stupid you are the the spiders are bullying me yeah it's like charlotte's web but instead of radiant or some [ __ ] it says you're [ __ ] stupid you're done you're stupid are you done yeah yeah i think i've made my point all right no we're not done we've still got to do the line clearing [ __ ] then and only then are we done okay okay uh clearing the lines is pretty [ __ ] simple this really is an easy game to make i'm just bad at my job all we really need to do is check if the line is full and then if it is uh remove it which you probably could have guessed i don't know why i'm explaining this to you get it it's tetris all right explanation done check that off the list okay i've got that implemented and let's [ __ ] party okay a new problem i have to actually clear a line to test this [ __ ] let's go first try oh oh no no nope nope that just keeps happening no oh come on [ __ ] you kick me while you're down why don't you okay uh apart from the pieces which you couldn't see which were there and apart from the pieces which you could see which weren't there that went well ah [ __ ] you spider i'm not stupid no i'm not oh god what the [ __ ] why is it so detailed how do you even know what that is how is that color i have so many questions spiders are [ __ ] me alright so whatever back to it before i start crying let's fix that okay there we go everything works the way it should and i shouldn't get my lunch money stolen by an [ __ ] spider okay now all that's left to do is make it look pretty wow so pretty look at that aspect ratio okay i've added some functionality which i can't be bothered explaining but basically you can now see the next piece to come and you can hold a piece if you don't want it you can just chuck it up there for a bit again i'm just explaining tetris this is tetris you've played tetris it's tetris all right okay now all that's left is for you to admire my ninja as [ __ ] tetra skills oh no [ __ ] okay stupid game anyway that's enough of that let's move on it's ai time goddamn transitions be on point today [ __ ] yeah okay okay let's talk ai i thought about doing like some fancy reinforcement learning [ __ ] but i've seen many videos of people trying and failing and it feels like it's going to end up like my 2048 video which if you've seen it is not a good thing you're so close thomas you dumb mother okay so here's the plan first we need to generate all the possible positions the current shape can finish in for example if we got this bad boy here it can end up in all these positions pretty simple so first up we need to figure out how to generate all these positions now it is important to write an algorithm which runs efficiently and quickly because we're going to need to run this search for every single shape this would have been a smart thing to do however i couldn't really be [ __ ] so instead i just bought a beast of a computer which can brute force it i've seen a couple of other people do this because a bunch of people have tried this because it's [ __ ] tetris but what they do is just drop the piece from each horizontal position and then each rotation and just see where it lands this does the job i guess but it means you can't do fancy moves like moving blocks under other blocks or doing t spins or anything which isn't just dropping that bad boy from the sky and we don't want that because here at code bullet studios our number one priority is quality because it's definitely not quantity so let's do something way less efficient and in many ways objectively worse but it will reach all possible end positions so you can do fancy [ __ ] like t spins and stuff i don't think it'll happen but it's a cute idea essentially we just simulate every possible combination of key presses the player can input and for each combination that results in a piece reaching a new end position add it to a list of finished positions it's a bit smarter than that but you get the gist it's brute forcey as [ __ ] i've brought shame to myself and my family but you know [ __ ] you it works all right so i've coded that up and this should rotate through all possible positions the current piece can land here we go bruh come on really that's not even like close to right ah now it's off the screen okay i think we've seen enough of that hey hey no don't you [ __ ] start mate i'll martin your ass boy i'm serious i'll [ __ ] do it [Music] okay so yeah you know you live you learn or you can use the philosophy i prefer you fail you forget it's way easier okay so here's what i achieved on the very first try without any problems or bugs to speak of fantastic it works i'm a great programmer okay so now that we can generate all the possible moves we need to pick the best one to perform this is kind of the backbone of the ai we need to figure out which moves are good moves and which moves are bad moves this is done by assigning a point score to each move the move with the highest score is chosen as the best so i really need to do is to quantify what a good move is and what a bad move is let's start off really simple anyone who's played tetris before will tell you that this is a dog [ __ ] move the main reason it's trash is because you've left holes under your piece and holes are bad rule one this holes are bad we'll define a hole as an empty space with a block above it so all these bad boys are holes so all we need to do is give the ai a little slap if it's going to generate a hole and sit back and watch as our ai finally comes to life [Music] you're a failure and i hate you so the problem with this is it has no interest in keeping its stacks low as long as the piece fits without generating a hole then it doesn't really give a [ __ ] where it goes like this move it's it's bad like this is a cancer-tier move but from its perspective it doesn't generate any new holes so you know what it's a great move this brings me to my second rule we're gonna punish moves based on how highly they're placed so this move is worse than this move pretty simple okay let's run this [ __ ] and this actually does way better like we're cooking it's finally happening [Music] it was rare if the previous algorithm cleared a single line now this bad boy can clear almost 300 lines before dying okay now we're talking and we're just getting started baby 300 is nothing i'm going for the world record and wait give me a sec it looks like the world record is uh 5 000 lines cleared okay that's more than i thought but that's fine i'm coming for you you little [ __ ] anyway let's improve this pitch there are still problems with the current solution but before we address them i'm going to make use of the hold function at the moment i've just been kind of ignoring that it exists but by using it we should be able to greatly improve what the air can achieve the idea is that if the best end position for the held face is better than their best end position of the current piece then we use the held piece it's a pretty simple change but it should have a big impact so let's dance yeah i'm gonna have to speed this up because otherwise i'm gonna be here and yeah it does go for [ __ ] ages some of the runs reach up to a thousand lines cleared which is awesome the problem is that some of them die at like line 50 which is not ideal and it basically means it's relying a lot on the luck of the draw which is not what we want we want it to be consistent the major problem that i can see is the ai's reliance on line pieces it has a tendency to create these pillars of empty spaces which is not a huge problem when there's only one empty pillar this is actually the go-to strategy if you want to slam some tetris the problem occurs when the ai creates more than one of these pillars that way when you dunk a line piece down there nothing happens you need another line piece before the lines are cleared and then by the time you've got the other line piece the pillars have grown even deeper and eventually you die because there just aren't enough line pieces so the solution i thought of was just to simply penalize any moves which resulted in a pillar of three or more empty blocks just like we did the holes alright and i've coded that up and so penalizing empty pillars is added let's see if it helps i'm gonna speed this up to a point where you're just gonna have to trust me that this is a game of tetris i technically could just be drawing random blocks in random positions and randomly increasing the score and you wouldn't know but everyone knows i'm the most reliable trustworthy consistent guy on the internet so you don't have to worry i'm here for you just like zak my man and you know what i don't give a [ __ ] if you trust me what are you gonna do i'll see you in court you can't prove [ __ ] boy [Music] oh and we're approaching 5 000 forgot about that that's the thing oh yeah [ __ ] you oh wait give me a second uh harry hong i mean not to downplay your achievement which is objectively worlds better than mine but [ __ ] you your [ __ ] get good bruh get good oh feels good man feels good [ __ ] that guy okay let's superspeed this [ __ ] because this is going great all right let's pick it up even faster because you know life is short and i'm honestly getting bored of tetris and yep looks even less like a game of tetris look at the next beast that's some trippy [ __ ] [Music] okay we hit 10 000. wow hopefully this doesn't go on forever because i got places to be i mean i don't really i've got videos to make oh hell am i kidding that's even less true just die soon so i can upload this video and disappear for three months please i got i got disappearing to do hey there we go i didn't actually see what the score was or what went wrong but i don't care at this point let's just round it up to an even fifteen thousand okay uh yeah i could probably improve it but you know uh like it's already a ridiculous game of tetris it's already sped up to the point where it doesn't look like tetris i could make it better but you know yeah this video is already getting long and i can't be [ __ ] oh yeah that's pretty much it for this video there are a few things that i wanted to put in this video but it's already long and i can't be [ __ ] at the moment i think it should be possible to do like an infinite run-through of the game and i'm sure that if i googled it i'd find something but as per usual i did zero research for this video it would also be really dope to use python to read in the screen and to bypass the keyboard to control a pre-made tetris game kind of a similar sort of thing to my storm the house or piano tiles or like the pong thing i tried and i found a very good victim for this it's a website called just where you can play against other people and there are like high scores and [ __ ] which would be fun to destroy and yeah so let me know in the comment section if that's a video you would like to see i might just do it anyway because bullying nerds and just sounds like a lot of fun to me or am i not it really depends on what i feel like but i'll still be interested in seeing what you guys want to see all right i'm done i hope you guys are keeping safe in the [ __ ] fight of a year uh that's all i'm going to say about that but yeah stay safe bye later
Info
Channel: Code Bullet
Views: 3,362,362
Rating: undefined out of 5
Keywords: artificial, intelligence, coding, processing, java, machine, learning, genetic, algorithm, evolution, computer, science, programming, comedy, educational, Tetris, world record, javascript, code bullet, Tspin, jojos
Id: QOJfyp0KMmM
Channel Id: undefined
Length: 17min 25sec (1045 seconds)
Published: Thu Jul 23 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.