Jump to content

How to build AI for a new pong game?

- - - - -

  • Please log in to reply
8 replies to this topic

#1
even821

even821

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
im working on a pong game, and thus i want to integrate an AI system. after a bit of planning the only way i could think of doing it would be to have one of the platform thingies (the AI one) follow the ball, but that would make impossible to beat it would it not? so is there any other way to do this?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You could have it follow the ball, but move the platform more slowly than the ball can move.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
even821

even821

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
not to stupid :)

but noob question, how can i make it slower than the ball? the only method for slowing things down or speeding them up that i have found as of yet is the FPS regulating.

#4
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
I don't know all that much about this kind of thing but here's my suggestion:

Have a variable that will be used to measure the direction of the paddle movement. Any time the ball moves to the other side of the paddle, have the variable switch to another value that will represent movement in that direction. You could have the variable flip between negative and positive values for direction. Then you could implement paddle movement separately from the ball's movement.
Latinamne loqueris?

#5
even821

even821

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
hmm ye that might work. i am too tired to try to implement it today, but i will definetely let you know if it worked once i implement it.

#6
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 552 posts
  • Location:/etc/passwd
Right now you might take 1 of the paddles y variable.
So instead you take say 0.8 making it 0.2 pixels per frame slower than something which has 1 taken off it's x value every frame. Get what I'm going at??
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#7
even821

even821

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
i did it like this, and it worked pretty good.

i checked if the y value of the paddle was less than the y value of the ball + its height. if this was true then the paddle would start moving up.

then i checked if the y value of the paddle + its height was greater than the y value of the ball. f this was true then the paddle would start moving down.

i hope that makes sense :)

#8
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 552 posts
  • Location:/etc/passwd
Cool, does the paddle move faster or slower than the ball?
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#9
even821

even821

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
it moves at the same phase as the ball, howerver it start moving after the ball has past the paddle in a way

i think i am gonna change it in the near future thought (it doesn't add to much of a challange to the game), but for a first AI im fairly happy with it lol.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users