AI design

Started by
4 comments, last by IADaveMark 19 years, 8 months ago
I have been working on an arcade-like air hockey game. To program the enemy, I have it move horizontally half as fast as the puck when the puck is on the other side of the board but moving closer, and when the puck is moving away from the enemy, it moves back to defend the goal. When the puck is on the same side of the enemy, it moves toward it. This works, but it's not exactly convincing. Any ideas would be helpful! ^_^
Advertisement
By enemy do you mean player 2 protecting their own goal?
You could get the AI to poll the position of the puck every second and react to the last known position, speed and direction by moving horizontal while it's far away... then when it's a little far away draw back a little and randomly either move forward or horizonal or a bit of both.

I suppose to get it to act more convincingly (human?) the movement has to appear less calculated... people often seem to stay still then pounce... sometimes moving back to the centre of the goal and sometimes not.

Some kind of finite state machine would be a pretty good place to start for this kind of AI I guess, although it also would lend itself to Neural Networks / Genetic AI - esp if you could automate the learning by allowing 2 computer players to play each other. Generic AI and NN tend to have a more organic feel to them then state machines, but a state machine would help you better define the problem domain into different player strategies.

Your project sounds pretty interesting, be sure to post about it if you finish!
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
thanks!
I set up a system so the opponent slows to a stop after it hits the puck, then start moving again after the player hits it back.
You were helpful! I'll be posting here again soon!
An ANN for this might not have to be too complex. If you have the AI move back to the goal (maybe a little randomly offsetted each time?) after hitting the puck, the ANN will be reacting from the same basic position everytime, simplifying things a lot.

Feed the position and vector of the puck into the ANN when the puck becomes within a min and max pair of radiuses from the goal, this simulates differing reaction times. Make that min/max pair close enough, and the AI will be able to react uniquely, but reliably.

The output could be a simple vector to move in. The longer the vector, the higher the velocity. Limit this, of course.

Train this manually, genetically, or through back-propagation, or some such and you might come up with a convincing AI player. Later, you might even add more ANNs, like one that controls the movement back to the goal, or one to pass the time until the reaction (move back and forth or something maybe?).

I'm a fan of multi-part AIs with events to trigger which are used when.
(http://www.ironfroggy.com/)(http://www.ironfroggy.com/pinch)
The complexity of your computer player (AI) will depend entirely on the complexity of your air-hockey simulation. Is your simulation a deterministic one, in that there is no friction between the puck and the table (and the puck and the air), no feedback between the puck and the airflow system, no uncertainty in bounce angles off the boards, no uncertainty in the bounce angles off the paddles, etc., etc.

If it is a perfect simulation with no uncertainty, then you can solve for the optimal behaviour of the computer paddle using simple geometry. If there is uncertainty in the pucks trajectory (because off all of the factors mentioned above) then you need some way of dealing with this uncertainty.

On top of this, you need a strategy... that is, given the puck coming in on a given trajectory, what is the computer going to try and do in terms of a return shot? Always shoot straight for the goal, go for a single rebound, try and sucker the player puck away from their goal with a fast shot, rebound and fast return shot? Maybe select these randomly from a list of possible 'shots'... that is, use a play book.

Cheers,

Timkin
This can all be done quite easily with the geometric prediction that has been discussed (for general positioning), a short-term response model (to handle any inaccuracies you build into your caroms as Timkin said), and a simple "playbook" of how to approach the next shot (which can be either purely random or deterministic depending on the state of the puck - e.g. slow moving could offer more shots whereas fast bouncing puck just equals "try and freaking hit it to stay alive!")

Considering your apparent level of knowledge coming into this problem, ignore the people how tell you to use ANNs. That's serious overkill.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

This topic is closed to new replies.

Advertisement