Pong AI?
Well when I was making pong I ran into a question. Does pong really have ai? I thought that if I made the computer paddle just follow the ball and randomly misses the ball that that would be a good way of doing it.
My question is does pong have AI and if no then would my way work. If yes how would I do it.
True God of the TribunalKelchargeMy SiteMy Ugly Forums
there is a million ways to do it but a really simple one is to only allow the paddle to track the ball when it is within a certain distance somewhere around the center of the screen will work pretty good. this will cause the paddle to miss on occasions but still look like it is trying to get to the ball.
ot increase the points as time goes on and see how many you can get.
there are 10 types of people in this world, those who can do bianary and those who cant.
I am actually working on a 3d version of Pong. My ideas for AI:
- Progressive levels of skill.
- Come up with strategies in the game of Pong:
- go to center after hit.
- trace position of ball.
- more...
- The NPC makes guesses that are innacurate when the ball is far away, and its guesses get more accurate as the ball gets closer.
- to add to levels of skill, restrict the speed of the paddle for lower levels, allowing less margin of error, and making it easier to beat the NPC.
Those are some ideas for how the AI can think. Make sense?
- Progressive levels of skill.
- Come up with strategies in the game of Pong:
- go to center after hit.
- trace position of ball.
- more...
- The NPC makes guesses that are innacurate when the ball is far away, and its guesses get more accurate as the ball gets closer.
- to add to levels of skill, restrict the speed of the paddle for lower levels, allowing less margin of error, and making it easier to beat the NPC.
Those are some ideas for how the AI can think. Make sense?
kelcharge-
For a simple game your technique would be fine. However if the balls horizontal velocity can be larger than the maximum velocity of the paddle then AI would definately be needed.
Using your simple code, the way to beat the computer would simply be make the ball go at a large enough angle that it moves faster in the horizontal plane than the computers paddle can move.
However with AI, the paddle could calculate the position the ball will end up given it's current position and velocity. That way it won't bother chasing the ball to one side if it knows that it will bounce of the wall and end up back in the middle again.
If I were writing this I'd start by writing a naive approach where the padel goes towards the balls current position, and then write more complex algorithm's.
Doolwind
For a simple game your technique would be fine. However if the balls horizontal velocity can be larger than the maximum velocity of the paddle then AI would definately be needed.
Using your simple code, the way to beat the computer would simply be make the ball go at a large enough angle that it moves faster in the horizontal plane than the computers paddle can move.
However with AI, the paddle could calculate the position the ball will end up given it's current position and velocity. That way it won't bother chasing the ball to one side if it knows that it will bounce of the wall and end up back in the middle again.
If I were writing this I'd start by writing a naive approach where the padel goes towards the balls current position, and then write more complex algorithm's.
Doolwind
Quote: Original post by Doolwind
However with AI, the paddle could calculate the position the ball will end up given it's current position and velocity. That way it won't bother chasing the ball to one side if it knows that it will bounce of the wall and end up back in the middle again.
Try shooting a ray from the ball’s position in the direction of the ball’s velocity, reflecting it off the side walls, and calculating the intersection point with the AI paddles movement plane to find where the AI should move. Worked like a charm for me. :)
Hopet this helps,
Jackson Allan
-----------Autumn Fog - A 2D Action Wargame
This does bring up a good question though, and one that I've been thinking for a while... with the latter approach (ray tracing and such), the paddle will always know exactly where the ball will be.
Does that mean that you have to program mistakes into the AI? It sounds like it does... which seems strangely counterintuitive to me. What approach do you guys have toward making it so that complex AI will "screw up" thus allowing the game to be playable?
Does that mean that you have to program mistakes into the AI? It sounds like it does... which seems strangely counterintuitive to me. What approach do you guys have toward making it so that complex AI will "screw up" thus allowing the game to be playable?
-Vendal Thornheart=) Programming for a better tomorrow... well,for a better simulated tomorrow. ;)
Quote: Original post by VThornheart
This does bring up a good question though, and one that I've been thinking for a while... with the latter approach (ray tracing and such), the paddle will always know exactly where the ball will be.
Does that mean that you have to program mistakes into the AI? It sounds like it does... which seems strangely counterintuitive to me. What approach do you guys have toward making it so that complex AI will "screw up" thus allowing the game to be playable?
Instead of calculating the ray precisely, you can add some random number during the calculation that it will miss by a certain degree.
I found that, as the ball velocity increases with each progressive hit, the AI will still miss the ball within a reasonable time frame if the player has it move back and forth to catch the ball (but this really depends on how fast you allow your paddles to move).
One thing that made the game much more exciting was to have the AI hit the ball to the opposite side that the player was on. I didn’t actually make this game (helped a friend program it), but I do recall it was as simple as determining whether the player’s paddle was closer to the left or right edge of screen and then moving to hit the ball to the other end. This produced AI that was fun to play against, yet not impossibly difficult.
Jackson Allan
One thing that made the game much more exciting was to have the AI hit the ball to the opposite side that the player was on. I didn’t actually make this game (helped a friend program it), but I do recall it was as simple as determining whether the player’s paddle was closer to the left or right edge of screen and then moving to hit the ball to the other end. This produced AI that was fun to play against, yet not impossibly difficult.
Jackson Allan
-----------Autumn Fog - A 2D Action Wargame
depending on if your paddle is stationary, moving up, or moving down the ball can be deflected in 3 different directions when it bounces
(assuming you are using simple digital style paddes, these are 3 discrete states)
thus each rebound creates 3 possible branches
in between rebound events the ball follows a stright predictable path
-your AI can choose 3 possible ball return paths
and you know that assuming the player sucessfully hits the ball there will be 3 possible points where the ball will come back to the AI side
paddle speeds are also finite; they can only move within a predicted distance over time
so, have the AI, upon hitting the ball do a minimax search to decide which of 3 ways to return the ball
and find a chain of events that will lead to the player's paddle being unable to reach the ball in time when it gets to him
depending on how you set up your playfield size, paddle speeds, and ball max speed, the game of pong may in fact be closed, and you can guarantee a win
(assuming you are using simple digital style paddes, these are 3 discrete states)
thus each rebound creates 3 possible branches
in between rebound events the ball follows a stright predictable path
-your AI can choose 3 possible ball return paths
and you know that assuming the player sucessfully hits the ball there will be 3 possible points where the ball will come back to the AI side
paddle speeds are also finite; they can only move within a predicted distance over time
so, have the AI, upon hitting the ball do a minimax search to decide which of 3 ways to return the ball
and find a chain of events that will lead to the player's paddle being unable to reach the ball in time when it gets to him
depending on how you set up your playfield size, paddle speeds, and ball max speed, the game of pong may in fact be closed, and you can guarantee a win
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement