Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

Need ideas for pong AI

This topic is 4069 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What are some very basic AI technics for pong? I have it were the computer paddle just fallows the ball but I want it to miss the ball once in a while. I tryed randomizing the position but it gave me jerky movements. How can I have the computer perdicte were the ball might be? Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
The simplest way would be to let the AI paddle know the velocity of the ball and it's current position. From that it can extrapolate out the point that the ball is heading for. Check that it won't bounce off a wall so you only chase balls that are going to score against you, then just move the paddle towards the spot using the same controls as the player (so the AI can't teleport or move faster than the player).

Once you've got that working - you'll find that if the AI paddle can make it to the spot, they'll always make the return so you might want to think about adding a slight variance to the paddles velocity, meaning it'll over shoot or not arrive in time - adding some variance to the final ball location would also provide the same idea without making the paddle move at different speeds from the "norm" (though that might be useful to use for different difficulty levels).

Share this post


Link to post
Share on other sites
HOw do I check if it is going to bounce off the wall before it gets there?

What I was thincking is that i would have to cut the playing area into grids and if it is going a certin direction at a certin point then it will collide but that would be alot of calculation.

Is there another way to do it?

Thanks

Share this post


Link to post
Share on other sites
Once you know the velocity, plot a line out from it's current position until you either hit a wall or go off the screen (meaning you'll score).

Share this post


Link to post
Share on other sites
what algorithm whould I use for that? Just an equestion will help.

I figure it has to do with direction, velocity, time, and position.

Not sure how to put that in an algorithm.

Share this post


Link to post
Share on other sites
this is what I got for my AI


int Paddle_AI()
{
ball_direction();

int PMax_Velocity = 4;

//keeps the paddle on the screen
if (paddle2.y > SCREEN_HEIGHT - paddle2.height){
paddle2.y = SCREEN_HEIGHT - paddle2.height;}

if(paddle2.y<=0){paddle2.y = 1;}

//check to make sure the ball is moving twords the computer paddle

if(ball_mov_player == false)
{
//check to see if the computer y == to ball y if not move the paddle so they match
if(paddle2.y < ball.y)
{

paddle2.y += PMax_Velocity ;
}
else {
paddle2.y -= PMax_Velocity ;
}
if(paddle2.y == ball.y )
{
return 0;
}
}
//if the ball is moving towrds the player center the paddle in the middle of the screen
else
{
while(paddle2.y != 100)
{
paddle2.y += PMax_Velocity;}
}

return 0;
}




but it locks up when the ball touches the paddle.

Any ideas why?

Thanks

Share this post


Link to post
Share on other sites
right here


//if the ball is moving towrds the player center the paddle in the middle of the screen
else
{
while(paddle2.y != 100)
{
paddle2.y += PMax_Velocity;}




is why the game would lock up.

Now all I have to do is figure out how to get the paddle to move to the middle of the screen after hitting the ball.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!