• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Giving Pong Computer Intelligence.

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:



 
reply
    Bookmark Topic Watch Topic
  • New Topic