aspose file tools*
The moose likes Beginning Java and the fly likes Giving Pong Computer Intelligence. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Giving Pong Computer Intelligence." Watch "Giving Pong Computer Intelligence." New topic
Author

Giving Pong Computer Intelligence.

Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
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.
yy is the computer paddle.

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:





Live And Let Learn.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Giving Pong Computer Intelligence.