module 11 spatial reasoning

42
Artificial Intelligence for Video Games Kevin Dill [email protected] Jeff Zuccaro [email protected]

Upload: kdill4

Post on 15-Jun-2015

790 views

Category:

Technology


0 download

DESCRIPTION

Spatial Reasoning lecture from my Game AI class

TRANSCRIPT

Page 1: Module 11   Spatial Reasoning

Artificial Intelligence for

Video Games

Kevin [email protected]

Jeff [email protected]

Page 2: Module 11   Spatial Reasoning

Some Words• Guard Post • Trench Line

• Bunker

• Outflank • Multi-Pronged Attack

• Surround • Ambush

• Surprise Attack

• Cover • Concealment

• Scout • Observation Post

Page 3: Module 11   Spatial Reasoning

A Classic Example*

• The funnel:

* Forbus, K., J.V. Mahoney, and K. Dill, “How Qualitative Spatial Reasoning Can Improve Strategy Game AIs,” IEEE Intelligent Systems, July/August 2002

Page 4: Module 11   Spatial Reasoning

Another Classic Example*

• The massed-fires problem:

* Forbus, K., J.V. Mahoney, and K. Dill, “How Qualitative Spatial Reasoning Can Improve Strategy Game AIs,” IEEE Intelligent Systems, July/August 2002

Page 5: Module 11   Spatial Reasoning

What Is Terrain Analysis?• Loosely defined, terrain analysis is the

process of reasoning about the positions of things in the game world.

• We may do this on the basis of the actual terrain (hills, mountains, forests, rivers, oceans, etc.)

• We may also include the “man-made” things in the world – buildings, armies, etc.

Page 6: Module 11   Spatial Reasoning

More formally…*

• Qualitative representations carve up continuous properties into conceptually meaningful units

• Qualitative spatial representations [a.k.a. terrain analysis] carve space into regions based on a combination of physical and task-specific constraints

* Forbus, K., J.V. Mahoney, and K. Dill, “How Qualitative Spatial Reasoning Can Improve Strategy Game AIs,” IEEE Intelligent Systems, July/August 2002

Page 7: Module 11   Spatial Reasoning

Tactical Positions

Page 8: Module 11   Spatial Reasoning

Examples of Tactical Positions• Cover (low/high)

• Concealment

• Sniper

• Etc.

Page 9: Module 11   Spatial Reasoning

Implementation• Designer placed waypoints

– The good: simple– The bad: incomplete coverage, errors can

happen, lots of work

• Automatically generated– The good: accurate, complete– The bad: expensive map analysis, bugs can

happen, lots of work

Page 10: Module 11   Spatial Reasoning

Automatic Generation• Cover points

– Generally found relative to objects– Mark your objects up with rectangles that

denote their cover characteristics

• Sniping points– Just cover points far from the player?– Maybe consider height? Fields of fire?

• Concealment– Use the lighting model to determine shadows– Other map characteristics (e.g. deep grass)

Page 11: Module 11   Spatial Reasoning

Finding Nearby Points• If you have a terrain analysis, look in

nearby regions

• If they’re in the path graph, use Dijkstra’s

• Use a BSP tree or similar algorithm

Page 12: Module 11   Spatial Reasoning

Regions

Page 13: Module 11   Spatial Reasoning

Less Formal Definitions• Region: An area of the map which is

composed entirely of terrain with similar characteristics (e.g. forest, water, etc.)

• Choke Point: A narrow area in the terrain which restricts movement.

• Corridors & Free Spaces: One way of breaking up terrain, first proposed by Forbus et al, which has proven to be effective in games (e.g. Master of Orion 3, War Leaders: Clash of Nations)

Page 14: Module 11   Spatial Reasoning

Characteristics of Regions• Homogenous

• Not too big, not too small

• Roughly convex

• Know stuff:– Contents (static and dynamic)– Traffic patterns– Last time viewed– Death history– Anything else that might be useful to your AI

Page 15: Module 11   Spatial Reasoning

Generating Regions

Page 16: Module 11   Spatial Reasoning

When It’s Easy*

• For many maps, the subdivision is obvious– Master of Orion 3:

stars & star lanes– Games set indoors

or underground tend to exhibit similar characteristics

* Dill, K. and A. Sramek, “Performing Qualitative Terrain Analysis in Master of Orion 3,” AI Game Programming Wisdom 2

Page 17: Module 11   Spatial Reasoning

Kohan II: Tile-Based Maps• Tile based map

• A rectangle is a collection of tiles, all with the same terrain type

• A region contains one or more rectangles of the same terrain type

• An island is the set of all connected regions of the same terrain type

Page 18: Module 11   Spatial Reasoning

Kohan II: Tiles

Page 19: Module 11   Spatial Reasoning

Kohan II: Rectangles

Page 20: Module 11   Spatial Reasoning

Kohan II: Regions

Page 21: Module 11   Spatial Reasoning

Kohan II: Islands

12

3

Page 22: Module 11   Spatial Reasoning

Kohan II: Choke Point Detection• A region is a choke point if there exist two

adjacent regions, A and B, such that you can not travel from A to B without passing through the region being tested– Limit your search to a depth of ~5 regions

Page 23: Module 11   Spatial Reasoning

Regions

Page 24: Module 11   Spatial Reasoning

Flood Fill*

• Can be used on tile-based or non-tile-based maps

• Rapid to compute– Company of Heroes uses

this technique to dynamically create regions in real time

• May create weird looking regions (?)

• Kohan 2 technique may not find choke points

* Buckland, M, Programming Game AI by Example

Page 25: Module 11   Spatial Reasoning

Navigation Mesh*

• If you’re using a navigation mesh for path planning, use the cells as regions

• Only works if the cells are appropriately sized & shaped, homogenous, etc.

• If you’re not using a navigation mesh, you can use regions as a high level path planning abstraction

* Buckland, M, Programming Game AI by Example

Page 26: Module 11   Spatial Reasoning

Image Processing*Select impassable areas (1) Expand selection (2)

Invert (3) and fill selection (4) Expand selection (5)

Invert selection (6) Deselect impassable (7) and fill (8)

Wild passable terrain

Impassable terrain

Game zone seed

Potential choke point

Lined areas belong to current selection

1. Select impassible terrain2. Expand selection3. Invert selection4. Fill (Free Spaces)5. Expand selection (Free

Space borders)6. Invert Selection7. Deselect impassible8. Fill (Choke Points)

* Obelleiro, J. et al, “RTS Terrain Analysis: An Image Processing Approach,” AI Game Programming Wisdom 4

Page 27: Module 11   Spatial Reasoning

Intelligent Path Planning

Page 28: Module 11   Spatial Reasoning

Path Quality• Army officers selecting a route consider

the following:– Distance – obviously, but generally the least

importantly– Trafficability – how quickly/easily can I travel– Visibility – where can I be seen from, where

can I see?– Fields of Fire – where can I be shot from,

where can I shoot?

• Current games give no more than lip service to these concepts

Page 29: Module 11   Spatial Reasoning

Modifying Path Cost• Adjust the cost of each edge in the path

graph based on tactical considerations

• Can greatly increase cost of A* search– Cost of A* is a function of how closely your

heuristic matches the actual travel cost– Perfect heuristic example– Swamp/grassland example

Page 30: Module 11   Spatial Reasoning

Using Multiple Paths*

• Remember this:

* Forbus, K., J.V. Mahoney, and K. Dill, “How Qualitative Spatial Reasoning Can Improve Strategy Game AIs,” IEEE Intelligent Systems, July/August 2002

Page 31: Module 11   Spatial Reasoning

Generating Path Candidates• Dijkstra’s Algorithm can be used to find all

paths out to some depth

• Generally speaking, finding all paths is expensive, so…– Prioritize queries, and time-slice the search to

answer them– Use A* first, then following up with Dijkstra’s if

the path is short enough– Instead of using Dijkstra’s, use A* to find a

path to each corridor adjacent to your target

Page 32: Module 11   Spatial Reasoning

Using Path Candidates• Score all paths wrt trafficability, visibility,

and fields of fire, take the best

• Coordinate movement down multiple paths– Improve overall flow– Launch simultaneous attacks

• Pick a random path– The military taught me to never use the same

path twice, lest I be ambushed

Page 33: Module 11   Spatial Reasoning

Intelligent Expansion

Page 34: Module 11   Spatial Reasoning

Exact Border Calculation*

• Walk the graph of corridors & free spaces

• Mark free spaces as:– Inside/outside borders– Threatened– Contested

* Dill, K. and A. Sramek, “Performing Qualitative Terrain Analysis in Master of Orion 3,” AI Game Programming Wisdom 2

Page 35: Module 11   Spatial Reasoning

Estimated Border Calculation• Generate an influence map extending out

from each player’s cities / buildings

• Influence levels indicate how strongly each player controls a particular location

• Contested areas are those with high influence for more than one player

• The result looks similar to Civilization IV

Page 36: Module 11   Spatial Reasoning

Expansion Considerations• Consider the strategic implications of a

build site– Is it or will it be a contested area?– Is it inside or outside of my borders?– Does it increase or decrease the number of

threatened areas?– Does it increase the territory that I control?– Does it protect important sites (home world)?– Is it inside enemy borders, or does it place an

enemy area inside my borders?

Page 37: Module 11   Spatial Reasoning

Military Considerations• Defensive

– Focus fixed defenses in threatened and contested areas

• Building them in “safe” areas is generally a waste of resources

• Even so, consider the magnitude of the threat when deciding what to build

– Build structures like walls to create choke points where none exist

• Offensive– Place a high priority on securing contested

areas and enemy areas inside your borders

Page 38: Module 11   Spatial Reasoning

Intelligent Unit Placement & Maneuver

Page 39: Module 11   Spatial Reasoning

Observation Posts• Place scout units out in positions to warn

you of enemy movement

• If game mechanics support it (or if you can talk designers into game mechanics that support it), you want them in concealed positions

• On tightly constrained maps, one good position is at the far end of corridors that lead away from your border areas

Page 40: Module 11   Spatial Reasoning

Defensive Lines• Many games feature units (e.g. artillery,

archers, quarterbacks, etc) which have significant offensive ability but are vulnerable when attacked

• Place stronger defensive units (e.g. infantry, swordsmen, or linebackers, respectively) in front of them

• Do the same thing with defensive buildings (e.g. forts, bunkers) and economic buildings (e.g. gold mines, HQ buildings)

Page 41: Module 11   Spatial Reasoning

More On Defensive Lines• Place defensive units and structures to

guard avenues of approach– This is particularly effective on tightly

constrained maps– Obelleiro et al* present an algorithm for

positioning forces near choke points

• Place units and structures so that they are mutually supporting– Don’t allow the enemy to mass his forces and

pick them off one at a time (defeat in detail)

* Obelleiro, J. et al, “RTS Terrain Analysis: An Image Processing Approach,” AI Game Programming Wisdom 4

Page 42: Module 11   Spatial Reasoning

Flanking Attacks• The classic infantry maneuver in almost all

cases is to pin the enemy down from the front, then send a second force around the flank to finish them

• Both of your forces can use cover to protect them from enemy fire as they maneuver, but it is very difficult to get cover from two angles at once