Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

20
Ch 7.1: Using a Ch 7.1: Using a Spatial Database for Spatial Database for Runtime Spatial Runtime Spatial Analysis Analysis

Transcript of Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Page 1: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Ch 7.1: Using a Spatial Ch 7.1: Using a Spatial Database for Runtime Database for Runtime

Spatial AnalysisSpatial Analysis

Page 2: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

PurposePurpose

Dynamic environment – player’s Dynamic environment – player’s actions are unpredictable, player can actions are unpredictable, player can change environment (i.e. game has a change environment (i.e. game has a physics engine)physics engine)

High levels of interactivity, coupled High levels of interactivity, coupled with dynamic environments, require with dynamic environments, require sophisticated AIsophisticated AI

AI needs way to process information AI needs way to process information in environmentin environment

Page 3: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

ExampleExample

Page 4: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Possible RepresentationsPossible Representations

StaticStatic• Place “hints” in the game worldPlace “hints” in the game world• Analyze world and build a data structureAnalyze world and build a data structure

DynamicDynamic• Influence maps (establishes implicit Influence maps (establishes implicit

boundaries between opposing forces)boundaries between opposing forces) Want a solution that represents all Want a solution that represents all

relevant datarelevant data

Page 5: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Spatial DatabaseSpatial Database

2D grid overlaid on top of the game 2D grid overlaid on top of the game worldworld

Multiple independent layers Multiple independent layers superimposed on the same gridsuperimposed on the same grid

Most useful layers:Most useful layers:• OpennessOpenness• Area occupancyArea occupancy• Area searchArea search• Line-of-fireLine-of-fire• Light levelLight level

Page 6: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Use of Spatial DatabaseUse of Spatial Database

Combine multiple layers to compute Combine multiple layers to compute composite desirability valuescomposite desirability values

•AI examines nearby cells, moves AI examines nearby cells, moves accordinglyaccordingly•Implicitly coordinates behavior of Implicitly coordinates behavior of multiple AIsmultiple AIs

Page 7: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Openness LayerOpenness Layer

Needed for tactics which require Needed for tactics which require certain amount of open space (ex – certain amount of open space (ex – “Circle of Death”)“Circle of Death”)

Cells contain values that indicate Cells contain values that indicate how close it is to a wall/objecthow close it is to a wall/object

If blocked, value = 0; else, value = 1If blocked, value = 0; else, value = 1 Propagate influence of 0-value cells Propagate influence of 0-value cells

to neighborsto neighbors

Page 8: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Example PropagationExample Propagation

00 11 11 11

00 0.20.2 11 11

00 0.20.2 0.40.4 11

00 0.20.2 0.40.4 0.60.6

Page 9: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Uses of Openness LayerUses of Openness Layer

Can determine the direction of Can determine the direction of increasing/decreasing opennessincreasing/decreasing openness

Can use this gradient to find the Can use this gradient to find the middle of the room (high openness) middle of the room (high openness) and the walls (low openness)and the walls (low openness)

Page 10: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Area Occupancy LayerArea Occupancy Layer

More for RTS games, “fog of war”More for RTS games, “fog of war” Each unit propagates an area of Each unit propagates an area of

influence around itselfinfluence around itself Cells with nonzero values are visibleCells with nonzero values are visible Units update grid values when moving Units update grid values when moving

(or created/destroyed)(or created/destroyed) Used in other genres for AIs to know Used in other genres for AIs to know

how populated an area of the world ishow populated an area of the world is

Page 11: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Uses of Area of Occupancy LayerUses of Area of Occupancy Layer

Higher values if cells are closer to Higher values if cells are closer to more agentsmore agents

Avoid moving into occupied areas Avoid moving into occupied areas when maneuveringwhen maneuvering

Difference between “fog of war” and Difference between “fog of war” and occupancy – values depend on occupancy – values depend on distance between AI units for distance between AI units for occupancy, not “fog of war”occupancy, not “fog of war”

Page 12: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Area Search LayerArea Search Layer

Games with stealth components, AI Games with stealth components, AI needs to search for playerneeds to search for player

Scouts in RTS games, uncovering the Scouts in RTS games, uncovering the mapmap

Initialize the layer to zero valuesInitialize the layer to zero values Increment cell values as they enter Increment cell values as they enter

AI agent’s view arcAI agent’s view arc

Page 13: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Implementation for Stealth GamesImplementation for Stealth Games

Guard considers surrounding area a Guard considers surrounding area a “hidden map”“hidden map”

Has clues to aid search; knows where Has clues to aid search; knows where to begin and where to lookto begin and where to look

Store database of evidence, bias search Store database of evidence, bias search towards ittowards it

Decay database over time (randomly?)Decay database over time (randomly?) Automatically coordinates multiple Automatically coordinates multiple

NPCsNPCs

Page 14: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Thief 3Thief 3

Page 15: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Line-of-Fire LayerLine-of-Fire Layer

For game genres with ranged weaponsFor game genres with ranged weapons Want to ensure that AIs don’t block each Want to ensure that AIs don’t block each

others’ shotsothers’ shots Each cell starts as zeroEach cell starts as zero When AI aims, propagates values in its When AI aims, propagates values in its

viewing arcviewing arc Each AI ignores its own contribution Each AI ignores its own contribution

(temporarily subtract value before (temporarily subtract value before reading)reading)

Page 16: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Light Level LayerLight Level Layer

Needed for games with dynamic Needed for games with dynamic lightinglighting

Stealthy characters/vampires would Stealthy characters/vampires would avoid light, guards would prefer lightavoid light, guards would prefer light

Initialize to 0sInitialize to 0s Each light source propagates values Each light source propagates values

based on current radius, lighting based on current radius, lighting type, intensity, etc.type, intensity, etc.

Page 17: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Handling 3D EnvironmentsHandling 3D Environments

Single 2D grid can’t represent Single 2D grid can’t represent vertically overlapping areasvertically overlapping areas

Solution: transform grid into one of Solution: transform grid into one of sub-gridssub-grids

Assign a sub-grid to each different Assign a sub-grid to each different heightheight

Works well for human environmentsWorks well for human environments

Page 18: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

Potential IssuesPotential Issues

Spatial database system could be a Spatial database system could be a performance nightmareperformance nightmare

Large grid + high resolution + large # of Large grid + high resolution + large # of AIs + frequent updates =AIs + frequent updates =

• Updating certain Updating certain areas constantly is a areas constantly is a

waste of time/memorywaste of time/memory

Page 19: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

OptimizationsOptimizations

Pare size of the grid (make cells Pare size of the grid (make cells represent larger areas of environment)represent larger areas of environment)

Don’t recalculate static layersDon’t recalculate static layers Decompress sub-grids as neededDecompress sub-grids as needed Combine cells if all values are the Combine cells if all values are the

samesame Use short-circuit evaluationUse short-circuit evaluation Update cells only when usedUpdate cells only when used

Page 20: Ch 7.1: Using a Spatial Database for Runtime Spatial Analysis.

SourcesSources

Tozour, Paul, “Using a Spatial Database for Tozour, Paul, “Using a Spatial Database for Runtime Spatial Analysis,” Runtime Spatial Analysis,” AI Game Programming AI Game Programming Wisdom 2Wisdom 2..

HL2 video - HL2 video - http://www.zippyvideos.com/212120745294215.hhttp://www.zippyvideos.com/212120745294215.htmltml

Thief 3 video - Thief 3 video - http://media.pc.ign.com/media/015/015244/vids_http://media.pc.ign.com/media/015/015244/vids_4.html4.html

BSOD image - BSOD image - www.palindrom.agava.ru/en.intro.bsod.htmlwww.palindrom.agava.ru/en.intro.bsod.html