Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis
Purpose Dynamic environment – player’s actions are unpredictable, player can change environment (i.e. game has a physics engine) High levels of interactivity, coupled with dynamic environments, require sophisticated AI AI needs way to process information in environment
Example
Possible Representations Static Place “hints” in the game world Analyze world and build a data structure Dynamic Influence maps (establishes implicit boundaries between opposing forces) Want a solution that represents all relevant data
Spatial Database 2D grid overlaid on top of the game world Multiple independent layers superimposed on the same grid Most useful layers: Openness Area occupancy Area search Line-of-fire Light level
Use of Spatial Database Combine multiple layers to compute composite desirability values AI examines nearby cells, moves accordingly Implicitly coordinates behavior of multiple AIs
Openness Layer Needed for tactics which require certain amount of open space (ex – “Circle of Death”) Cells contain values that indicate how close it is to a wall/object If blocked, value = 0; else, value = 1 Propagate influence of 0-value cells to neighbors
Example Propagation 1 0.2 1 0.2 0.4 1 0.2 0.4 0.6
Uses of Openness Layer Can determine the direction of increasing/decreasing openness Can use this gradient to find the middle of the room (high openness) and the walls (low openness)
Area Occupancy Layer More for RTS games, “fog of war” Each unit propagates an area of influence around itself Cells with nonzero values are visible Units update grid values when moving (or created/destroyed) Used in other genres for AIs to know how populated an area of the world is
Uses of Area of Occupancy Layer Higher values if cells are closer to more agents Avoid moving into occupied areas when maneuvering Difference between “fog of war” and occupancy – values depend on distance between AI units for occupancy, not “fog of war”
Area Search Layer Games with stealth components, AI needs to search for player Scouts in RTS games, uncovering the map Initialize the layer to zero values Increment cell values as they enter AI agent’s view arc
Implementation for Stealth Games Guard considers surrounding area a “hidden map” Has clues to aid search; knows where to begin and where to look Store database of evidence, bias search towards it Decay database over time (randomly?) Automatically coordinates multiple NPCs
Thief 3
Line-of-Fire Layer For game genres with ranged weapons Want to ensure that AIs don’t block each others’ shots Each cell starts as zero When AI aims, propagates values in its viewing arc Each AI ignores its own contribution (temporarily subtract value before reading)
Light Level Layer Needed for games with dynamic lighting Stealthy characters/vampires would avoid light, guards would prefer light Initialize to 0s Each light source propagates values based on current radius, lighting type, intensity, etc.
Handling 3D Environments Single 2D grid can’t represent vertically overlapping areas Solution: transform grid into one of sub-grids Assign a sub-grid to each different height Works well for human environments
Updating certain areas constantly is a waste of time/memory Potential Issues Spatial database system could be a performance nightmare Large grid + high resolution + large # of AIs + frequent updates = Updating certain areas constantly is a waste of time/memory
Optimizations Pare size of the grid (make cells represent larger areas of environment) Don’t recalculate static layers Decompress sub-grids as needed Combine cells if all values are the same Use short-circuit evaluation Update cells only when used
Sources Tozour, Paul, “Using a Spatial Database for Runtime Spatial Analysis,” AI Game Programming Wisdom 2. HL2 video - http://www.zippyvideos.com/212120745294215.html Thief 3 video - http://media.pc.ign.com/media/015/015244/vids_4.html BSOD image - www.palindrom.agava.ru/en.intro.bsod.html