Artificial Intelligence in Games Week 7 Steve Rabin steve.rabin@gmail.com www.aiwisdom.com/uw
Pathfinding Integration Project How did it go? Any problems? How much time did it take?
Euphoria Demo
Tactics and Terrain Analysis
Terrain Analysis Algorithmic analysis of terrain In general: Automated with no human intervention Alternative to hard-coding regions of interest In general: Are there spots on the terrain that are advantageous to me? How can these be determined algorithmically? Given the current terrain, how can I tease out this info?
Terrain Analysis: Real-Time Strategy Games What are static points of interest on an RTS map? What are dynamic points of interest during an RTS battle?
Terrain Analysis: Real-Time Strategy Games Chokepoints Barriers force units through narrow path Barriers can be cliffs, walls, water, etc. Ambush sites High terrain overlooking low terrain chokepoint Wall building sites Low cost for building walls Natural barriers so not much wall required Cliffs Water Edge of map Identify front of the battle Identify flanking routes Identify inferior forces
Terrain Analysis: First-Person Shooter Games What are static points of interest in an FPS map? What are dynamic points of interest during an FPS fight?
Terrain Analysis: First-Person Shooter Games Cover points Shielding Darkness Sniper points Good cover point (shielding, darkness) Potential high visibility to a large area Rear coverage Height advantage Escape route Safe paths to move from area to area Low casualties in path Low visibility to other areas Good cover along path Line-of-sight vulnerability Stay out of other's line-of-sight
Tactical Reasoning in a First-Person Shooter Visibility is a good tactical indicator Does spot provide cover? Front cover and rear cover? How safe is it? Does spot provide accessibility? Is a given spot good to shoot from? Can we escape easily? How dangerous is it?
Tactical Reasoning with Waypoints: Half-Life 2 (first-person shooter) Implementation strategy: Preprocess terrain, storing visibility info Can area A see area B? Store visibility info in waypoint nodes Node A’s ability to see every other node How would you store it?
Tactical Reasoning with Waypoints: Storing Visibility Information Store visibility info with bit strings Can perform operations on groups and or not
Tactical Reasoning with Waypoints: Safe and Dangerous Nodes Which locations are Potentially safe? Potentially dangerous? Safe pathfinding Penalize dangerous nodes These are node visibilities What about the actual enemies?
Tactical Reasoning with Waypoints: Attack Positioning Visible nodes Show where you could attack from But no cover Better strategy Find a node to attack enemy X from Which is also shielded from other enemies
Tactical Reasoning with Waypoints: Attack Positioning 1. Get nodes visible to selected enemy 2. Get nodes visible to other enemies 3. Get safe nodes to attack from: 3 = 1 & !2
Tactical Reasoning with Waypoints: Attack Positioning Other strategies Take cover from everyone Find a safe node that is close to a completely safe node (in case NPC needs to reload) Flanking Eliminate attack points that the enemy is facing For sneaking up on enemies
Tactical Reasoning with Waypoints: Static Waypoint Analysis Determine danger of each node in a static environment Weight each node based on number of nodes that can see it If pathfinding takes into consideration Paths are less likely to be visible to enemies
Tactical Reasoning with Waypoints: Static Waypoint Analysis Nodes marked for visibility count Sniper nodes have high exposure next to nodes with low exposure
Tactical Reasoning with Waypoints: Pinch Points and Squad Tactics Identify pinch points as ambush spots 1. Find node (N) with only two neighbors 2. One neighbor node must be in confined area 3. Nodes connected to other neighbor nodes are ambush spots
Tactical Reasoning with Waypoints: Limitations Must use hierarchy of networks to reduce size of bit strings Ducking action can make some nodes both good cover and good attack locations Annotate these nodes Unidirectional connections makes it a little more complicated Density of waypoints impacts quality of reasoning
Influence Mapping
Influence Mapping Abstracts distribution of power 2D grid superimposed on terrain Unit strength is summed into grid cells Influence declines exponentially with distance Helps determine Weaknesses Neutral routes to flank enemy The “front” of the battle
Influence Mapping: Basic Influence Map
Influence Mapping: Engagement
Influence Mapping: Analysis of Options
Influence Maps: Other Uses SimCity Non-violent use Influence of crime, pollution, police, fire stations, etc
Spatial Database for Spatial Analysis
Spatial Database for Spatial Analysis Generalize “terrain reasoning with waypoints” Use a grid instead Expand to capture dynamic features Capture other interesting aspects
Spatial Database for Spatial Analysis: Many Layers of Grids Visibility How many squares are visible Openness layer Proximity to static obstacles Cover layer Locations where AI can take cover from gunfire Area occupancy layer Number of units in an area Line-of-fire layer Direction that weapons are being aimed Light level layer Brightness or darkness of any spot Area search layer Spots that have been searched
Spatial Database for Spatial Analysis: Openness Layer
Spatial Database for Spatial Analysis: Area Occupancy Layer
Spatial Database for Spatial Analysis: Line-of-Fire Layer
Spatial Database for Spatial Analysis: Combine Layers Combat desirability layer Represents desirability of moving into any given area in combat Combines openness, static cover, area occupancy layers
Project 3: Implement Terrain Analysis Due next week (May 19th) (100%) Create at least 3 simple layers of grids and 1 combined layer that can be toggled through (with the "L" key) Possible layers: Openness Layer, Occupancy Layer, Line-of-Fire Layer, Cover Area Layer, Area Search Layer, and Combat Desirability Layer Extra Credit: (10%) Have the agents use the information to do something intelligent
Squad Tactics
Squad Tactics: Decentralized vs Centralized
Squad Tactics: Decentralized Squad
Squad Tactics: Decentralized Squad Key points: Extension of individual AI Easy to add to existing AI Robustly handles many situations Deals well with a variety of capabilities within the team Can be easily combined with scripted squad member actions Cooperation and group behavior emerges from individual behaviors Technique used in original Half-Life
Squad Tactics: Decentralized Squad void SoloAI::Think() { CombatSitiation* sit = GetSituation(): sit->Observe(); for each available action { if(action.IsApplicable(sit)) { determine value of action in sit; if better than best action, make best action } execute best action(); void SoloAI::Think() { CombatSitiation* sit = GetSituation(): sit->Observe(); sit->ProcessTeamIntentions(); sit->ProcessTeamObservations(); for each available action { if(action.IsApplicable(sit)) { determine value of action in sit; if better than best action, make best action } nearbySqdMembers->AnnounceAction(); execute best action();
Squad Tactics: Solo AI vs Squad Member Fire-and-maneuver behavior If too many static squad members, move up If too many engaging threat, won't stop to engage same threat Robust against squad member casualties Interactions easily translated to audio for effect/realism
Squad Tactics: Squad Assault Tactical behavior (on top of fire/move) Stay close to cover Don't block other's line-of-fire Take weapon ability into account Maintain team cohesion / line-of-sight Spread out to avoid being a single target Keep a line-of-sight on enemy
Squad Tactics: Squad Assault – Squad Members Mental Picture For each squad member Current pos and activity Claimed destination Line-of-fire For each opponent Last known position and state Estimated position Squad members engaging this opponent For other threats (grenades, fires) Known/estimated position Damage radius
Squad Tactics: Squad Assault with Four-Man Patrol in Hostile Situation
Squad Tactics: Leader evaluating positions and picking one (center, top)
Squad Tactics: Executing L-Shaped Ambush Wait until enemy enters kill zone, aggressively attack, pull back to predefined rally point Problems Decentralized squad has trouble waiting until right moment to attack. Attack moment requires some kind of coordination Squad lacks autonomy Can't create L-shape itself, can't abort if enemy doesn't show up
Squad Tactics: Decentralized Squad (reference)
Squad Tactics: Relation Between Squad and Squad Member
Squad Tactics: Centralized Approach Advantages Separates concerns – reduces number of problems each AI has to deal with Saves CPU – do computations once AIs can be specialized independently from each other
Squad Tactics: Centralized Approach Authoritarian command style No "I" in "team" Squad can sacrifice a member to achieve a goal Squad member's view might conflict with squad's objective Told to defend a front, but sniper is behind Coaching command style Each squad member given tasks Can choose to ignore and tell squad he can't comply Deals with sniper case But squad members get distracted easily
Squad Tactics: Situation and Extracted Features Force ratio 5:3, line-of-fire ratio 2:1
Squad Tactics: FSM for Valid Maneuvers Avoids oscillations FSM prevents attacking before completing pullback
Squad Tactics: Bounding Overwatch Pullback Tail Squad Member’s Behavior Teammates lay down suppression fire
Squad Tactics: Bounding Overwatch Pullback Pullback path, Cover fire locations, and two bounding moves in progress
Squad Tactics: Stages of Performing a Maneuver
Team Member AI: Avoiding Friendly Fire If player is shooting, how can buddy AI avoid friendly fire? If player is moving around, how can buddy AI avoid friendly fire?
Team Member AI: Avoiding Friendly Fire Two options
Planning
Planning Find series of actions for AI that changes the current configuration of the game world into a target configuration Planning allows innovative solutions when the game world is sufficiently rich Requires Planning algorithm World representation Choosing set of actions Action Preconditions Effects
Planning
Planning Config1: Target not dead Action: Attack Config2: Target is dead, Weapon must be loaded Action: Load Weapon Config3: Target is dead, Weapon loaded, Weapon must be armed Acton: Draw Weapon Config4: Target is dead, Weapon is loaded, Weapon is armed