| | |
Where to start with AI in a game?!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I've decided to start my first real project in C++, so I picked something simple; to make a game just like Pong. I've got most of the GUI setup, but i have no idea where to start on programming the computer character that will play against the user. Does anyone know where to start with something like this???
Thanks in advance
~ mike
Thanks in advance
~ mike
I'm pretty much a noob! I'm here to learn new things and to gain skillz by observing and helpin'. I'll try to help you to the best of my abilities, and apparently the guys on here aren't cool enough to appreciate my rep begging :(
Look, it's a link!!!!
http://shallweprogram.blogspot.com/
Look, it's a link!!!!
http://shallweprogram.blogspot.com/
very open ended question, and many possible answers. i think you are going to need to provide some information on your design (not just interface) to get solid answers.
if it were me, i would be looking at adding some smarts into the computer player in between each movement of the pong ball. this would involve some kind of prediction of where the ball is heading.
there are many many consideration that need to be taken into account like the behaviour of the computer player, are they limited in slider speed? will it just "teleport" the slider and guess? what restrictions need to be placed on the computer so it is not invincible? etc...
i hope this is the sort of answer you were looking for ...
if it were me, i would be looking at adding some smarts into the computer player in between each movement of the pong ball. this would involve some kind of prediction of where the ball is heading.
there are many many consideration that need to be taken into account like the behaviour of the computer player, are they limited in slider speed? will it just "teleport" the slider and guess? what restrictions need to be placed on the computer so it is not invincible? etc...
i hope this is the sort of answer you were looking for ...
•
•
Join Date: Mar 2008
Posts: 1,439
Reputation:
Solved Threads: 118
In a game of Pong?
Making the bot really isn't difficult in a game such as this, the main functionality would be something like this: As for making it an even game, just do some trial & error until the difficulty seems right.
Making the bot really isn't difficult in a game such as this, the main functionality would be something like this:
C++ Syntax (Toggle Plain Text)
if (ball.y < bot.y) { bot.y -= 5; } if (ball.y > bot.y) { bot.y += 5; }
Last edited by William Hemsworth; Jun 26th, 2009 at 11:12 am.
I need pageviews! most fun profile ever :)
•
•
•
•
In a game of Pong?
Making the bot really isn't difficult in a game such as this, the main functionality would be something like this:As for making it an even game, just do some trial & error until the difficulty seems right.C++ Syntax (Toggle Plain Text)
if (ball.y < bot.y) { bot.y -= 5; } if (ball.y > bot.y) { bot.y += 5; }
Thanks man I'm pretty much a noob! I'm here to learn new things and to gain skillz by observing and helpin'. I'll try to help you to the best of my abilities, and apparently the guys on here aren't cool enough to appreciate my rep begging :(
Look, it's a link!!!!
http://shallweprogram.blogspot.com/
Look, it's a link!!!!
http://shallweprogram.blogspot.com/
Like it says above you will NEED to add restrictions or it will be impossible :/. To make the AI I would make it so that you keep the center of the computers bar aligned along the Y axis with the ball. Almost like what was said above.
The AI is not hard at all in a game of Pong, whats hardest in pong is the mathematics of making the ball go up and down and in certain directions based on where it hits the bar.
The AI is not hard at all in a game of Pong, whats hardest in pong is the mathematics of making the ball go up and down and in certain directions based on where it hits the bar.
•
•
Join Date: Nov 2008
Posts: 397
Reputation:
Solved Threads: 72
If you are writing a Pong game, I think that you are going to learn a lot, so well done.
Second AI in Pong is interesting, there are at least three models:
(a) pure deterministic. That is the computer calculates exactly where is wants to be and tries to go there. TWO things need to be calculated in this (i) the ball position and (ii) the humans bat position because (normally, the edges of the bat give different angles to the ball exit tragectory).
(b) Pseudo random. The computer plays with perfect play but the information has a random error. It is often better to have larger random error from based on the distance that the ball is from the computers bat. The exact weighting value between 0 and 1 (ie. completely random and perfect info) give an excellent human/computer game play. [Adjust the value on each won point/game]
(c) Use a neural network to determine the position that the computer bat should go to, this again, can give excellent results, but the neural network can but untrained after each win to give excellent human/computer playability.
Just some thoughts on stuff I have tried in a couple of game simulations [not actually pong but very close]
Second AI in Pong is interesting, there are at least three models:
(a) pure deterministic. That is the computer calculates exactly where is wants to be and tries to go there. TWO things need to be calculated in this (i) the ball position and (ii) the humans bat position because (normally, the edges of the bat give different angles to the ball exit tragectory).
(b) Pseudo random. The computer plays with perfect play but the information has a random error. It is often better to have larger random error from based on the distance that the ball is from the computers bat. The exact weighting value between 0 and 1 (ie. completely random and perfect info) give an excellent human/computer game play. [Adjust the value on each won point/game]
(c) Use a neural network to determine the position that the computer bat should go to, this again, can give excellent results, but the neural network can but untrained after each win to give excellent human/computer playability.
Just some thoughts on stuff I have tried in a couple of game simulations [not actually pong but very close]
experience is the most expensive way to learn anything
•
•
•
•
If you are writing a Pong game, I think that you are going to learn a lot, so well done.
Second AI in Pong is interesting, there are at least three models:
(a) pure deterministic. That is the computer calculates exactly where is wants to be and tries to go there. TWO things need to be calculated in this (i) the ball position and (ii) the humans bat position because (normally, the edges of the bat give different angles to the ball exit tragectory).
(b) Pseudo random. The computer plays with perfect play but the information has a random error. It is often better to have larger random error from based on the distance that the ball is from the computers bat. The exact weighting value between 0 and 1 (ie. completely random and perfect info) give an excellent human/computer game play. [Adjust the value on each won point/game]
(c) Use a neural network to determine the position that the computer bat should go to, this again, can give excellent results, but the neural network can but untrained after each win to give excellent human/computer playability.
Just some thoughts on stuff I have tried in a couple of game simulations [not actually pong but very close]
I was really impressed by suggestion A, that's the one I will choose, Thanks! I'm pretty much a noob! I'm here to learn new things and to gain skillz by observing and helpin'. I'll try to help you to the best of my abilities, and apparently the guys on here aren't cool enough to appreciate my rep begging :(
Look, it's a link!!!!
http://shallweprogram.blogspot.com/
Look, it's a link!!!!
http://shallweprogram.blogspot.com/
![]() |
Similar Threads
- a bot for online game (Computer Science)
- Game won't start. (Command&Conquer) (Windows NT / 2000 / XP)
- How can I have both watching a movie and playing a game (Windows NT / 2000 / XP)
- Ea Nhl 2003 Wont Start?? Help Please? (Windows NT / 2000 / XP)
- Kids game raises volume levels by itself (Windows NT / 2000 / XP)
- HELP creating a multiserver game in VB winsock (Visual Basic 4 / 5 / 6)
- beginner needs help with game programming (Game Development)
- My comp freezes when I start a game (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Random C++ array
- Next Thread: Visual C++ 2008
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






