1 / 24

# - PowerPoint PPT Presentation

CSE 380 – Computer Game Programming Pathfinding AI. Dig Dug, by Namco. 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

Related searches for

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about '' - felton

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### CSE 380 – Computer Game ProgrammingPathfinding AI

Dig Dug, by Namco

• 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

• 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

• 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 45-90 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

• 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

• Modern strategy games use lots of units simultaneously

• Dynamically computing paths can be expensive

• Solution: precompute

• 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

• Paths should avoid obstacles

• 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

• 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

• 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?

• 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

• Searches one way all the way until:

• it finds the goal

OR

• it runs out of space

• 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:

• http://carbon.cudenver.edu/~hgreenbe/sessions/dijkstra/DijkstraApplet.html

• 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

• 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

• 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

• A* Pathfinding for beginners

• http://www.policyalmanac.org/games/aStarTutorial.htm