 Okay, welcome to Simple Pong in Python 3-4 beginners. This is part 8 AI player And I'm recording this one and a half years after the original tutorial So I wanted to add something to this today. I actually passed 25,000 subscribers on my channel So I thought I'd do a special episode and make a little game AI a very simple one because it's a very simple game So let's take a look and see what we have for those of you who haven't seen the game in a while So I'm gonna go ahead and run this and I don't normally use Visual Studio code anymore. I use something called genie, but I thought to keep it consistent. I would have the same Editor as I did the last time. Okay, so this is our game and what I want to do is I want to automate this Player so that when this player will track the ball And it's very very simple if you think about it If the ball is below the paddle the paddle should go down if the ball is above the paddle the paddle should go up That's that's it. It's a very very simple thing. So let's go ahead and give that a shot Okay, so I'm gonna just kind of scroll down. I'm gonna keep the Original commands in there paddle be up paddle be down. I'm just gonna leave it the way it is and So you could kind of override the AI if you wanted to it was gonna come all the way down here and Again note the indentation here. I'm using spaces. So I'm gonna call this AI player So I'm just gonna take a look at the X and R. Excuse me at the Y coordinates. So if the pedal Be dot Y core note the parentheses is Let's say if it's less than the ball dot Y core That means that we want the paddle to go up So then we'll set we'll just go ahead and use the function that's already there We already have a function called paddle be up So I'm gonna go ahead and type paddle Be it's paddle be oops, it's paddle underscore B underscore up and Kind of put a parentheses there and then I'm gonna go L if because it's not possible for it to have both conditions I'll say paddle B dot Y core is Greater than ball dot Y core. Yeah, we're just looking at where they are relative to each other I'll say paddle be Down and parentheses and we'll see what happens. So it should be pretty straightforward. So I'm gonna go ahead and run it and Start without debugging in this case Okay, so you can see how it is moving towards the ball. That's a little flashy It's a little slightly problem But it is following the ball, which is which is what we want to see and we got that weird little artifact I'm not quite sure how to fix that. Let's let's think about that for a second and I tell you I'm gonna try a little effort. I'm gonna try it a little thing. I say and ABS and I'm just gonna copy this because I'm well known for being a lazy person I'm gonna say in ABS That's the absolute value So basically I'm just looking for the difference and let's see is let's say less than 10 And let's go ahead and copy that if it works. I'll explain a little in a little bit more detail I think I got enough Yeah Now that that's not correct. So here's what It's always always a problem here. You're gonna make sure you have your parentheses correct and we weren't using parentheses on that side So again, this is something, you know, it oops, you know beginners have a lot of trouble with and Also people who've been doing this for a while. Those are easy mistakes to make And let's see what happens. I don't know if it's gonna work. I just kind of just thought of it. Um, so let's take a look Okay, that didn't work Geez Um Let's see. What did I do wrong here? The paddle b y coordinate That's what value is less than 10 Ah, okay is greater than 10 because I want to know if it's more than 10 pixels away Okay, so that's that's why it wasn't working. Let's go ahead and run that oops wrong wrong configuration. Let's go to run Oops run and run without debugging Let's take a look at that. Okay. So now it's it's It's doing what we want it to do basically. Okay, so it kind of looks like the guy on the left Okay, we notice how it's following the ball. So the ball is going down paddles going down And so you can see how that would be a very difficult ai to beat so I'm gonna leave that at that So let's go take a look real quick at the code just for a quick review and see if I can get out of that thing I don't think I can because I'm recording the screen. But anyway, uh, so basically I'm just looking at is the paddle is paddle b's y coordinate less than The y coordinate of the ball and is it Over 10 now, probably some of you who are good at math can probably figure out a way to simplify this But I want to leave it like this just so we can think about the different conditions that we need This is the minimum condition And then this just keeps it from bouncing around all the time. I could change this to 20, you know to give it make it a larger number, but let's stick with 10. That's fine And again, depending on your computer's speed, you might see a slightly different result in at least the way that it's rendered And so in this case if the paddle is above the ball And that distance is more than 10 and we're going to move the paddle down So that is that thanks for still watching a year and a half later This is a very popular, uh tutorial and I appreciate every view every comment and especially every subscription. Thanks so much everyone