# Need ideas for pong AI

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

## 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 on other sites
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 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 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 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 on other sites
Any one else got any ideas of implementing pong ai?

##### 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 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 on other sites
What do other people use for pong AI?

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633730
• Total Posts
3013579
×