Code Bullet: I programmed an AI to Destroy the game PONG

In this AI video ...

Hey team, how’s it going? Today’s gonna be a bit of a mess of a video. I’ve got some announcements, I’ve got some questions, I’ve got an AI to show you. Okay, so first up, let’s check out the AI I’m doing today. AI learns to play pong? Yeah. I’m like my last video, I’ll just say it instead of doing the Cinema Sins intro. Cause it’s only like 20% of my audience actually understood that that was a reference and not me plagiarizing the intro. Like, what do you think? I thought people wouldn’t notice one of the most iconic intros on YouTube, you dumb fk, sorry. I’m a bit unnecessarily aggressive today. Um, that’s probably because I just finished eating the exams. Uh, but yeah, anyway. A little bit out of the way, let’s get to the AI. So yeah, we don’t, we don’t want pong today. Really pong isn’t that like the easiest game ever? Shut up, I’ve been busy. Alright. Okay, so usually I start by making the game and then I add the AI to the game. You know, life is short and I can’t be fucked. So I’m gonna be doing something that you guys have been suggesting for years. And then, you dumb sh, why did you spend a month making Hillblime racing when you could have just downloaded it from the App Store? You were redefined the word dictionary. So yeah, we’re gonna be playing pong directly off the internet and hopefully the difficulties I face in this will show you why I don’t do this. So my first challenge, which I really didn’t think would be a struggle, was finding a version of pong which is actually good. Like, check this one out. Well, that was sh**. Alright, so if I any found a good version of pong and here she is, this is our enemy. Look at that smug motherfucker. He thinks he’s so great. Following the ball everywhere. I’ll show him. I’ll show them all. So yeah, pong. So first up, this is pretty new for me. So don’t expect this to be good. I learned how to do most of this from a tutorial by Centnex, which is Python plays GTA 5. So if you haven’t seen that and you want to see somebody who can actually do this kind of thing well, then go check out that tutorial. That was really helpful and you’ll see how much I use a little. So first up, we need to figure out a way to get images from the screen so we can look at them and figure out where the pong is, where the ball is. Yeah, it’s just everything. We need to be able to see the screen. Just going to go over to Centnex’s tutorial and just thank you taking this. Yeah, and bam! There we go. Too easy. That’s how coding is done. So now we just need to specify where on the screen the game is so we know where to get the pixels from. So this I just took a print screen, chucked it into paint and check out the pixel locations. Too easy. There you go. You can see what the game is seeing. The frame rate is a bit slower but that’s actually so much better than using a lot of other libraries. So I just let Centnex do the work for me and I just grabbed these shit. So thank you again. Okay. So now we got input into the screen, which is fantastic. That’s great. I suppose, but it doesn’t really do much. So the other thing we need to be able to do is do we have to control the keyboard with our program. Let’s just try and do that. Once again, get a cheeky snag some code of Centnex’s tutorial. Ah, thank you. Gonna plagiarize that a little bit. There we go. Okay. So now we’re just gonna have the pome go up and down and up and down. Don’t even bother about looking for shit. Just to prove that we can control the pome. There we go. Hell yeah. I mean, I suppose technically it’s as good as I was. So making progress. So now what we’re gonna do is we’re gonna read in the location of the enemies pome and out pome and see if we can kind of match them up. It’s gonna be our first kind of shitty AI. So once you have the location of each pome, you just need to check. If you’re below the enemies pome, then go up. If you’re above the enemies pome, go down. You get it. It’s not hard. Okay. Next, we’re gonna need to be able to read in the location of the bull. This is one of the biggest challenges of the game because you kind of have some idea where the pome’s up, but the bull can be anywhere. And if you read over the entire array of pixels, it takes fucking forever to figure out where the bull is and that means each frame is really slow, which means it’s a big distance percentage thing. It’s just, it’s not ideal. But again, I’m not used to this. So I’ll just do in this the basic way. So now we know the location of the bull and the location of the paddle, which means that we can try and follow the bull and just copy what the other AI is doing. Once I’ve done that, you can see the lag between the bull and the player moving because we’ve got to take the screenshot process that find out where the pome is, find out where the bull is and then move the player towards that location. But time we’ve done all that, the bull’s move somewhere else. So yeah, this approach isn’t really gonna work for us. But don’t you fret, don’t you worry, we got one more strategy that we’re gonna try and implement. What we’re gonna do if we get two frames of where the bull is, we can figure out the velocity of the bull. Once we figure that out, we can run some calculations because we’re gonna try and use the velocity of the bull to kind of peep into the future a little bit and calculate the position of which the bull’s gonna hit the pome. And so we can just move to that position. So yeah, I don’t program in Python much, which is why my code looks gross as shit, so it’s gonna try and fix that. Alright, there we go. Much prettier. That’s pretty cool. Look at that! Fantastic! It’s still shit! Yeah, that’s awesome, but I’m tired and I’m going to bed. I’ll pick this up in the morning. Alright, so let me explain a few of the bugs that I’m facing. First of all, whenever the ball bounces off a wall, the predictions are to where we should put the paddle, just trip out, they just go nuts. This is simply because when it’s calculating the velocity of the two frames, it doesn’t take into account the fact that the ball has bounced off the wall, so the velocity is all wrong. I know I’ll throw up a visual, kind of hard to explain, but yeah, it’s wrong, it’s shit. We need to fix that. And well, yeah, okay, I did that and, whoa! Guess what? Boys! It’s still shit! Who would have thought it? Alright, I’m getting… This is not supposed to be this hard. It’s just fucking pong! And another fun bug that I’ve got, Gowan, is most of the time the text in the top isn’t an issue. That is until the point score hits seven. For some reason, my AI thinks the number seven is the ball, and then it just goes up and follows that, which is awesome! At the moment, we can never win, because as soon as we get to the point score seven, it just wigs out and goes to the top, which is… And fucking dastic! And I know there are ways to fix this, but honestly, I’m tired. It’s supposed to be like three hour thing, I’ll just pump it out, I’ll get the video done, and then we can move on to something far more interesting. But nope, nope, fuck you Evan, is it gonna be actually a challenge? You know what? You know what? Fuck this, fuck this, fuck this. You wanna pong, AI? I’ll give you a fucking pong AI. Just going over to the cutting train, got this, thank you! Alright, too easy, open that and processing, add a few if statements, and then boom! There we go! There’s your pong AI. That is how hard it should have been. Fuck this, I’m going home, I am home, fuck you, fuck you. Yeah, alright, that’ll do, I don’t care. Yeah, I thought this would be a lot easier than it would, as per usual. So hopefully you can understand why I don’t usually just play games on the internet with AI’s, because yeah, there’s a lot more issues than you’d think there is. I still plan to do that for more static games, ones where there isn’t like collisions and a moving ball that you’ve got to try and figure out where it’s going. Yeah, so whatever, that’s the AI done, I suppose, if you wanted more impressive AI, then fuck you. Yeah, okay, I said I had some announcements, and this is announcement number one. We have got a website, ladies and gentlemen, in my very limited spare time, I’ve been working on a website kind of behind the scenes, so I can upload all my projects to there, and you can, you know, play them and watch the AI’s, do stuff. So here it is, the bigcb.com, because CodeBullet.com was taken. Fuck. So yeah, codeBullet.com was taken, which is kind of a kick in the balls, but the bigcb.com will do. Yeah, so yeah, here it is. Look at this, I don’t know if the compression on YouTube will make the dots look like shit again, but you can go to the website. You can go check it out. You can know if you’re self looking, you can knock them around and stuff. Now, we want a website, and you can go to the projects thing, and look at, oh, whoa, look at that. What a terrible demo. Yeah, and I’ll let you explore the website, you can figure it out. Yeah, so it’s announcement number one. Check that out. Announcement number two is that university has done, at least for this year. That means I have three to four months, I don’t know how long it is, I don’t really want to know, but I have a long time spent just on CodeBullet.com, which is pretty awesome. That means I’m going to be trying to be a bit more consistent with my upload, because I don’t have to juggle university and CodeBullet. I’m going to try, no promises, no promises, I’m going to try putting out a video every week, kind of at the same time every week. I’m not generally known for my consistency, so it definitely, like, it’s definitely a potential that this might not work at all, and it might be off of like every week, but I will try my best to give it a go. Sometimes I might upload every other week, if I want to do a bigger, more ambitious project, but yeah, I should release videos kind of at the same time every week, which will be probably Saturday morning for me, so that I’ll probably be Friday afternoon, if you’re in America, or whatever. I’m in Australia, so you can figure that out. Yeah, so that’ll be pretty dope, so keep an eye out for that. Yeah, yeah, have a good day.

AI video(s) you might be interested in …