Pong Clone Help

Started by
4 comments, last by Zanshibumi 16 years, 10 months ago
I have made a C++ pong clone. However I don’t know how to make AI. What do I need to do in code so that the AI paddle goes after the ball? Does anyone know a specific tutorial or example code for this? Many thanks
Advertisement
By the way, the project is done with C++ with allegro. Though it should not affect the way the AI should be made.
Compare the position of the ball to the position of the paddle. If the ball is left from the paddle, make the paddle move to the left. If it's right, make it go right. That's a pretty simple way to do it.
you could also make the paddle be only to move after a certain amount of time... otherwise it will be impossible to beat if you match the paddle to the ball movement...
Quote:Original post by Shwanger
you could also make the paddle be only to move after a certain amount of time... otherwise it will be impossible to beat if you match the paddle to the ball movement...


Not really, the paddle should never move faster than what the player can move, thus it would come into situations where the ai-paddle can't keep up.

My pong clone only moved the AI when the ball headed towards him, but this can be tweaked back and fourth, you can set a limit on the screen where the AI can 'see' the ball and react to it.

When the ball goes towards the opponent, move the paddle to the center.

After the opponent has touched the ball:

- medium difficulty: move the paddle towards the ball as already suggested.
- hard difficulty: precalculate where the ball will end and move the paddle to that position.

P.S.: impossible difficulty is: while the ball goes towards the opponent, precalculate where the ball will end in the opponent's side, then calculate all the possible trajectories of return (taking into account any receiving position of the opponent's paddle) and move the paddle to the center of the most probable returning positions.

This topic is closed to new replies.

Advertisement