Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

AJFleming

AI Ideas for Air-Hockey Simulator

This topic is 5844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I''ve been playing around with an air-hockey simulation (dull and boring I know, but it''s a simple enough domain for a first attempt at a simulation-style-game.) I''ve got a basic front-end, the physics more or less as I want it, and the control code written and all of it plays happily together. I''m now looking at implementing some simple AI for the game. I''ve been giving it some thought and digging around on the net a bit, but I can''t seem to find a simple starting point. I found a really useful paper on machine learning for air-hockey simulations, but it seems a little heavy-duty for what I''m looking at. Basically, I''m looking for a simple heuristic which won''t result in the opponent being completely unbeatable! Anyone got any ideas or comments? cheers, Adam...

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by InnocuousFox
Wouldn't it just be a modified Pong AI?



Apologies to anyone who read my response before I editted it... Just done some digging around looking at Pong AI and I can ask questions a little (!) more intelligently now

From what I've seen, all the Pong alorithms appear to be defensive - which isn't going to make for a fun air-hockey simulation. They also appear to assume one-dimensional movement which isn't the case in my system.

However, the various resources I've found (mostly here on the Forum) have given me a couple of ideas to work with.

Has anyone seen any examples, or would anyone have any suggestions on how Pong-style AI might be extended to a more complex game (such as air-hockey - or table-football which is the next project ) ? How do people generally approach problems such as this, where in the real world a game is based more heavily on reaction time and physical factors (like how hard you hit something)? It seems to me that it's relatively easy to write AI systems with complete knowledge, but which would be unbeatable - even if real-world limits on bat-movement and the like are imposed. So how do you go about toning down the intelligence of a system?

My apologies if any of the above sound like newbie questions - I haven't really tried writing AI systems for games before...

cheers,

Adam...

[edited by - AJFleming on June 10, 2002 5:22:08 PM]

Share this post


Link to post
Share on other sites
Well, I''m thinking Pong AI would be mostly math and geometry. Calculate the current path of the puck and move to intercept. Advances to that would be then calculating a slightly different position so that your round paddle and direction of stroke would send the puck in a direction other than a direct (mirror)reflection. Advances to that would be pre-calculated but randomly selected shots (direct, bank left, bank right, double bank) to throw off the human player. All of this would have to include a +/- error to humanize it. *shrug*

Dave Mark
President and Lead Designer
Intrinsic Algorithm Development

"Reducing the world to mathematical equations!"

Share this post


Link to post
Share on other sites
Hi IF,

thanks for your comments.

One problem that I can see though - each shot type (straight, single deflection, double deflection etc) would have an infinite number of possible strokes to effect it - especially since the physics model of this system (kind of) takes account of spin during collisions. I guess some kind of stroke-generation engine would be required in order to make the system work. This would allow for further "humanisation" though - if different strokes could be characterised as "easy" "hard" "agressive" etc...

Hmmm, have to give this some more thought...

cheers,

Adam...

Share this post


Link to post
Share on other sites
Yeah... that''s your best bet.

Step 1: What is the path of the puck?
Step 2: What sort of shot should I take?
Step 3: Calculate the intercept point of the puck path and the stroke path in order to generate the proper angle, spin, etc.
Step 4: Fuzzify step 3 in order to humanize the outcome.

Dave Mark
President and Lead Designer
Intrinsic Algorithm Development

"Reducing the world to mathematical equations!"

Share this post


Link to post
Share on other sites
simple pong ai:

if(ball.x>paddle.x)
movePaddleRight();
else
if(ball.x movePaddleLeft();

it is only unbeatable if the paddle can move as fast as the ball, ussually there is some "trick" shot in which you move the paddle as it collides to cause the ball to have greater velocity. done enough times and the cpu cant keep up. you can improve this by allow slower reaction time (ie the cpu waits longer before moving the paddle), slower paddle speed, randomness in cpud movement (ie sometimes the cpu overshoots the ball and must adjust).

ai is just the mimicing of something just like physics in games. it dont always need complex algorithms. heck gravity is a complex reaction of forces on mnay objects dependent on mass, distance, etc. in games, its reduced to a simple constant since its a suitable replacement. not all things can be simplified as nicly, but most can be simplfied with acceptable results.

Share this post


Link to post
Share on other sites
If you want to tone down the AI as you said, you could do it like Innocuous Fox said - Calculate the best path of the puck and have the AI player try to hit it there, but randomize it a little. Then you could have difficulty levels by increasing the chance that the AI player can actually produce the perfect shot. Say the "Hard AI" player has an 80% chance of making the perfect shot, while the "Easy AI" player has more like a 40% chance. That way the dumb player can still get lucky It might be kinda fun to implement that way.

"I''ve never seen that. I''ve never seen anybody drive their garbage down to the side of the street and bang the hell out of it with a stick. I''ve never seen that."

Share this post


Link to post
Share on other sites
Several people have talked about adding a random factor to the response function of the CPU paddle to ''humanise'' the game play. There is a better way. Add uncertainty into the predictability of the CPU.

The basic idea is that you provide noisy observations on the position of the puck at different times (every frame, every 5th frame, every 20th frame,... whatever interval you choose). The CPU then has to predict the puck velocity and respond to it. How it responds is a tactical procedure. What shot it attempts to play is a strategic procedure.

Anyway, to get back to the filtering. Implement a simple linear Kalman filter to predict the velocity of the puck given observations on position. The output of the filter applied to a linear system is the mean and covariance of a guassian distribution on position and velocity.

Once you have these, you can use the prediction step of the algorithm to predict the position and velocity at any future time. In the absence of observations (during prediction) the uncertainty in the predicted posterior distribution will be proportional to the prediction time interval... so the longer ahead of time the prediction, the more uncertainty. The closer the puck gets to the paddle, the better able the system is to predict the point at which the puck will cross a certain point.

You can use the predictions to plan shots. The earliest predictions will give a feel for where the puck is going to end up and with what trajectory. Given the uncertainty in speed, direction and position of puck, there might be a couple of different return shots that are appropriate. A choice could be made based on the ''set up time'' for the shot, which would be inversely proportional to the speed of the puck. Or perhaps on some other constraint that enabled the system to respond quickly in defensive situations (where the puck is coming in fast), or set up a complex shot if more time allowed (where the puck is coming in slow).

This would then approximate how humans play games like air hockey.

If you need advice on implementing a kalman filter, just holler.

Cheers,

Timkin

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!