Archived

This topic is now archived and is closed to further replies.

Spindle

How to do AI in Pong.

Recommended Posts

Well there are many ways to implement ai in pong. The impossible to beat tracking algo works pretty well. You basicaly see where the ball is and move towards it. How ever it is nearly impossible to beat. What I''ve done in previous pong games is set the field of view for the AI to the center of the screen. If the ball is moving towards the AI and is as far as the center of the screen, then you move the paddle towards the ball. It works quite well. I''ve got full source code on my GDI Pong game in the GD Showcase if you''d like to see it.

Share this post


Link to post
Share on other sites
I think that if you want something easy, just let the AI move towards the direction of the ball. because this AI is impossible to beat (unless the ball is going to fast) you could put a delay so it doesn''t start moving until x mil-secs or secs after the player hits the ball. Or you could put some randomness in by letting it go the way it wants to x out of 100 times. Just some ideas, even though they are kinda basic I hope it gives you a good start of ideas for your killer pong game!

Share this post


Link to post
Share on other sites
For my Pong game I have the paddle follow the ball once it is past the center of the screen. Also if you hit the edge of the padlle the ball goes faster increasing the chance of the computer missing.

Share this post


Link to post
Share on other sites
the best thing about designing ai player is you can make them do exctly what you want or don''t.
To make the pong player more human, give it a reaction time, so maybe it could start moving in the wrong direction for a sec, or maybe give it a speed attribute that changes with its emotions, e.g. If its lost a lot it will be angry and have a high max speed. (im talking about the paddle there)...

Share this post


Link to post
Share on other sites
This is a smart and fair AI solution for pong...But naturally, it''s more complex than the ''set the paddle to the vertical location of the ball'' approach : )

This is a somewhat realistic approach as well, since this is what I do when I''m playing pong : )

For starters, each paddle can only move so fast...no jumping the paddle around for the CPU player...

Ok...every ''update'', or every second, or whatever you think a realistic amount of time between judgements is, you look at where the ball is, and where it''s heading. You throw a vector on top of it, which represents where you think it''s going, with some level of variance. You track where the ball goes, and if it hits a wall, you find the opposing vector, with some variance, and when your proposed ball path hits the CPU side, that''s where the paddle tries to move towards, one step at a time. So, if the ball is going to hit 5 times before getting to your paddle, you could be way off on where it''s going to land, but if it''s not going to hit at all, you''ve got a great chance fo knowing where it''s going to land. Lastly, the distance the ball has to travel should also be a factor. Because, when the ball is really close, you''ve always got a good idea of where it''s going.

Difficulty levels? Increase the variance. Impossible, near zero variance (aka, near-perfect prediction).

G''luck,
-Alamar

Share this post


Link to post
Share on other sites
I made a pong game for my computers class, and i made my AI as follows...

I had 3 different difficulty levels to choose from, lvl 1 made one mistake in 3 moves, the other made one wrong move in 10 moves, and the highest made one wrong move in 20 (randomly of course, like rolling 20 sided dice)

so if it was a wrong move, it would move opposite the way the ball was moving (up or down), if it was right, it would go the same way as the ball.

After I made the game however, i decided i should have made the things move to have the ball in the center of the paddle, so it would follow the ball up and down the "court". just test to so if its higher or lower than the midpoint, and move accordingly.

Also, by saying some moves were right, some wrong, my cpu''s kept moving every 20 cycles, im not a pro, so thats how i did it.

Hope im not to late for you, and if i am, that others find this helpful!!!

Dustin

Share this post


Link to post
Share on other sites