Sign in to follow this  
Followers 0
phil67rpg

pong AI

2 posts in this topic

Something extremely easy would be to keep track of the Y position of the ball and assign that position to the enemy paddle. This will result in an unbeatable AI if you don't reduce the speed of the paddle. Pong does not require an extremely complicated AI, something like this will suffice :

[code]

void GetEnemyPosition( const vector2D& ballPosition,vector2D& enemyPosition)
{
if (ballPosition.y < enemyPosition.y )
enemyPosition.y -= speed; // calculated based on the clock
else if (ballPosition.y > enemyPosition.y)
enemyPosition.y += speed;
// if the position is equal the paddle will not move
}

// the += or -= depends on the axis-system you are using, i'm assuming that the origin
// of the system is in the topleft corner.

[/code]

P.S. If you want to do something else you could try to predict where the ball will hit the wall. Then randomly make the enemyPaddle spin the ball in some random direction.

Excuse my english please Edited by Sparkon
0

Share this post


Link to post
Share on other sites
The first thing you should do is search this entire forum for the word "pong". It has been discussed [i]ad nauseum[/i].
0

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  
Followers 0