943,740 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 711
  • C++ RSS
Jun 26th, 2009
0

Where to start with AI in a game?!

Expand Post »
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
Similar Threads
Reputation Points: 67
Solved Threads: 16
Junior Poster in Training
athlon32 is offline Offline
97 posts
since Jan 2009
Jun 26th, 2009
0

Re: Where to start with AI in a game?!

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 ...
Reputation Points: 85
Solved Threads: 64
Practically a Master Poster
sillyboy is offline Offline
686 posts
since Mar 2007
Jun 26th, 2009
0

Re: Where to start with AI in a game?!

Quote ...
restrictions need to be placed on the computer so it is not invincible...
Concentrate on this part because it is very easy to make computer win everytime or to make it loose everytime,but randomizing the win or loss is difficult.
Reputation Points: 485
Solved Threads: 88
Posting Pro
csurfer is offline Offline
564 posts
since Jan 2009
Jun 26th, 2009
0

Re: Where to start with AI in a game?!

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:
C++ Syntax (Toggle Plain Text)
  1. if (ball.y < bot.y) {
  2. bot.y -= 5;
  3. }
  4. if (ball.y > bot.y) {
  5. bot.y += 5;
  6. }
As for making it an even game, just do some trial & error until the difficulty seems right.
Last edited by William Hemsworth; Jun 26th, 2009 at 11:12 am.
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008
Jun 26th, 2009
0

Re: Where to start with AI in a game?!

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:
C++ Syntax (Toggle Plain Text)
  1. if (ball.y < bot.y) {
  2. bot.y -= 5;
  3. }
  4. if (ball.y > bot.y) {
  5. bot.y += 5;
  6. }
As for making it an even game, just do some trial & error until the difficulty seems right.
This guy has the right idea Thanks man
Reputation Points: 67
Solved Threads: 16
Junior Poster in Training
athlon32 is offline Offline
97 posts
since Jan 2009
Jun 27th, 2009
0

Re: Where to start with AI in a game?!

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.
Reputation Points: 78
Solved Threads: 15
Junior Poster
u8sand is offline Offline
131 posts
since Dec 2008
Jun 28th, 2009
1

Re: Where to start with AI in a game?!

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]
Reputation Points: 732
Solved Threads: 134
Practically a Master Poster
StuXYZ is offline Offline
659 posts
since Nov 2008
Jun 28th, 2009
0

Re: Where to start with AI in a game?!

Click to Expand / Collapse  Quote originally posted by StuXYZ ...
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]
Hey man, great post I was really impressed by suggestion A, that's the one I will choose, Thanks!
Reputation Points: 67
Solved Threads: 16
Junior Poster in Training
athlon32 is offline Offline
97 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Random C++ array
Next Thread in C++ Forum Timeline: Visual C++ 2008





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC