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

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 ...

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.

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:

if (ball.y < bot.y) {
  bot.y -= 5;
}
if (ball.y > bot.y) {
  bot.y += 5;
}

As for making it an even game, just do some trial & error until the difficulty seems right.

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:

if (ball.y < bot.y) {
  bot.y -= 5;
}
if (ball.y > bot.y) {
  bot.y += 5;
}

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

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.

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]

commented: Thanks DUDE!!!! +1

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.