230 likes | 484 Views
Pathfinding. Extensions: Terrain Cost, Influence Mapping. Extending Pathfinding. Standard pathfinding algorithms (A*, Dijkstra, etc.) can be extended to simulate intelligent environments Terrain costing Influence mapping A* pathfinding also have many interesting variants
E N D
Pathfinding Extensions: Terrain Cost, Influence Mapping
Extending Pathfinding • Standard pathfinding algorithms (A*, Dijkstra, etc.) can be extended to simulate intelligent environments • Terrain costing • Influence mapping • A* pathfinding also have many interesting variants • Iterative deepening (IDA*) • Dynamic A* • Jump point search – Rectangular Symmetry Reduction (Harabor, 2011)
Realistic? • Standard A* algorithm determines path cost based on distance travelled • However, for realistic worlds, the shortest possible path is NOT always the fastest path! • Terrain types can contribute to the differences in selection of best path • In our initial examples of A* algorithm, there is terrain cost… but that cost is uniform, because all the terrain are the same!
Terrain Cost • There is no reason why we can’t assign different cost values to different nodes • Remember how to calculate the total cost in the original algorithm? f(n) = g(n) + h(n) • How do we factor in the terrain cost into this formula? Suggestions?
A* Algorithm – Terrain Cost • Using the previous example of the spider and man…but with added terrain tiles.
A* Algorithm – Terrain Cost • A* Algorithm always searches for the path with the lowest total cost, so your design of the formula is crucial! • Now, let’s examine the original path over the new “terrain-ized” map…
A* Algorithm – Terrain Cost • Re-calculating the path using the terrain costs…
A* Algorithm – Terrain Cost • We now get a slightly different lowest-cost path that “looks” longer…
A* Algorithm – Terrain Cost • For the sake of realistic implementation, the speed of the character over higher-cost terrains should be slower (by about the same factor used for the path terrain cost) • This is so that the character does not appear to take an even longer time to traverse the new lowest-cost path!
A* Algorithm – Terrain Cost • Terrain cost is also useful in CE • In TBE, all nodes are equidistant (assuming that every tile is represented by a node), but in CE, nodes can be situated at different distances from one another • Although the varying distances have already different costs, terrain costs can also be incorporated • It is possible to think of cost as other types of resources such as money, fuel, etc.
Dynamic Path Costs? • Terrain cost is usually something programmers hardcode or pre-determine in the game world • However, other kinds of elements can influence path cost • For e.g. Nodes that pass through the line of sight of any enemy might present a higher cost. We cannot build this cost into the game level since the position of the game characters can change! • What other possible scenarios where path cost can dynamically change throughout the game?
Influence Mapping • Influence mapping is a way to vary the cost of the nodes depending on what happens during the game (dynamic)
Influence Mapping • The position and orientation of the tank below influences the “danger cost” of taking a certain path. • Observe how the danger costs are assigned to the nodes near the tank’s line of fire. • Building the best path will result in the character taking a longer, slower and less dangerous path • This influence map changes dynamically when the tank eventually moves or turns.
Influence Mapping • You can use influence mapping in many creative ways to make your characters seem smart. • E.g. Record individual game incidents in an influence map. There might be locations in map that: • The human player repeatedly ambushes or kills NPCs at a certain doorway. That doorway might increase in cost in future rounds, allowing the NPC to build alternative paths if possible. • It appears that the NPCs are learning from their past mistakes!
Influence Mapping • Influence map using number of kills that occur in the map. “Danger spots” are being identified by adding these danger costs to future path calculations.
Influence Mapping in RTS • In RTS, influence maps can be built for base turrets/towers/ defensive structures • We can imagine them as having a “radius” of influence. Realistically, the influence should be taken to drop off with distance
Linear Influence Model • We can use a simple linear drop off to model this I0 is the influence at distance 0 X d
Limited radius of influence • Many units with a million locations in the world map Huge calculation task! • Limited radius of influence : to constrain the effect of influence to a certain radius. Beyond this max radius, unit cannot exert influence, no matter how weak r
Limited radius of influence • If we use a linear drop off formula for influence, and we have a threshold influence, It then the radius of influence r
Limited radius of influence • Disadvantage: Small influences do not add up over large distances • E.g. The zone in front of the 3 turrets is potentially dangerous, however the location just outside all three have 0 influence! • Actual influence effect of all 3 turrets should be the blue circle instead
Overlapping influences • Overlapping influences (from more than one unit) should be totaled up. Here’s an example influence map
Influence Mapping in RTS • In RTS, influence mapping can also be used for other tactical/strategic purposes • Tactical analysis – dealing with known and unknown base influences (“Fog-of-war”)
Influence Mapping in RTS • Multi-layer tactical information – combining multiple influence maps to make decisions (e.g. using security, visibility and proximity factors to decide where to place new towers)