# Better AI for Pong than just following the ball?

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

## Recommended Posts

I'm just wondering, is there a better way to program some AI for a simple Pong clone than simply having the automated paddle follow the game ball once it gets to a certain point on the playing field?

##### Share on other sites
Of course, just predict exactly where it crosses your "paddle line" and go straight there. If you allow the paddle to actually controll the ball's direction, then you also want to direct the ball to the point firthest from your opponent's paddle. It is a very easy game to make perfect AI for, the reason you don;t do it is that the game is pointless then.

##### Share on other sites
When I wrote pong last, I used some spiffy linear algebra to extrapolate exactly where the ball will be when it crosses into the goal threshold (given its current position and velocity), so given that value the AI can just mosey on over.

To make it not-impossible, I threw in some "rounding error" variations which occasionally (pretty rarely, actually) made the computer miss it slightly when the ball was travelling at high speed, angle (or both). It was an undocumented feature [wink]

##### Share on other sites
Make the AI a little slow to react. Have a delay of .5 seconds after the player hits the ball before the AI moves at all. Then when the AI does move, force them to move slowly at first, and speed them up over time (maybe a full second until the AI can move at full speed). Combine that with an error-prone prediction algorithm that those guys are talking about, and you'll have a pretty fun AI.

##### Share on other sites
I made a simple pong where the ball direction was governed by where it hit the bat. No big deal but you could aim the ball away from the opponents bat.
In that situation, as soon as the AI hit the ball, it moved back towards the centre as a tennis or squash player would and waited to see in what direction the ball was returned (OK, really it THEN just followed the ball).
The AI would also aim to get return the ball as far from the player as possible with a slight bias to their current direction.
The next step was to add a slight speed reduction when a player changes direction but I lost interest.

1. 1
Rutin
22
2. 2
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633308
• Total Posts
3011293
• ### Who's Online (See full list)

There are no registered users currently online

×