620 likes | 909 Views
Sports Games: Artificial Intelligence and Physics. Sports Game Design and Development Architectures Class Structures Agent Cooperation Team based cooperation and Optimization Physics Object physics Agent physics Dead Reckoning Strategy Development Artificial and Human Elements. Topics.
E N D
Sports Game Design and Development • Architectures • Class Structures • Agent Cooperation • Team based cooperation and Optimization • Physics • Object physics • Agent physics • Dead Reckoning • Strategy Development • Artificial and Human Elements Topics
Simulating a natural, well-known environment • Modeling fields, courts, rinks, etc. • Modeling player personalities and animations • Physics engine • Strategy • Sports are a form of Real-Time strategy • Strategies while confined to a set of rules and the size of the field, are numerous and constantly changing Challenges
A well known fact: Video game detail has improved over the years • From Tecmo Bowl to Madden 2008 • Better player models • Larger fields, increased atmosphere • More intelligent AI • More modes, styles of play • Arcade versus Simulation • Longer play modes • Online play A Brief History
A Sports game has many CPU-Intensive tasks • Player animation • Route planning • Physics modeling • Strategy development • Breaking these down in a high level architecture confined by the rules of the game can help ease the complexity of the development Building a Sports AI Architecture
Layering the architecture Building a Sports AI Architecture
Plans • Offensive • Pass • Shoot • Drive to the basket • Defensive • Position the defender • Double team the ball handler • Shared • Rebound • Set up for a free throw • Plans enable the players to move freely and determine their own best routing methods • This level of abstraction provides a sense of realism to the game Building a Sports AI Architecture
Example planning class Class AgentPlan { float EvaluateInitiation(); float EvaluateContinuation(); void Initiate(); void Update(); } • Initiation and continuation are very important concepts because they determine if a plan is working and where to go next • Common return values are between -1.0 and 1.0 • Update is called for every tick to update the AI Building a Sports AI Architecture
High level strategy module sets a goal • An opportunity is seen to complete a through pass in front of the goal for a score • Plan is created • An opportunity is seen to complete a through pass in front of the goal for a score • Route finding plots course • Each player (opponent and team) is considered, momentum(team and player), and even ball planning • Execute plan • Not all plans will work out • Depending on the skill level of the other team and unforeseen occurrences, this leaves the game interesting Building a Sports AI Architecture
States • A game can be broken into states with responsibilities and transition points. • Moving from an offensive state to a defensive state • These states can govern the types of plans that will be used • In an offensive state you wouldn’t push all your defenders back • Well you might • But more often than not you will push defenders up so that they can support an offense and keep momentum moving in the positive direction Building a Sports AI Architecture
Agent AI • Well thought out collection of utility functions and data used by the plans • Determine a player’s chance of success • Determine the likelihood of certain actions • Dunks, lay-ups, bicycle kicks, etc • Based on real-world player abilities and conditions of the game • Perform the action and determine the type of action that can be performed by providing a wrapper to the mechanics Building a Sports AI Architecture
Agent Mechanics • Considered to be low-level AI • Manage and select animations to be used • Some of these decisions are determined through the use of a random number • This gives the effect that the game is more real • Humans do not always react to the same situation in the same way • This level also takes into consideration the kinds of commands that users would input into the system • Run • Shoot • Pass Building a Sports AI Architecture
Originally developed as a tool for navigators • Determining the position of his ship given parameters such as direction, intended course, and speed • Estimating position based on past position and trajectory • This becomes more complicated when other factors are taken into consideration • Wind or current Dead Reckoning
Inertia • Dead Reckoning at its most basic level reduces to Newton’s first law of motion • Knowing an object’s position and speed, we can assume the object will continue to travel in a straight line. • Pt = P0 + vt • Px,t+1 = Px,t + vx • Py,t+1 = Py,t + vy • Pz,t+1 = Pz,t + vz • These calculations can sometimes prove to be “too good” • Incorporating an error calculation might help • Even the best quarterbacks have a bad game Dead Reckoning
Pseudo- Brownian Motion • An extremely maneuverable object is harder to predict velocity vectors over lengths of time • In the case of a UFO which can do whatever it pleases (Or so we assume), knowing the velocity magnitude can only help us determine a spherical region of possible positioning • In sports games this can be observed as objects in motion which experience seemingly random movement which is an effect of outside forces • As a pass is being completed, a strong wind may blow and knock the ball off of its intended course. Dead Reckoning
Kinematics • If the object’s initial velocity is unknown, it can be computed from observation by plotting the curve of its position for an arbitrary interval and computing speed as the first derivative of the position curve. • Adding an estimate of its acceleration vector can help in estimating the object’s future trajectory. • P = P0 + v0t + 0.5at2 Dead Reckoning
Uses in sports games • Shooting a ball or puck • Passing a ball or puck • Dead reckoning is useful for planning the trajectory of players to determine if a player can make it to an open position to complete the pass. • Good examples of this can be found in soccer games • Players will often link passes together by passing to a teammate when faced with a defender and running past the defender to accept a return pass up the pitch Dead Reckoning
Online play • Dead Reckoning can be used in games to minimize the effects of network latency • Each player periodically broadcasts a packet containing his avatar’s location, velocity, and acceleration • During the intervals between packets, each machine runs a dead reckoning algorithm to compute the approximate positions and orientations of all other players • When a new incoming packet from another player is received, the local state of the world is updated accordingly, and the process starts anew Dead Reckoning
Inferring goals • Dead Reckoning can help to infer another players goals and try to intercept them • This can be seen as interceptions in football and soccer Dead Reckoning
Interceptions occur in many sports • The interesting aspect of calculating interceptions is that the same theories apply as in Dead Reckoning, but the system is less planned • Meaning that, interceptions are not intentional • Games should include interceptions as incidental and unplanned from an AI perspective in order to accurately model a sports game Interceptions
An object is at a position Pb • It travels in a straight line with velocity Vb • Another object is at a Pp and wants to intercept the first object • The intercepting object has a set speed it can move at • A velocity to intercept, Vp, is calculated • This is a simplified model Interceptions
For instance: • A basketball bouncing off of a rim has a path that is parabolic in shape • Break the model down into two submodels • Altitude of the ball • Motion in the ground plane • The ground plane motions are orthogonal to the altitude axis • These motions can be considered in isolation Interceptions
Another simplification occurs in the previously described model • No turning radius • Infinite Acceleration • Indefinite travel at maximum velocity • Error isn’t always frowned upon…by developers • Passes are missed. It happens. • Other methods can be used to calculate for heading changes Interceptions
For an interception to occur, the position of the ball and the player must be the same at some time t • If Vp is known prior, then the function can look like • Pb + Vbt = Pp + Vpt • However Vp is the variable that needs to be solved for • Distance between the player’s initial position and the ball at time t: • |(Pb – Pp) + Vbt| • If the player can move a distance equivalent to how distant the ball is, the player can intercept the ball at time t • |(Pb – Pp) + Vbt| = sit Interceptions
|P + Vt| = st • (P +Vt)*(P+Vt)=(st)2 • P*P + 2P * Vt + V*Vt2 = s2t2 • (V*V – s2)t2 + (2P*V)t + (P*P) = 0 • Now the equation is a second-order polynomial of t • Now it’s time to use the quadratic equation Interceptions
Category of solution is determined by the expression in the radical • b2 – 4ac • A better form to look at our equations from • b2-4ac = (2P*V)2 – 4(V*V-s2)(P*P) • … • (P*V)2 + (s2 – V*V)(P*P) Interceptions
No Real Roots • The radicand(quantity with the radical) is negative • There are no real roots • The ball cannot be intercepted • This occurs when the ball travels at a speed greater than the maximum speed of the player • S2 – V*V must be negative • S<|V| • The player has to be able to move faster than the ball if he hopes to intercept it Interceptions
One Real Root • Border case between whether or not the player can intercept the ball • Only one point in time for interception • The radicand must be zero • Two Special Cases • (P*V)<0 • The ball’s velocity is toward the interceptor and can be caught • (P*V)>0 • The ball’s velocity is not toward the receiver • This happens because the interception theoretically happened in the past Interceptions
Two Real Roots • Does not require the speed of the player to be greater • Two positive roots • The player is close to the line of motion and able to catch the ball anytime • Two negative roots • Impossible interception. Negative time. • One positive and one negative root • The player is moving faster than the ball and can meet at any time to meet it in the positive direction Interceptions
Error correction • The translational error between the real position of an agent and the estimate provided by dead reckoning can become unbounded with time. • The agent will compute its own short-term map of its surroundings • The short-term map is compared with the a priori map using pattern recognition techniques • Small, incremental corrections are applied on the fly Dead Reckoning
Coordination and communication are key amongst human teams and the same goes for the PS3, Xbox360, and Commodore 64 • The first step is to define behaviors for the agents. • In the case of baseball: • Baserunning • Fielding • Hitting • Pitching Agent Cooperation
Hitting and Pitching • Not too complex • Very much animation based • The pitch is thrown • It is hit, or not hit • The ball will have a determined path • Once the ball is hit, its initial velocity an angle are the only real factors of importance • These two factors in addition to existing baserunners directly affect how the ball is fielded • Ball hit and ball pitched act more like events • Prepare to field • Field • Prepare to run Agent Cooperation
Fielding Behaviors • Assignments happen off of two main triggers (events) • Ball Hit • Ball Fielded • Players should react differently to these situations • Only one player fields a ball, so the other players watch, or prepare for other strategies Agent Cooperation
Class Structure Class BasicBehavior { … void Entry(Cplayer*); void Exit(Cplayer*); void Process(Cplayer*); … } • Each derived behavior has a transition table to switch between behaviors and actions • Many times this can result in a similar behavior being performed • Transition tables do not always lead to a distinctly different behavior Agent Cooperation
Initial Behavior Assignments • In the case of a ball hit event, once the initial angle and velocity are known, it is easy to determine where the ball will land, and what actions and behaviors to disperse • Determining the Hit Type and Hit Zone can be done using physics and trigonometry • The Hit Type and Hit Zone values can be used to control values across the entire field Agent Cooperation
Hit Types • Ground ball • Fly ball • Line drive • Popup • Deep drive • In the case of a hit type ground ball Zone 7 • The first baseman and right fielder should motion to the Behavior Field Ball • The rest of the infielders will move to Behavior Cover Base, with exception to the second baseman who will assume Cutoff or Field Ball depending on velocity • Left and Center Field are in Behavior Back Up Agent Cooperation
Hit Zones Agent Cooperation
Initial Behavior Assignments for Runners • Hit Types • Ground Ball – Behavior Go or Behavior Go Back • A runner on second, not forced will assume Behavior Go on any ball hit in a right-hand zone • Hit type fly ball will throw Behaviors Go Halfway, or Tag Up • The runners evaluate situations exactly like humans do • They check proximities of fielders to the ball, evaluate the actions of other runners and make a best decision on what to do Agent Cooperation
Throw Determination • Fly balls • 95 percent of the balls either go to second or home • Or throw to the cutoff man and let him decide • Rundowns • We have enough information to run the player down every time (100 percent success rate) • So the better approach to take is to make it interesting and allow the runner to fool with the window Agent Cooperation