algorithmartificial-intelligencepong

Pong: How does the paddle know where the ball will hit?


After implementing Pacman and Snake I'm implementing the next very very classic game: Pong.

The implementation is really simple, but I just have one little problem remaining. When one of the paddle (I'm not sure if it is called paddle) is controlled by the computer, I have trouble to position it at the correct position.

The ball has a current position, a speed (which for now is constant) and a direction angle. So I could calculate the position where it will hit the side of the computer controlled paddle. And so Icould position the paddle right there. But however in the real game, there is a probability that the computer's paddle will miss the ball. How can I implement this probability?

If I only use a probability of lets say 0.5 that the computer's paddle will hit the ball, the problem is solved, but I think it isn't that simple.

From the original game I think the probability depends on the distance between the current paddle position and the position the ball will hit the border.

Does anybody have any hints how exactly this is calculated?


Solution

  • We made a (pseudo-)3D ping-pong game for our high school CS class. What we did was, we made the computer always move the paddle toward the ball, but with a maximum speed -- that way, it could miss the ball if it's too far, but it's still smart. Does this help?