Sign in to follow this  
Marshal

Pong AI

Recommended Posts

[color="#000000"]Hello![/color]

[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]


[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.][/color] Edited by IADaveMark
Added code tags... kinda

Share this post


Link to post
Share on other sites
you can look at previous topic :[url="http://www.gamedev.n...ncible--solved/"]My AI Is Invincible :( [SOLVED][/url]
[url="http://www.gamedev.net/topic/591564-my-ai-is-invincible--solved/"] [/url][url="http://www.gamedev.net/topic/591564-my-ai-is-invincible--solved/"]
[/url]

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.

Share this post


Link to post
Share on other sites
[quote name='IADaveMark' timestamp='1298495034' post='4778126']
See note on original post about code.
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='Nanoha' timestamp='1298478934' post='4778009']
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.
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='Jarod42' timestamp='1298477711' post='4778002']
you can look at previous topic :[url="http://www.gamedev.n...ncible--solved/"]My AI Is Invincible :( [SOLVED][/url]
[url="http://www.gamedev.net/topic/591564-my-ai-is-invincible--solved/"] [/url][url="http://www.gamedev.net/topic/591564-my-ai-is-invincible--solved/"]
[/url]
[/quote]


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

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

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