5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

29
06/27/22 1 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn

Transcript of 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

Page 1: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 1

Team Sport AI

CIS 479/579

Bruce R. Maxim

UM-Dearborn

Page 2: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 2

Game Objects

• Soccer pitch• Two goals• One ball• Two teams• Eight field players• Two goalkeepers

Page 3: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 3

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)

Page 4: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 4

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

Page 5: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 5

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

Page 6: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 6

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

Page 7: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 7

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

Page 8: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 8

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

Page 9: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 9

SoccerTeam

• Contains pointers to pitch, home goal, opponent goal, team players, opponent players, and key players– 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)

Page 10: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 10

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

Page 11: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 11

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)

Page 12: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 12

Field Player States

• GlobalPlayerState• Wait• ReceiveBall• KickBall• Dribble• ChaseBall• ReturnToHomeRegion• SupportAttacker

Page 13: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 13

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

Page 14: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 14

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

Page 15: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 15

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

Page 16: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 16

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

Page 17: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 17

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

Page 18: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 18

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

Page 19: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 19

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

Page 20: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 20

Goalkeeper States

• GlobalKeeperState• TendGoal• ReturnHome• PutBallBackInPlay• InterceptBall

Page 21: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 21

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

Page 22: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 22

Return Home

• Steers goalkeeper toward home region• When home region reached state or

opponents gain control of the ball changes to tend goal state

Page 23: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 23

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

Page 24: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 24

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

Page 25: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 25

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

Page 26: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 26

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

Page 27: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 27

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

Page 28: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 28

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

Page 29: 5/18/20151 Team Sport AI CIS 479/579 Bruce R. Maxim UM-Dearborn.

04/18/23 29

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)