Sports Games Artificial Intelligence and Physics Sports Game

  • Slides: 58
Download presentation
Sports Games: Artificial Intelligence and Physics

Sports Games: Artificial Intelligence and Physics

�Sports Game Design and Development ◦ Architectures ◦ Class Structures �Agent Cooperation ◦ Team

�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

�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

�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

Building an Sports AI Architecture

Building an Sports AI Architecture

�A Sports game has many CPU-Intensive tasks ◦ Player animation ◦ Route planning ◦

�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

�Layering the architecture Building a Sports AI Architecture

� Plans ◦ Offensive �Pass �Shoot �Drive to the basket ◦ Defensive �Position the

� 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

Building a Sports AI Architecture

Building a Sports AI Architecture

� Example planning class Class Agent. Plan { float Evaluate. Initiation(); float Evaluate. Continuation();

� Example planning class Class Agent. Plan { float Evaluate. Initiation(); float Evaluate. Continuation(); 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

� 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.

�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

Building a Sports AI Architecture

Building a Sports AI Architecture

�Agent AI ◦ Well thought out collection of utility functions and data used by

�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

�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

Dead Reckoning

Dead Reckoning

�Originally developed as a tool for navigators ◦ Determining the position of his ship

�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

�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 = P 0 + v t ◦ 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

�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

�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 = P 0 + v 0 t + 0. 5 at 2 Dead Reckoning

�Uses in sports games ◦ Shooting a ball or puck ◦ Passing a ball

�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

�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

�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

Interceptions

�Interceptions occur in many sports �The interesting aspect of calculating interceptions is that the

�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

Interceptions

Interceptions

�An object is at a position Pb �It travels in a straight line with

�An object is at a position Pb �It travels in a straight line with velocity V b �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

�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

�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

Interceptions

Interceptions

� For an interception to occur, the position of the ball and the player

� 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 + V b t = P p + V p t � 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 + 2 P * Vt +

�|P + Vt| = st �(P +Vt)*(P+Vt)=(st)2 �P*P + 2 P * Vt + V*Vt 2 = s 2 t 2 �(V*V – s 2)t 2 + (2 P*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 ◦ b 2

�Category of solution is determined by the expression in the radical ◦ b 2 – 4 ac �A better form to look at our equations from ◦ b 2 -4 ac = (2 P*V)2 – 4(V*V-s 2)(P*P) ◦… ◦ (P*V)2 + (s 2 – V*V)(P*P) Interceptions

�No Real Roots ◦ The radicand(quantity with the radical) is negative �There are no

�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 ◦ S 2 – 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

�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

�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

Dead Reckoning

Dead Reckoning

�Error correction ◦ The translational error between the real position of an agent and

�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

Agent Cooperation

Agent Cooperation

�Coordination and communication are key amongst human teams and the same goes for the

�Coordination and communication are key amongst human teams and the same goes for the PS 3, Xbox 360, 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

� 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

�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

Agent Cooperation

Agent Cooperation

� Class Structure Class Basic. Behavior { … void Entry(Cplayer*); void Exit(Cplayer*); void Process(Cplayer*);

� Class Structure Class Basic. Behavior { … 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 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

� 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

�Hit Zones Agent Cooperation

�Initial Behavior Assignments for Runners ◦ Hit Types �Ground Ball – Behavior Go or

�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

Agent Cooperation

Agent Cooperation

�Throw Determination ◦ Fly balls � 95 percent of the balls either go to

�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

Real Time Strategy Development

Real Time Strategy Development

� Sports games are confined to sets of rules and the development of strategies

� Sports games are confined to sets of rules and the development of strategies both team-wide and personal that confine themselves to the rules of physics and the rules of the game � This does not limit however the amount of work and planning that is done by each individual player, who has to model the abilities and limitations of his or her real-life component. � Team dynamic is equally important ◦ Some teams have characteristically strong defense ◦ Some players communicate better than others, and are more intelligent Real Time Strategy Development

�Soccer Games ◦ Real time strategy in the sense of team control ◦ Moving

�Soccer Games ◦ Real time strategy in the sense of team control ◦ Moving offense/defense forward and back ◦ Controlling player motions �Many of the players use advanced AI techniques to predict good strategies to use with you �Games can allow you to change offense and defensive strategies on the fly. �Different players have different abilities ◦ This skill set in some ways can become very detailed ◦ Some famous players are known for their speed, shooting, defensive abilities and a knowledgeable player can exploit these to their own advantage Real Time Strategy Development

�Positions and zones are of extreme importance ◦ Players have roles ◦ Like in

�Positions and zones are of extreme importance ◦ Players have roles ◦ Like in RTS games, some characters cannot perform well on certain terrain ◦ The same goes for players playing in muddy conditions or snow �Teams have characteristics and players that make them more powerful against other teams ◦ Not a division on race and inherent abilities ◦ A division based on skill and communication �There are optimal configurations Real Time Strategy Development

�A new trend is also to give you manager control ◦ This involves more

�A new trend is also to give you manager control ◦ This involves more long term planning regarding player trading, development, and economics ◦ Played over a long period of time, your decisions affect your win percentages and offers you receive. �This kind of play rewards players who are very tied to the individual sport Real Time Strategy Development

�Skills Vs. Strategy ◦ An interesting development in sports gaming is that of providing

�Skills Vs. Strategy ◦ An interesting development in sports gaming is that of providing you with additional skills ◦ Managing a team from the top level, while managing a player’s actions on a lower level are becoming increasingly common ◦ FIFA 2008 included a new mode titled “Be a Pro” which allows the user to master skills such as dribbling and tackling at a level that goes beyond simply pressing A or B ◦ This type of a game feature can almost be compared to some aspects of RPG gaming, where a player levels up and is rewarded with experience points and abilities Real Time Strategy Development

�Sports games have the difficult task of being true to the sport and physics

�Sports games have the difficult task of being true to the sport and physics ◦ Accurate player modeling ◦ Robust physics engines �Sports games incorporate features from many different genres ◦ Real-time strategy styles ◦ RPG-type player development �Through the years sports games have advanced significantly to allow a deeper level of play Final Notes

Questions?

Questions?