Download presentation

Presentation is loading. Please wait.

Published byJulian Gilbert Modified over 2 years ago

1
**CSE 380 – Computer Game Programming Pathfinding AI**

Dig Dug, by Namco

2
**Computation and execution of a path from point p1 to p2 **

Pathfinding Computation and execution of a path from point p1 to p2 Perhaps most common AI problem in games Can be very frustrating to implement well Algorithms must be tailored to fit games For an object at point p1, suggest an algorithm to get to point p2

3
**Simple 2D Vectoring Solution**

Determine vector v to head towards p2 v.x = p2.x – p1.x v.y = p2.y – p1.y Now, scale v according to speed (use simple geometry) What’s the problem? we are assuming there are no obstacles

4
**For simple obstacles that aren’t large Algorithm:**

Simple Trial and Error For simple obstacles that aren’t large Algorithm: Go towards target destination When you hit an obstacle: Back it up Randomly turn it right or left degrees Move it forward again for some random amount in a range Go back to step 1 Easy & fast Not good for fixed obstacles of any size

5
**Contour Tracing Algorithm: Go towards target destination**

If you hit an obstacle: trace the contour of the obstacle blocking the path move such that you are a uniform distance from edge periodically test if a line to your destination intersects the obstacle anymore if yes, stop tracing and head towards destination if no, go back to tracing

6
Real Time Pathfinding Modern strategy games use lots of units simultaneously Dynamically computing paths can be expensive Solution: precompute

7
**Setup a network of paths**

Waypoint Pathfinding Setup a network of paths connect all points of interest in the game via a connected network of nodes each node represents a waypoint edges in the network represent: vector direction vector length

8
**Key for precomputed paths**

Paths should avoid obstacles

9
**What are precomputed paths?**

Nodes: locations on map (x, y) Edges direct paths to other nodes (x, y) distance Vectors computed from node to node along path Options: pre-compute and store entire paths (only viable for small data sets) dynamically calculate paths from pre-computed graph data

10
**How do we improve finding a path**

Game objects don’t necessarily start at nodes they shouldn’t have to go to nodes to pick up a path either Made easier by path coverage making sure that everywhere on the board can reach a path quickly

11
**Dynamic Pathfinding Algorithms using Graphs**

Breadth-first search Depth-first search Dijkstra’s algorithm A* Premise: you have a graph of nodes you are at one node & you want to get to another What combination of edges will get you there?

12
**Fan out in all directions at the same time**

Breadth-first search Fan out in all directions at the same time visit each node one unit away then two units away then three etc. Like a growing circle What’s bi-directional breadth-first search?

13
**Searches one way all the way until:**

Depth-first search Searches one way all the way until: it finds the goal OR it runs out of space

14
**Similar to minimum spanning tree algorithm **

Dijkstra’s Algorithm Similar to minimum spanning tree algorithm O(V2), where V is the # of vertices Premise: find the shortest path from starting node to other nodes along the way use those shortest path to determine your ultimate shortest path A nice Dijkstra’s Applet:

15
**Solves shortest path problem for a directed graph **

A* Algorithm Solves shortest path problem for a directed graph All nodes have a G & H value G: min distance from origin node (A) to the given node H: estimated distance to goal Key to determining which nodes to use: Minimize G + H

16
**How does it work Place origin node A in open list**

Look at all adjacent nodes for A Add them to open list with A as parent Remove A from open list & add to closed list Which node (B) is the minimum distance (G + H)? Remove minimum from open list and add to closed list Look at all adjacent nodes for B not on the closed list Add them to open list with B as parent Which node (C) is the minimum distance (G + H)? Is that node (C) already on the open list? If yes, just ignore B in path Continue in this manner until destination is reached

17
**Strategy games are typically played on grids **

A* and Grids Strategy games are typically played on grids A grid can be easily divided into large nodes store the center of the node nodes must not include impassible terrain (e.g. water) The smaller the nodes, the more processing Example assumptions: horizontal/vertical movements cost 10 diagonal movements cost 14 no diagonal movements through obstacles

18
A* Grid Example

19
A* Grid Example

20
A* Grid Example

21
A* Grid Example

22
A* Grid Example

23
A* Grid Example

24
**A* Pathfinding for beginners**

References A* Pathfinding for beginners

Similar presentations

OK

Artificial Intelligence in Game Design Dynamic Path Planning Algorithms.

Artificial Intelligence in Game Design Dynamic Path Planning Algorithms.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on historical monuments in delhi Ppt on different solid figures Ppt on power diode Ppt on time response analysis control Ppt on tcp ip protocol suite layers Ppt on agriculture and food security Ppt on time series analysis using spss Ppt on earthquake in japan Bill of rights for kids ppt on batteries Ppt on different solid figures pictures