#### Archived

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

# a pong AI question

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

## Recommended Posts

I''m trying to make a simple pong game in vbasic/dx7... how do I make the computer follow the ball so he can hit it back towards me? I know this is AI, but I''m not sure how to do it.

##### Share on other sites
If the paddles are on the left and right sides of the screen, the ball moves up and down. That should be all that the computer cares about.
There are a number of ways to do this:
1) If the ball is above, the AI paddle should move up. Same for below.
2)If the ball moves up, the AI should move up as well. Disadvantage: if the paddle is already above where the ball will go, it will not seem too intelligent.
3)The AI should determine where the ball is going to intersect with the paddle''s area. Then the paddle should move in the direction needed, either up or down, until it hits that point. Now, the problem is setting the speed so that it is possible to beat the AI, but that shouldn''t be too hard to implement. Also for this type of AI, you would also need the left right movement of the ball.

Hope this helps!

##### Share on other sites
The easiest way to make a simple ai for a pong game is to have the computer head in whatever direction the ball is. By this I mean, if the x-coordinate of the ball is less than the computer, it moves left, if it is greater, it moves right. The problem is that if the computer''s speed is too fast, it will be impossible to beat it, and if it goes too slow, it will almost never win. Another way of doing it is calculating where in the computer''s ''end zone'' the ball will end up when it gets that far, and have the computer go there. The latter method gives you a better playing computer, while the first one is easier. I''m sure there are others, but those are the easiest.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 12
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632991
• Total Posts
3009749
• ### Who's Online (See full list)

There are no registered users currently online

×