This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Giving Pong Computer Intelligence.  RSS feed

Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!