Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


pong AI


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 28 October 2012 - 10:02 PM

I want to incorporate some Ai into my pong game. I don't know what to do first.

Sponsor:

#2 Sparkon   Members   -  Reputation: 395

Like
0Likes
Like

Posted 29 October 2012 - 02:27 AM

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 :


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.


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, 29 October 2012 - 02:33 AM.


#3 IADaveMark   Moderators   -  Reputation: 2532

Like
0Likes
Like

Posted 29 October 2012 - 08:06 AM

The first thing you should do is search this entire forum for the word "pong". It has been discussed ad nauseum.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC

Professional consultant on game AI, mathematical modeling, simulation modeling
Co-advisor of the GDC AI Summit
Co-founder of the AI Game Programmers Guild
Author of the book, Behavioral Mathematics for Game AI

Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS