Introduction to Artificial Intelligence for Game Development Path Finding - PowerPoint PPT Presentation

1 / 50
About This Presentation
Title:

Introduction to Artificial Intelligence for Game Development Path Finding

Description:

Agents must be able to find their way around the game world ... The fastest and most efficient pathfinding techniques tend to consume a great deal of resources ... – PowerPoint PPT presentation

Number of Views:75
Avg rating:3.0/5.0
Slides: 51
Provided by: isabellebi
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Artificial Intelligence for Game Development Path Finding


1
Introduction to Artificial Intelligence for Game
Development Path Finding
2
Outline
  • Path Finding
  • Path Representation
  • Search algorithms
  • Example

3
Learning Objectives
  • Understand how to represent a path finding data
    structure.
  • Understand main algorithms for path finding.
  • Understand examples of code for path finding.

4
Acknowledgments
  • Rabin, Steve, AI Game Programming Wisdom series.
  • Bourg, D.M., Seeman, G. AI for Game Developers.
    (Safari online).
  • Buckland, Mat, Programming Game AI by Example.
  • Some of these slides have been adapted from Steve
    Rabin

5
Introduction
  • Almost every game requires pathfinding
  • Agents must be able to find their way around the
    game world
  • Pathfinding is not a trivial problem
  • The fastest and most efficient pathfinding
    techniques tend to consume a great deal of
    resources
  • Needs a data structure (a navigation graph) and a
    search algorithm

6
Representing the Search Space
  • Agents need to know where they can move
  • Search space should represent either
  • Clear routes that can be traversed
  • Or the entire walkable surface
  • Search space typically doesnt represent
  • Small obstacles or moving objects
  • Most common search space representations
  • Grids
  • Waypoint graphs
  • Navigation meshes

7
Grids
  • 2D grids intuitive world representation with
    cells / tiles
  • Works well for many games including some 3D games
    such as Warcraft III
  • Each cell is flagged
  • Passable or impassable
  • Each object in the world can occupy one or more
    cells

8
Characteristics of Grids
  • Fast look-up
  • Easy access to neighboring cells
  • Complete representation of the level (may be very
    large 100 x 100 10,000 cells)

9
Waypoint Graph
  • A waypoint graph specifies lines/routes that are
    safe for traversing (points of visibility POVs)
  • Each line (or link) connects exactly two waypoints

10
Characteristicsof Waypoint Graphs
  • Waypoint node can be connected to any number of
    other waypoint nodes
  • Waypoint graph can easily represent arbitrary 3D
    levels
  • Can incorporate auxiliary information
  • Such as ladders and jump pads
  • Incomplete representation of the level

11
Navigation Meshes
  • Combination of grids and waypoint graphs
  • Every node of a navigation mesh (navmesh)
    represents a convex polygon (or area)
  • As opposed to a single position in a waypoint
    node
  • Advantage of convex polygon
  • Any two points inside can be connected without
    crossing an edge of the polygon
  • Navigation mesh can be thought of as a walkable
    surface

12
Navigation Meshes (continued)

13
Characteristics of Navigation Meshes
  • Complete representation of the level
  • Ties pathfinding and collision detection together
  • Can easily be used for 2D and 3D games

14
Searching for a Path
  • A path is a list of cells, points, or nodes that
    an agent must traverse
  • A pathfinding algorithm finds a path
  • From a start position to a goal position
  • The following pathfinding algorithms can be used
    on
  • Grids
  • Waypoint graphs
  • Navigation meshes

15
Criteria for Evaluating Pathfinding Algorithms
  • Quality of final path
  • Resource consumption during search
  • CPU and memory
  • Whether it is a complete algorithm
  • A complete algorithm guarantees to find a path if
    one exists

16
Random Trace
  • Simple algorithm
  • Agent moves towards goal
  • If goal reached, then done
  • If obstacle
  • Trace around the obstacle clockwise or
    counter-clockwise (pick randomly) until free path
    towards goal
  • Repeat procedure until goal reached

17
Random Trace (continued)
  • How will Random Trace do on the following maps?

18
Random Trace Characteristics
  • Not a complete algorithm
  • Found paths are unlikely to be optimal
  • Consumes very little memory

19
Understanding A
  • To understand A
  • First understand Breadth-First, Best-First, and
    Dijkstra algorithms
  • These algorithms use nodes to represent candidate
    paths

20
Understanding A
  • class PlannerNode
  • public
  • PlannerNode m_pParent
  • int m_cellX, m_cellY
  • ...
  • The m_pParent member is used to chain nodes
    sequentially together to represent a path

21
Understanding A
  • All of the following algorithms use two lists
  • The open list
  • The closed list
  • Open list keeps track of promising nodes
  • When a node is examined from open list
  • Taken off open list and checked to see whether it
    has reached the goal
  • If it has not reached the goal
  • Used to create additional nodes
  • Then placed on the closed list

22
Overall Structure of the Algorithms
  • 1. Create start point node push onto open list
  • 2. While open list is not empty
  • A. Pop node from open list (call it currentNode)
  • B. If currentNode corresponds to goal, break
    from step 2
  • C. Create new nodes (successors nodes) for cells
    around currentNode and push them onto open list
  • D. Put currentNode onto closed list

23
Breadth-First
  • Finds a path from the start to the goal by
    examining the search space ply-by-ply

24
Breadth-First Characteristics
  • Exhaustive search
  • Systematic, but not clever
  • Consumes substantial amount of CPU and memory
  • Guarantees to find paths that have fewest number
    of nodes in them
  • Not necessarily the shortest distance!
  • Complete algorithm

25
Best-First
  • Uses problem specific knowledge to speed up the
    search process
  • Head straight for the goal
  • Computes the distance of every node to the goal
  • Uses the distance (or heuristic cost) as a
    priority value to determine the next node that
    should be brought out of the open list

26
Best-First (continued)
27
Best-First (continued)
  • Situation where Best-First finds a suboptimal
    path

28
Best-First Characteristics
  • Heuristic search
  • Uses fewer resources than Breadth-First
  • Tends to find good paths
  • No guarantee to find most optimal path
  • Complete algorithm

29
Dijkstra
  • Disregards distance to goal
  • Keeps track of the cost of every path
  • No guessing
  • Computes accumulated cost paid to reach a node
    from the start
  • Uses the cost (called the given cost) as a
    priority value to determine the next node that
    should be brought out of the open list

30
Dijkstra Characteristics
  • Exhaustive search
  • At least as resource intensive as Breadth-First
  • Always finds the most optimal path
  • Complete algorithm

31
A
  • Uses both heuristic cost and given cost to order
    the open list
  • Final Cost Given Cost (Heuristic Cost
    Heuristic Weight)

32
A Example
33
Heuristic search
  • Greedy search example

34
Heuristic Search
  • Greedy search example

35
Heuristic Search
  • Greedy search example

36
Heuristic Search
  • Properties of greedy searchComplete?? No can
    get stuck in loops, e.g., with Oradea as goal,
    Iasi ? Neamt ? Iasi ? Neamt ? Complete in
    finite space with repeated-state checkingTime??
    O(bm), but a good heuristic can give dramatic
    improvementSpace?? O(bm) keeps all nodes in
    memoryOptimal?? No

37
Heuristic Search
  • A search
  • Avoid expanding paths that are already expansive
  • Evaluation function f(n) g(n) h(n)g(n)
    cost so far to reach nh(n) estimated cost to
    goal from nf(n) estimated total cost of path
    through n to goal
  • A search uses an admissible heuristici.e., h(n)
    ? h(n) where h(n) is the true cost from
    n.(also require h(n) ?0, so h(G) 0 for any
    goal G.)example, hSLD(n) never overestimates
    the actual road distance.
  • Theorem A search is optimal.

38
Heuristic Search
  • A search example

39
Heuristic Search
  • A search example

40
Heuristic Search
  • A search example

41
Heuristic Search
  • A search example

42
Heuristic Search
  • A search example

43
Heuristic Search
  • A search example

44
A (continued)
  • Avoids Best-First trap!

45
A Characteristics
  • Heuristic search
  • On average, uses fewer resources than Dijkstra
    and Breadth-First
  • Admissible heuristic guarantees it will find the
    most optimal path
  • Complete algorithm

46
A versus Dijkstra
  • Afinds the least cost path to one specific
    target
  • Dijkstra finds the least cost path to any number
    of specific targets.

47
Summary
  • Two key aspects of pathfinding
  • Representing the search space
  • Searching for a path

48
PathPlannerApp Demo
49
Waypoint Graph Demo

50
Examples
  • In class.
Write a Comment
User Comments (0)
About PowerShow.com