# Pong AI

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

## 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

##### Share on other sites
you can look at previous topic :My AI Is Invincible [SOLVED]

##### 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.

##### Share on other sites
See note on original post about code.

##### Share on other sites

See note on original post about code.

##### 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 on other sites

you can look at previous topic :My AI Is Invincible [SOLVED]

Cool, thanks for the link I will look it over!

##### 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)

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002284
×