This week's book giveaway is in the Performance forum.We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!

# Giving Pong Computer Intelligence.

Martin vanPutten
Ranch Hand
Posts: 124
Here what I did. It doesn't really give intelligence to the AI but only randomizes what happens.
Y is for the ball.

So... if (Y > 0 && Y < 100 && X > 0 && X < 100)
yy =+ yy - 1;

I set the parameters up in blocks where every other block means yy =+ yy - 1.

Initially yy = Y - 25 so that its somewhat in the center of the paddle.
Here are my flaws... the paddle stops at 0 and 420 (because the height of the field is 500 and the paddle is 80) so that when the ball bounces off the walls the paddle moves again when it hits its initial value which was yy = Y - 25. Also, I think when it hits the opposing blocks with nothing set to it it goes back to its initial value. So... you can see my problem.
Heres my code for this part:

As you can see... its too much pointless code for an AI. But... if someone can enlighten me on how to fix my problems on my random computer movement... it would be most appreciated. But... if someone can give me an example on how to create a real AI... then it would make things just perfect!! The following is the rest of the code if needed: