State Driven Agents

Team Sport AI
CIS 479/579
Bruce R. Maxim
UM-Dearborn
7/13/2017
1
Game Objects
•
•
•
•
•
•
Soccer pitch
Two goals
One ball
Two teams
Eight field players
Two goalkeepers
7/13/2017
2
SoccerPitch.h
• Rectangular playing area enclosed by walls
• Contains pointers to ball, two teams, and two
goals
• Pitch is divided into 18 regions (3 by 6)
numbered 0 to 17
• Each player assigned to a home region at start
of play and after each goal
• Player regions change during play to
implement team strategy (e.g. push forward on
attack)
7/13/2017
3
SoccerPitch.cpp
• The main game loop calls Update and
Render each iteration
• The corresponding Update methods for the
team and ball objects are called
• The appropriate Render methods are called
to draw new images of the pitch, ball, and
team formations are call
7/13/2017
4
Goal.h
• Goals are defined by a left goal post, a right
goal post, and a scoring direction
• Basically used to check for ball crossing
between goal posts
• Resets player positions and indicates a
scoring change to be processed elsewhere
7/13/2017
5
SoccerBall.h
• Derived from MovingEntity
• Contains data members for updated ball
position, player possessing the ball, and local
wall boundaries
• Contains additional methods for
– Kicking the ball
– Testing for collisions with objects (not players)
– Calculating future ball positions
7/13/2017
6
SoccerBall.cpp
• FuturePosition
– Calculates future ball position applying a frictional
constant using the usual formula
• TimeToCoverDistance
– Time to travel from point A to point B given the
amount of force applied to ball
7/13/2017
7
AI Design
• Two player types (goalkeeper, field player)
derived from PlayerBase
• All players make use of reduced version of
SteeringBehaviors class
• The SoccerTeam and players classes make
use of the StateMachine class to implement
tiered AI (common to RTS games)
• Players can send messages (telegrams) to
each other, but not the entire team
7/13/2017
8
SoccerTeam
• Contains pointers to pitch, home goal,
opponent goal, team players, opponent
players, and key players
–
–
–
–
7/13/2017
Receiving player
Closest player to ball
Controlling player
Supporting player (moves to spot determined by
calculating the best support spot based on goal
scoring potential)
9
Team States
• Prepare for kick off
– Players sent to home regions, sets key player
pointers to NULL, state change to defending
• Defending
– Players move to regions closer to home goal,
when ball regained state changes to attacking
• Attacking
– Some players advance to regions closer to
opponent goal, best support spot determined,
pass or shot, when ball lost state becomes
defending
7/13/2017
10
Field Players
•
•
•
•
Derived from same base class
Come in two flavors, attackers and defenders
Player motion is velocity aligned
Motionless players turn to face the ball (as a
human player might)
• Players use the arrive, seek, and pursuit
behaviors to help them chase the ball (these
behaviors turned on in state Enter method
and turned off in Exit method)
7/13/2017
11
Field Player States
•
•
•
•
•
•
•
•
GlobalPlayerState
Wait
ReceiveBall
KickBall
Dribble
ChaseBall
ReturnToHomeRegion
SupportAttacker
7/13/2017
12
Player Messages
• Msg_SupportAttacker
– Sent by controlling player to move pass receiver
• Msg_GoHome
– Return to home region
• Msg_ReceiveBall
– Sent to receiving player when pass is made
• Msg_PassToMe
– Sent to controlling player from potential scoring
player
• Msg_Wait
– Player should hold position
7/13/2017
13
ChaseBall State
• Player will seek ball’s current postion and try
to get in kicking range and is able change
state to KickBall
• Remains in this state as long as player is
closest team member from ball
7/13/2017
14
Wait
• Tries to maintain position, even if bumped out
of position by another player
• If upfield from controlling player player will
call for a pass, if pass can be made player
changes state to receive the ball
• If waiting player becomes closest to ball, it will
change state to chase ball
7/13/2017
15
Receive Ball
• At most, only one player on a team may be in
this state
• The receiving player sets steering to the
target position for pass
• Both arrive and pursuit can be used to
approximate the most believable behavior to
intercepting the ball trajectory
7/13/2017
16
Kick Ball
• Implements the logic for passing or shooting on
opponent goal
• If player cannot pass or shoot, state change to
dribble is made
• Player cannot remain in KickBall state for more that
one update cycle
• State entered when player comes within kicking
distance of the ball, steering used to intersect ball
position
• Player moves to wait state after kick
7/13/2017
17
Dribble
• Teammates notified that controlling player is
moving the ball
• May need to turn ball to move toward
opponent goal
• Player makes small kick and changes state to
chase ball
• Continues until pass or shot is possible
7/13/2017
18
Support Attacker
• First action by controlling player is to find
potential support player and send a message
• SupportSpotCalculator determines which
player to change state
• On entering the state, the arrive behavior is
switched on and steering behavior directed
toward location of BSS
• If a safe pass can be made the state will
move to receive pass
7/13/2017
19
Goalkeeper States
•
•
•
•
•
GlobalKeeperState
TendGoal
ReturnHome
PutBallBackInPlay
InterceptBall
7/13/2017
20
Tend Goal
• Keeper move laterally across goal mouth
trying to keep body between goal and ball
• Relies on the interpose behavior
• If ball is close to keeper state changes to put
ball back in play
• If ball is in intercept range state changes to
intercept ball
• If keeper to too far from goal after intercept
and return to tend goal stay change to return
home will be made
7/13/2017
21
Return Home
• Steers goalkeeper toward home region
• When home region reached state or
opponents gain control of the ball changes to
tend goal state
7/13/2017
22
Put Ball In Play
• When keeper gains possession of ball it
enters this state
• Keeper announces this fact to team and
players return to their home regions
• Once a player is in position to receive a clean
pass a message is sent to let the player know
that the ball is one the way and state changes
to tend goal
7/13/2017
23
Intercept Ball
• If opponent with ball enters threat range
keeper will use pursuit behavior and move
toward the ball
• Monitors distance from its home goal and
may change state to return home if “too far”
from goal
• If ball is out of goal range and keeper is
closest player keeper continues after the ball
7/13/2017
24
SoccerTeam::
isPassSafeFromAllOpponents
• Method used to determine if ball trajectory
from point A to B can be intercepted by any
opponent player for proposed kicking force
• Assumes ball can be kicked harder than
closest player’s maximum speed
• Opponent’s farther away from target than
intended receiver can also be ignored
• Best interception opportunity will be for player
running perpendicularly to ball trajectory
using bounding circle (or ellipse) approach
7/13/2017
25
SoccerTeam::CanShoot
• Player in possession of ball queries
CanShoot
• Selects a number of random positions in front
of the goal mouth and tests them for shot
without interception by any opponent
7/13/2017
26
SoccerTeam::FindPass
• Called by player to see if pass to teammate is
possible
• If so pick best teammate and target position
by trying each teammate one at a time using
GetBestPassToReceiver
• Parameters: passer, pass target, kicking
force, minimum distance for receiver
• Returns receiver and target location
7/13/2017
27
SoccerTeam::
GetBestPassToReceiver
• Examines several positions around potential
receiver to find safe passing target
• Returns best target location and a Boolean
indication whether location is safe
• Takes vision range into account as well as
distance from passer and receivers lateral
range of motion
7/13/2017
28
Estimates and Assumptions
• Don’t want perfect AI behavior, so using
estimates and heuristics is better than using
exact physics modeling
• You could do perfect calculations and dumb
down the AI (systematic errors or random
noise)
• You could make some assumptions that
prevent perfect play (bounding circles rather
ellipses that take turning time into account)
7/13/2017
29