• Advertisement
Sign in to follow this  

Pong AI

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

[color="#000000"]Hello!

[color="#000000"]I'm new to game development, so new I'm green! I have been reading books and doing tutorials. I have a good understanding of C#. I understand I still have tons to learn, but I feel I'm making progress. Currently I have created a Pong clone for the Windows Phone 7 platform using Visual Studio Express 2010 with XNA 4.0. The issue I'm having if creating a great AI for the computer controlled paddle. Currently I have the paddle reacting to the ball based on the balls Y axis position. This works OK, but I'm not happy. I have looked online for samples of AI for pong and haven't really found a good alternative in C#. I am finding it quite difficult to think of another way to code the AI to get that balance of not too hard but not too easy. I know this is mostly due to my inexperience in programming, this is a simple game and it's frustrating not knowing even were to start with this issue, so I turn to the experts here on this forum! I would appreciate some help with this issue.

Below is my code:


[color="#FF0000"][Ed note: tried to wrap your code in code tags but then the forum barfed all over your formatting with font tags and whatnot. Please repaste your code but put it between tags by using the "<>" symbol above.] Edited by IADaveMark
Added code tags... kinda

Share this post


Link to post
Share on other sites
Advertisement
Your AI seems quite reasonable for pong. I see you have paddle speed there, perhaps add a "reaction time" value too. By altering those values you can change the difficulty of the AI. You could use the balls velocity to predict where to move the paddle. pos = currentPos + v*t, solve to find out the y position when x is at the edge then start moving towards that position.

Share this post


Link to post
Share on other sites

See note on original post about code.


Oops, sorry about that. Thanks for the heads up about code.

Share this post


Link to post
Share on other sites

Your AI seems quite reasonable for pong. I see you have paddle speed there, perhaps add a "reaction time" value too. By altering those values you can change the difficulty of the AI. You could use the balls velocity to predict where to move the paddle. pos = currentPos + v*t, solve to find out the y position when x is at the edge then start moving towards that position.


Thank you very much for the info! I will see what I can do. :)

Share this post


Link to post
Share on other sites
I have created a simple pong game in java and to make the AI more fun I added a couple of features.

- first, the AI paddle would move only after the ball X position would pass the middle of the screen, and as the score difference increases in favor of the player that X position advances towards the player
-second I have done speed progression which increases as the score progresses.

Also, I have plans to make it in such that the AI paddle can anticipate the final position of the ball by measuring the angles the ball bounces from the last edge (I am still working on this one)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement