32
2.3 – Path Look-Up 2.3 – Path Look-Up Tables Tables Owen Cummings Owen Cummings

2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Embed Size (px)

Citation preview

Page 1: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

2.3 – Path Look-Up 2.3 – Path Look-Up TablesTables

Owen CummingsOwen Cummings

Page 2: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

William van der SterrenWilliam van der Sterren CompanyCompany

CGF-AICGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads and individuals, squad maneuvers and team tactics, dynamic squads and individuals, squad maneuvers and team tactics, dynamic response to threats, smart use of the terrain, human-like situational response to threats, smart use of the terrain, human-like situational awareness, and interpretation of combat situations. awareness, and interpretation of combat situations.

ProductsProducts William is contributing to the AI for William is contributing to the AI for GuerrillaGuerrilla's 's KillzoneKillzone (PlayStation2, (PlayStation2,

2004, published by Sony (SCEE / SCEA)). Killzone already collected an 2004, published by Sony (SCEE / SCEA)). Killzone already collected an IGN Award IGN Award "PlayStation 2 Best of Show""PlayStation 2 Best of Show" and another IGN Award and another IGN Award "Best Shooter""Best Shooter" at the May 2004 E3 conference / trade show. at the May 2004 E3 conference / trade show.

William contributed to the AI used in William contributed to the AI used in GuerrillaGuerrilla's 's Shellshock: Nam '67Shellshock: Nam '67 (PlayStation2, Xbox, PC, 2004, published by Eidos Interactive). (PlayStation2, Xbox, PC, 2004, published by Eidos Interactive).

Page 3: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Why use Path Look-Up Tables?Why use Path Look-Up Tables?

Path Look-Up tables can be 10 to 200 Path Look-Up tables can be 10 to 200 times faster than searching with A*times faster than searching with A*

However, the amount of memory required However, the amount of memory required for the tables often prohibits using them for for the tables often prohibits using them for anything other than small levelsanything other than small levels

Also they have problems reflecting Also they have problems reflecting changes in terrainchanges in terrain

Page 4: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Path Look-Up MatrixPath Look-Up Matrix

For N waypoints, the matrix has size NxNFor N waypoints, the matrix has size NxN Each entry in the matrix contains, for the Each entry in the matrix contains, for the

corresponding source and destination pair, corresponding source and destination pair, the next neighboring waypoint to visit or a the next neighboring waypoint to visit or a no path available marker.no path available marker.

Page 5: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Simple ExampleSimple Example

1

2

3

4

5 6 7

8

9

Start

End

A(2,9) = 1

A(1,9) = 3

A(3,9) = 5

A(5,9) = 6

A(6,9) = 7

A(8,9) = 9

A(7,9) = 8

Success!

A(2,9) = No path sentinel

Failure!So this means that we knowright away with one memoryaccess and without searchingthat a path does not existfrom node 2 to node 9

Page 6: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Problems with Path Look-Up Problems with Path Look-Up MatricesMatrices

Memory ConsumptionMemory Consumption Increase quadratically with number of Increase quadratically with number of

waypointswaypoints Typical number of waypoints between 256 Typical number of waypoints between 256

and 65535 so 2 bytes per entryand 65535 so 2 bytes per entry• For 1000 waypoints -> 2MBFor 1000 waypoints -> 2MB• For 2000 waypoints -> 8MBFor 2000 waypoints -> 8MB

This limits the use of these tables to small This limits the use of these tables to small levelslevels

Page 7: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Problems continuedProblems continued

Static representation of terrainStatic representation of terrain Can only reflect changes via update or patchCan only reflect changes via update or patch Updating the table is an O(nUpdating the table is an O(n33) operation) operation Patching also problematicPatching also problematic

• To handle a central door being unlocked for a 1000 To handle a central door being unlocked for a 1000 waypoint level, the full 2MB table would have to be waypoint level, the full 2MB table would have to be replacedreplaced

Page 8: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Smaller Indexed Path Look-Up Smaller Indexed Path Look-Up MatrixMatrix

Replace the 2 byte next waypoint to visit by a 4 Replace the 2 byte next waypoint to visit by a 4 bit index in the waypoint’s list of outgoing bit index in the waypoint’s list of outgoing waypointswaypoints

Assumes a maximum of 15 outgoing waypoints Assumes a maximum of 15 outgoing waypoints per waypointper waypoint

Memory ConsumptionMemory Consumption N*N*0.5 for the matrix + N*15*2.0 for the outgoing N*N*0.5 for the matrix + N*15*2.0 for the outgoing

waypoint listwaypoint list 542KB for 1000 waypoints542KB for 1000 waypoints 4MB for 2000 waypoints4MB for 2000 waypoints

Page 9: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Smaller Indexed Path Look-Up Smaller Indexed Path Look-Up MatrixMatrix

ProsPros Memory consumption reduced by a factor of 4Memory consumption reduced by a factor of 4 Can deal with 4 times as much terrain for the Can deal with 4 times as much terrain for the

same amount of memory, at a mere 5-percent same amount of memory, at a mere 5-percent reduction in performancereduction in performance

ConsCons Still scales quadratically with number of Still scales quadratically with number of

waypointswaypoints Still hard to accommodate terrain changesStill hard to accommodate terrain changes

Page 10: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

But…But…

Using 1 MB for path look-up tables is not Using 1 MB for path look-up tables is not an option on many game platformsan option on many game platforms

So we need a different solution…So we need a different solution…

Page 11: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Area-Based Path Look-Up TableArea-Based Path Look-Up Table

Area-Based ApproachArea-Based Approach Do path look-up at two levelsDo path look-up at two levels

• Set of portalsSet of portals• Clusters of waypoints (“areas”)Clusters of waypoints (“areas”)

Page 12: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

How it worksHow it works

To get from waypoint a to waypoint bTo get from waypoint a to waypoint b Determine the nearby portals for a and bDetermine the nearby portals for a and b Determine the shortest path between these Determine the shortest path between these

portals using a portal path look up tableportals using a portal path look up table Translate this portal path into a waypoint path, Translate this portal path into a waypoint path,

for each pair of portals on the portal path, for each pair of portals on the portal path, retrieve the waypoint path between them retrieve the waypoint path between them using the look-up table of the area connecting using the look-up table of the area connecting this portal pairthis portal pair

Page 13: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

How to Partition the Terrain?How to Partition the Terrain?

Areas Areas Should consist of co-located waypoints with Should consist of co-located waypoints with

good interconnectivitygood interconnectivity Small borders to neighboring areasSmall borders to neighboring areas Optimal area size is sqrt(N)Optimal area size is sqrt(N)

PortalsPortals Waypoints that connect the areasWaypoints that connect the areas Try to keep portals per area < 10 for faster Try to keep portals per area < 10 for faster

and smaller look up tablesand smaller look up tables

Page 14: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

When the number of areas is tripled,the memory consumption of the areabased look up tables is 3.3 timeslarger as opposed to 32 as largefor the other LUTs

This is because the portal tableincreases by a factor of 32 and the area tables only increase by a factor of 3 and because the portal table ismuch smaller this only results in atotal memory increase of 3.3

Page 15: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

The Algorithm in more detailThe Algorithm in more detail

To look up a path from a (in area A) to b (in area To look up a path from a (in area A) to b (in area B)B) If A = B, retrieve the local path from area A’s own If A = B, retrieve the local path from area A’s own

look-up matrix and we are donelook-up matrix and we are done If A If A ≠ B do the following≠ B do the following

• For source area A, retrieve the outgoing connections ApFor source area A, retrieve the outgoing connections Ap• For destination area B, retrieve the incoming portals BpFor destination area B, retrieve the incoming portals Bp• Pick the pair (ApPick the pair (Apoo, Bp, Bpii) that yields the shortest path (a - Ap) that yields the shortest path (a - Apoo - -

BpBpii -b) -b)• For the pair ApFor the pair Apoo, Bp, Bpii, retrieve a path consisting of inter-area , retrieve a path consisting of inter-area

connectionsconnections• Finally, retrieve and construct the detailed waypoint path, by Finally, retrieve and construct the detailed waypoint path, by

retrieving the in-area path for each area on the pathretrieving the in-area path for each area on the path

Page 16: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

What do we need to do this?What do we need to do this?

For each area, we need to record how to For each area, we need to record how to travel from any waypoint in this area to travel from any waypoint in this area to another waypoint also in the areaanother waypoint also in the area

Need to record all connections from that Need to record all connections from that area to other areasarea to other areas

For every connection between two areas, For every connection between two areas, we need to record the cost and shortest we need to record the cost and shortest path to any other inter-area connectionpath to any other inter-area connection

Page 17: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

DemoDemo

Show the demo programShow the demo program

Page 18: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Terrain Representation issuesTerrain Representation issues

For a map with 1,500 waypoints and 20 For a map with 1,500 waypoints and 20 areas, there might be some 300 waypoints areas, there might be some 300 waypoints lying on the border of connected areaslying on the border of connected areas

Find the minimal set of waypoints that Find the minimal set of waypoints that together still represent all inter-area together still represent all inter-area connectionsconnections Typically 60 – 75% smallerTypically 60 – 75% smaller More efficient look-up at higher levelMore efficient look-up at higher level Smaller inter-area travel info matrixSmaller inter-area travel info matrix

Page 19: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Per Area InformationPer Area Information

Waypoints within the area, and the connected portals (2 Waypoints within the area, and the connected portals (2 bytes per waypoint)bytes per waypoint)

Incoming and outgoing waypoints in dedicated arrays (2 Incoming and outgoing waypoints in dedicated arrays (2 bytes per waypoint)bytes per waypoint)

All in-area paths, as a matrix containing the index to the All in-area paths, as a matrix containing the index to the next neighbor. Index is a 1-byte index into the array of next neighbor. Index is a 1-byte index into the array of area waypoints.area waypoints.

Travel time to the outgoing portal, for every combination Travel time to the outgoing portal, for every combination of waypoint, outgoing portal (1 byte per entry)of waypoint, outgoing portal (1 byte per entry)

Travel time from the incoming portal, for every Travel time from the incoming portal, for every combination of incoming portal, waypoint (1 byte per combination of incoming portal, waypoint (1 byte per entry)entry)

Page 20: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads
Page 21: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Portal Path InformationPortal Path Information

Matrix that contains for every pair of portal Matrix that contains for every pair of portal waypoints (pwaypoints (pii, p, poo):): Travel time from pTravel time from p ii to p to poo or no path (2 bytes) or no path (2 bytes)

Next portal to visit to get to pNext portal to visit to get to poo (2 bytes) (2 bytes)

Next area to traverse to get from pNext area to traverse to get from p ii to the next to the next

portal (2 bytes)portal (2 bytes)

Page 22: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Performance ComparisonPerformance Comparison

Short Paths – 0 to 16 waypointsLong Paths – 17+ waypointsFar Travel Costs – costs of paths longer than 16 waypoints. AI typically comparestravel costs when selecting the nearest item or power up to fetch.

Path look-up matrices offer 50 to 150 times better performance than A*, and 2 to 5 times better than area basedArea based look-up tables provide a speed up of 10 to 80 times

Page 23: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Pesky Dynamic TerrainPesky Dynamic Terrain

Area based look up tables are much more Area based look up tables are much more suitable for handling terrain changes because of suitable for handling terrain changes because of the partitioningthe partitioning

Worst case the patch consists of several tens of Worst case the patch consists of several tens of KB when the portal table and an area table have KB when the portal table and an area table have to be changedto be changed

More complicated when several portals can be More complicated when several portals can be opened or closed in arbitrary order. Have to opened or closed in arbitrary order. Have to compute various patches for all sequencescompute various patches for all sequences

Page 24: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Quake 3Quake 3

Quake 3 Arena uses an approach similar Quake 3 Arena uses an approach similar to the area-based look-up tables, but for to the area-based look-up tables, but for volume-based (as opposed to waypoints) volume-based (as opposed to waypoints) navigation data.navigation data. Link to Link to pdfpdf Section 6 and 12Section 6 and 12 Very in depth, very technical, very confusingVery in depth, very technical, very confusing

Page 25: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

2.4 - An Overview of Navigation 2.4 - An Overview of Navigation SystemsSystems

This “exciting” chapter goes over software This “exciting” chapter goes over software engineering strategies to implement a engineering strategies to implement a navigation systemnavigation system

What is a navigation system?What is a navigation system? A navigation system is a separate component A navigation system is a separate component

responsible for synthesizing movement responsible for synthesizing movement behaviors.behaviors.

Page 26: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Levels of AbstractionLevels of Abstraction Choosing the level of abstraction mostly Choosing the level of abstraction mostly

depends on the complexity of the agent AIdepends on the complexity of the agent AI PlannerPlanner : Only the shortest path algorithm is : Only the shortest path algorithm is

abstracted out and implemented separately. Agent is abstracted out and implemented separately. Agent is responsible for making the path request and responsible for making the path request and interpreting the resultinterpreting the result

PathfinderPathfinder : Gives slightly more responsibility to the : Gives slightly more responsibility to the navigation system, the pathfinder would deal with the navigation system, the pathfinder would deal with the execution of plans.execution of plans.

Sub-architectureSub-architecture : It’s possible to use an AI : It’s possible to use an AI architecture specifically for navigation. This will architecture specifically for navigation. This will generally be composed of different movement generally be composed of different movement behaviors and planning abilities, including the terrain behaviors and planning abilities, including the terrain modelmodel

Page 27: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Navigation InterfacesNavigation Interfaces

Agent AI has a certain level of complexity Agent AI has a certain level of complexity in the desires and motivationsin the desires and motivations

Creating intelligent movement involves Creating intelligent movement involves transmitting these motivations to the transmitting these motivations to the navigation systemnavigation system

The interface allows information about The interface allows information about these motivations to be expressedthese motivations to be expressed

Page 28: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Interface ExpressivenessInterface Expressiveness

Choosing an interface involves making a Choosing an interface involves making a compromise between focus and flexibilitycompromise between focus and flexibility Highly focused – can be better tuned to a Highly focused – can be better tuned to a

specific problemspecific problem Flexible – can have the expressiveness to Flexible – can have the expressiveness to

handle a wider variety of scenarioshandle a wider variety of scenarios

Page 29: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

Different levels of expressivenessDifferent levels of expressiveness

Existing paradigmsExisting paradigms Single Pair : Two points are specified in the world Single Pair : Two points are specified in the world

(origin and destination), and the shortest path (origin and destination), and the shortest path between them is returnedbetween them is returned

Weighted Destinations : Instead of limiting the Weighted Destinations : Instead of limiting the requests to one destination, this can be extended to requests to one destination, this can be extended to multiple goals, each with its own reward coefficient. multiple goals, each with its own reward coefficient. An optimal path that maximizes the tradeoff between An optimal path that maximizes the tradeoff between reward and costreward and cost

Spatial Desires : Abstracting out space, it’s possible Spatial Desires : Abstracting out space, it’s possible to specify the movement by passing the motivations to specify the movement by passing the motivations from the agent to the navigation system (e.g. get from the agent to the navigation system (e.g. get armor or a weapon)armor or a weapon)

Page 30: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

AI Paradigms for MovementAI Paradigms for Movement

Reactive BehaviorsReactive Behaviors Takes sensory input and performs direct mapping to determine Takes sensory input and performs direct mapping to determine

outputoutput Possible Behaviors – obstacle avoidance, seeking, fleeingPossible Behaviors – obstacle avoidance, seeking, fleeing Perfect for simple situationsPerfect for simple situations Can’t handle traps or complex layoutsCan’t handle traps or complex layouts

Deliberative PlanningDeliberative Planning Provably optimal pathsProvably optimal paths Higher-level of spatial intelligence; plans made according to Higher-level of spatial intelligence; plans made according to

terrain representationterrain representation Hybrid SystemsHybrid Systems

Combine common sense of reactive behaviors with intelligence Combine common sense of reactive behaviors with intelligence of planningof planning

Page 31: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

ImplementationImplementation

Reactive BehaviorsReactive Behaviors Steering behaviors based on highly explicit mathematical Steering behaviors based on highly explicit mathematical

equationsequations Two problems : integration of multiple behaviors and realismTwo problems : integration of multiple behaviors and realism Prioritize behaviors and use fuzzy logic to simulate realismPrioritize behaviors and use fuzzy logic to simulate realism

Deliberative PlanningDeliberative Planning Not necessarily a search, other techniques can be more efficientNot necessarily a search, other techniques can be more efficient Precompute everything (like the look-up tables)Precompute everything (like the look-up tables) Reactive approximation techniques to build near optimal paths Reactive approximation techniques to build near optimal paths

without a searchwithout a search Dynamic environments make things trickyDynamic environments make things tricky

• Trigger a replan when the conditions have changed sufficientlyTrigger a replan when the conditions have changed sufficiently• ““Quality of service” algorithmsQuality of service” algorithms

Page 32: 2.3 – Path Look-Up Tables Owen Cummings. William van der Sterren  Company CGF-AI specializes in tactical AI for 3D virtual worlds: autonomous AI squads

ConclusionConclusion

The development of a navigation system The development of a navigation system takes more than understanding a heuristic takes more than understanding a heuristic search algorithmsearch algorithm

Numerous issues involved in synthesizing Numerous issues involved in synthesizing realistic movement in gamesrealistic movement in games

Ignoring these can lead to a suboptimal Ignoring these can lead to a suboptimal solution, unnecessarily complex code, and solution, unnecessarily complex code, and visible problems with the behaviorsvisible problems with the behaviors