| Author |
Message |
Scott tutorialtoday.com

Joined: 24 Mar 2005 Posts: 2599 Location: Mississauga, Ontario
|
Posted: Thu Mar 13, 2008 7:53 am Post subject: Making Game AI |
|
|
I'm just messing around with OpenGL and making a simple pong game and I am wondering how you would make AI for a game using C++, specifically the other paddle in a pong game. _________________ Tutorial Management Script - Version 1.3 Released
TutorialToday - Up and running, submit your tutorials!
Linux Tutorials - Coming Soon |
|
| Back to top |
|
| |
Pie32 Not Banned

Joined: 17 Mar 2005 Posts: 1420 Location: Lost in 84
|
Posted: Thu Mar 13, 2008 9:35 am Post subject: |
|
|
AI I think is really tricky business, and even harder to program well. But, something for Pong is actually really simple. Back when I made a simple Pong clone, my AI was simply, "if the center of the ball is above the center of your paddle, move up; else if the center of the ball is below the center of your paddle, move down."
I would start with something like that. If your Pong game is as bad as mine was, that will make an impossible to beat AI. However, if your ball physics are better than constant speed and bounces that don't change the angle of the ball, then you may want to make some tweaks, such as maybe moving the paddle to the center when the ball is going away from it and then trying to keep in level with ball if it moves beyond x pixels of the center. _________________ [img]http://luneknight.com.ru/counter.jpg[/img]
Random Battle: [img]http://luneknight.com.ru/l.jpg[/img] vs. [img]http://luneknight.com.ru/r.jpg[/img] |
|
| Back to top |
|
| |
Scott tutorialtoday.com

Joined: 24 Mar 2005 Posts: 2599 Location: Mississauga, Ontario
|
Posted: Thu Mar 13, 2008 12:00 pm Post subject: |
|
|
Well I basically used what you said but made it a bit more beatable. I made the paddle (moves at 0.20f) move slower than the ball (moves at 0.25f).
I also made it so the paddle only moves when the ball is coming towards it.
Also, it only moves if the ball is above 60% of the paddle or below 40% of the paddle. So if it is in the middle 20% of the paddle then it won't move. If that made sense... _________________ Tutorial Management Script - Version 1.3 Released
TutorialToday - Up and running, submit your tutorials!
Linux Tutorials - Coming Soon |
|
| Back to top |
|
| |
Pie32 Not Banned

Joined: 17 Mar 2005 Posts: 1420 Location: Lost in 84
|
|
| Back to top |
|
| |
LP-SolidRaven Dictator of the Dump

Joined: 06 Jun 2004 Posts: 7036 Location: The cheese is made out of moon
|
Posted: Sat Mar 15, 2008 3:16 am Post subject: |
|
|
You should also make the pad move a bit randomly while the ball is at the other side  _________________
| Quote: |
<bart416> I just realized something
<bart416> we celebrate the fact that this piece of rock made one rotation around a glowing ball of plasma that is kept together due to its own gravity well
<njsg> HAPPY NEW YEAR
<Easter> ^^
|
|
|
| Back to top |
|
| |
flaran Master Poster

Joined: 03 Aug 2005 Posts: 178
|
Posted: Sat Apr 19, 2008 11:30 am Post subject: |
|
|
It seems that there are two practical limiters for AI at this level.
One is to make certain cases where it is impossible for the AI to win. In this case you can make it so that if the paddle is, say, at the bottom of the screen and you hit it towards the top it is incapable of moving it up fast enough. This way can work but players soon figure out patterns that will beat the AI every time. That makes this method a lot less effective.
There is also the choice of randomizing the effectiveness of the AI. This way, the bot will occasionally make mistakes (ex: hesitating or misjudging the location of the ball). As difficulty progresses, that chance of mistakes can lower.
I've thought about other ways of approaching AI for different games but these are the ones that really apply to pong from my point of view. |
|
| Back to top |
|
| |
|
|
|