Sign in to follow this  
neob

Pong Clone Help

Recommended Posts

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

Share this post


Link to post
Share on other sites
By the way, the project is done with C++ with allegro. Though it should not affect the way the AI should be made.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this