Should be simple: Air hockey AI
Hi guys!
The game:
The game I'm working on is nothing special: just another air-hockey game ;-)
The world is very simple: 2 players (each moving a bat) and a puk on a rectangular playing field (yeah, just like pong).
What should the AI do?
The AI has to one thing only: move its bat in x and y directions.
This should be done in a way to avoid hits into his own goal, and to score at the opponent's goal.
Of course "human" behavior would be nice, so that the AI makes mistakes (like hitting the ball in an undesired way or missing it completely).
My question:
How can these simple strategic rules be "translated" to x and y movements of the AI's bat?
My first idea was the following:
Just calcute the ideal position for the bat (e.g. in collision course to the ball) and move there. Repeat this constantly.
But I'm not sure if that would result in a good/natural looking bat-movement, or if it works at all ;-)
Any ideas? Thanks!
Hi, there are two aproaches i might take, both involve working out the best place to put the bar/bat.
Get the vector of the ball and work out exactly where it will end up after bouncing, this will involve working out bounces off walls etc.
This involves some relatively simple maths as you can work out where on the wall it will hit and bounce.
To make it more human you can:
1. make the predictions later i.e. when the ball reaches a certain distance down the table, this will give human like reactions as the paddle will move later making it harder to get to the ball.
2.Adding a random element to it by placing a small randomness in each of the vector predictions so the computer doesn't get the hits too right. This needs to be experimented with the get the right amount of randomness.
To add hardness, reduce randomness, increase "seeing/prediction" distance and or shrink the goals (i think this is the classic method).
To make the movement to the place you have set, just simply move towards it at the normal player speed, it should look quite natural.
If you need more help on the exact math needed feel free to post back here.
PureBlackSin
Get the vector of the ball and work out exactly where it will end up after bouncing, this will involve working out bounces off walls etc.
This involves some relatively simple maths as you can work out where on the wall it will hit and bounce.
To make it more human you can:
1. make the predictions later i.e. when the ball reaches a certain distance down the table, this will give human like reactions as the paddle will move later making it harder to get to the ball.
2.Adding a random element to it by placing a small randomness in each of the vector predictions so the computer doesn't get the hits too right. This needs to be experimented with the get the right amount of randomness.
To add hardness, reduce randomness, increase "seeing/prediction" distance and or shrink the goals (i think this is the classic method).
To make the movement to the place you have set, just simply move towards it at the normal player speed, it should look quite natural.
If you need more help on the exact math needed feel free to post back here.
PureBlackSin
For Games, Articles and Custom High End Computers, come visit.Myndoko
Quote: Original post by VanKurtIn the air hockey tables I've seen, the bat is round, and its rotation might spin the puck and alter its bouncing. Since there is a person's arm beyond the bat, bat position (and orientation if not round), velocity and angular velocity, are dependent variables; the control variables are the force and torque applied to the bat.
Hi guys!
The game:
The game I'm working on is nothing special: just another air-hockey game ;-)
The world is very simple: 2 players (each moving a bat) and a puk on a rectangular playing field (yeah, just like pong).
What should the AI do?
The AI has to one thing only: move its bat in x and y directions.
To complicate realistic control, the movement of the bat in a person's hand is constrained to 2D but it isn't isotropical like, say, the movement of a NC mill or a bridge crane: there is a specific comfort zone at arm's length, far from which movements are slower and weaker; only curved bat trajectories come natural; and moving the bat particularly close or far requires slow and fatiguing movements of the whole body.
Maybe you could make an articulated model (feet and bent body, shoulder, arm, hand and bat) and convert, for player and AI alike, forward movement controls to highly nonlinear bending of the body (to move the shoulder) and lateral movement controls to more or less circular sweeps of the arm around the shoulder; adjusting the lateral position of the feet and bending the arm can be slower automatic processes.
Quote:The peculiar simplicity, symmetry and strategic statelessness of the game suggest that simple rules that instantaneously express the control variables as a function of the dynamical state of the puck and of both players should be enough. Note that the control needs not change at every frame.
This should be done in a way to avoid hits into his own goal, and to score at the opponent's goal.
Of course "human" behavior would be nice, so that the AI makes mistakes (like hitting the ball in an undesired way or missing it completely).
My question:
How can these simple strategic rules be "translated" to x and y movements of the AI's bat?
Some rules could be hand-coded, some could be learned and interpolated from a record of what human players have been observed to do in the same case; human-like errors could be obtained by randomly picking bad moves rather than good moves from the rule base (either blindly, or deliberately, after classifying them as good or bad moves).
Omae Wa Mou Shindeiru
The standard AI for pong moves the paddle up when the ball is above the paddle, and down when the ball is below the paddle, and does so at a fixed velocity. This is simple to implement, simple to tweak for difficulty (by modifying the movement speed), and encourages audacious banked shots.
Another thing to possibly consider is that you need to impact the puck to make it move fast (unlike in pong, where the ball has a perfectly elastic collision with the paddle. That means you need to do a little preplanning - not moving the paddle to where you want to impact the puck, but a place behind that, and you'd need to time when to make the strike (push the paddle into the puck)
Sounds like a fun problem to work on!
Sounds like a fun problem to work on!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement