Sign in to follow this  
_damN_

Pong AI?

Recommended Posts

_damN_    127
Hi! Im currently writing a ping pong game and wanto add some AI for the CPU paddle? But i dont know the best way to do this. How can a add movement the the computer paddle to make it seem alsmost as if a human is controlling it. Any ideas would help me alot! Thanks!

Share this post


Link to post
Share on other sites
kauna    2922

Hi,

it is hard to tell what is the best way of doing it, but here's some ideas.

Practically you want the AI to use the same controls as the human player. I assume that you have a simple version where you can move your pad just left or right. If you use the mouse as input the pad may move at varying velocities.

Simplest AI would just try to keep the pads middle point in the same line as the ball. Of course since the CPU has always exact information about the pad position and the ball position, it would be impossible to beat this AI. Also, this kind of AI doesn't look very human.

To make it a bit more realistic, the AI player should be able to do some kind of estimation about the movement of the ball. ie. it should be able to see in the future a bit by running an internal simulation of the balls movement. This is what you do when you play any game. According to the results of this simulation the AI should place the pad in the correct position. The AI can run this simulation constantly of course and refine the pads location.

To make the AI lose sometimes, you may add some factors to the pad movement. Like if the AI moves the pad really fast, it may end of further than intended. Or perhaps the AI runs the simulation a bit less often. Or perhaps the simulation in AI's head has slightly simplified rules compared to the board physics etc etc.

Good luck!

Share this post


Link to post
Share on other sites
Kirl    174
I fixed a very simple AI by easing the paddle to the balls position when it's comming (towards cpu paddle) and easing to the middle when it's going away (towards player paddle).

It works alright. I imagine most Pong games use a similar method. A true AI would be interesting for research, but kind of an overkill for such a simple kind of game. The only possible options are up/down, left/right, even for the most advanced pong AI. :)

Share this post


Link to post
Share on other sites
speciesUnknown    527
A fascinating subject. I implemented pong AI years ago with just a simple "more left" / "more right" method; on each AI timestep the AI decides if it needs to go more left or more right using a few rules. It then sets the paddle moving in one of the two directions. The better the AI, the more frequent these updates, and the lower the random error factor.

It looked alright but became sporadic as the ball got faster.

Share this post


Link to post
Share on other sites
Agent_Q    100
The most recent way I've considered doing Pong AI is by giving the AI paddle a state which tells it whether the ball is incoming or outgoing. If it is incoming then I would use the aforementioned technique (of the paddle homing in on the ball) otherwise, I would keep the paddle still after it hit the ball.

Another method would be a form of path prediction (which is common with steering behaviors) but that might make the opponent too smart!

I never considered a fudge factor before this, but that sounds like a great idea for varying the levels of difficulty for an opponent.

Share this post


Link to post
Share on other sites
_damN_    127
This is a pretty interesting subject. Currently the AI for my pong game moves towords the balls direction at a particular velocity only slightly slower than the ball. This gives about a 40 percent chance that he will miss it. If the AI paddles velocity is faster than the ball, he will never miss it. It works well but it isnt very realistic at all.
I like the idea about the incoming/outgoing state. There is potential to make the AI more realistic like that. For example...

if(Outgoing)
{
// Move towards items instead of the ball.
}


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