Where to start with AI in a game?!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2009
Posts: 91
Reputation: athlon32 is on a distinguished road 
Solved Threads: 16
athlon32's Avatar
athlon32 athlon32 is offline Offline
Junior Poster in Training

Where to start with AI in a game?!

 
0
  #1
Jun 26th, 2009
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
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/
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

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

 
0
  #2
Jun 26th, 2009
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 ...
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 476
Reputation: csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice 
Solved Threads: 76
csurfer's Avatar
csurfer csurfer is offline Offline
Posting Pro in Training

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

 
0
  #3
Jun 26th, 2009
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.
I Surf in "C"....
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,439
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 118
Sponsor
William Hemsworth William Hemsworth is online now Online
Nearly a Posting Virtuoso

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

 
0
  #4
Jun 26th, 2009
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:
  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.
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 91
Reputation: athlon32 is on a distinguished road 
Solved Threads: 16
athlon32's Avatar
athlon32 athlon32 is offline Offline
Junior Poster in Training

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

 
0
  #5
Jun 26th, 2009
Originally Posted by William Hemsworth View Post
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:
  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
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/
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 117
Reputation: u8sand is on a distinguished road 
Solved Threads: 15
u8sand's Avatar
u8sand u8sand is offline Offline
Junior Poster

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

 
0
  #6
Jun 27th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 397
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz

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

 
1
  #7
Jun 28th, 2009
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]
experience is the most expensive way to learn anything
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 91
Reputation: athlon32 is on a distinguished road 
Solved Threads: 16
athlon32's Avatar
athlon32 athlon32 is offline Offline
Junior Poster in Training

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

 
0
  #8
Jun 28th, 2009
Originally Posted by StuXYZ View Post
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!
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/
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC