Jump to content
  • Advertisement
Sign in to follow this  

AI for an Air Hockey player

This topic is 3973 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

The most basic school of thought is design a set of layered behaviors, which can be used as components in a state machine.

At the lowest level there is are two competencies
* setting a new trajectory for the puck (a path which includes time information) for the puck.
* estimating future states of the puck

At the middle layer you can add a number of basic air hockey defensive and attacking techniques
* standard block
* block off sidewall in the AI half (when you 'set' the puck to be slammed into the other half)
* standard attack
* sidewall attack in the opponent half (useful when the opponent comes forward).

At the top layer you can use an state evaluation function (state machine) to select the technique which is most appropriate at the current time.

An alternative to the state machine/layered behaviors is machine learning. Although these techniques might work, but it would probably be a bit of a stretch to get something like that going in a reasonable amount of (your) time. The basic concept is to try to maximize the probability of scoring goals, whilst minimizing the chance of the opponent scoring goals.

The problem with even something as simple as air hockey is that the problem is large. The state space is quite large (velocities and positions for the two players and the puck), continuous and contains significant discontinuities (collisions) in some regions. The actions space is more reasonable (velocity of the ai), but is still continuous.

As for specific ML techniques, anything which results in a function which maps states to inputs will result in *a* strategy, but controlling the level of difficulty of the ai is hard. Although something like NN might work, they're probably not worth the time you'll spend on training and debugging. AFAIK a 12D state-space is probably verging on being too difficult to solve with standard dynamic programming / reinforcement learning techniques.

google keep-away soccer, a simplified robocup variant if you're interested in a hybrid behavior / reinforcement learning approach.

Share this post

Link to post
Share on other sites
ok i know that this is a fairly old and dead-looking thread at the moment and that a fairly comprehensive list of ideas has already been suggested, but I'm currently working on the ai for a tennis game and so thought I would share my thoughts.

I think the important thing to realise here is that the state space for this game is as good as infinite, unless you generalise greatly (i.e. divide the board up into sections and store the grid position of the puck and the paddles) but this would lose precision which would not be ideal for such a fast moving game. I think any form of reasoning about future game states (i.e. planning or other forms of look ahead) are pretty much out.
I also think that learning may be a bit much here and any sophisticated methods could be overkill but you may wish to do something like log the rough positions in which the enemy tends to strike or defend so that you can look for patterns in their behaviour to help assist defensive positioning or shooting positioning.

I would suggest using a kind-of sketchy plan inasmuch as you devise a simple strategy and then let the mathematics decide on most of the tactics for you. I think that the strategy part is reasonably simple but the maths could be tricky, but given that this is a 2d game, some elements could be simplified by this.

Instead of thinking in states, how about thinking in objectives? I would suggest that the objectives would be something like

1. Move to defensive position.
2. Move to an attacking position.
3. Strike the puck

which would loop until a point is scored. It is important that the Ai knows about the acceleration and top speed that it can achieve when moving its paddle so that it can mathematically calculate how it can hit the moving puck. I will know describe each state

1. Move to defensive position:

This objective should be triggered at a sensible time i.e. either when the Ai hits the puck, or the puck moves beyond a point of reach into the opponents half. I would suggest that the best defensive position would be close to your own goal somewhere along the line that can be drawn between the puck and the center of your goal. Now wait for either the puck to be struck or for it to move to such a position that your opponent can no longer hit it.

2. Move to an attacking position.

This is the hard part. On transition to this objective, you will need to calculate the entire path of the puck until it either goes into your goal, or goes back into your opponents half and out of your reach. This is the maths part because you will need to then find the best position on that line to strike the puck, and then find the best position for your paddle to be before it commits to the shot, so that it can be moved towards the puck to hit it towards your opponents goal. Several things could happen after calculating this line:

- The puck will go into your goal without you being able to reach it in time, in which case, just try to reach the puck anyhow. You will fail, but it will look like you have at least tried
- The puck will bounce about and go back into the opponents half without you having a chance to hit itm in which case, go back to objective 1
- You will be unable to get a decent strike on goal, but you should at least attempt to hit the puck towards their end
- You will be able to hit the puck back towards their goal. I would suggest finding the position that will allow you the most momentum on the puck as a decent heuristic here. Hitting it harder will give more accuracy. Remember that you can hit the puck off of the walls too

3. Strike the puck

Assuming that everything went according to plan, this bit should be a simple case of finding the line of closest approach and striking the puck. Go straight back to objective 1.

Whoops, sorry. Got a bit carried away there! But to summarise, I would devise a simple strategy like I have suggested and then let maths mostly carry out the rest. You can use pattern matching or even randomness to help decide on the defensive and attacking tactics, but I would see how the Ai performs without it first, it may not be needed. Good luck!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!