Download presentation
Presentation is loading. Please wait.
Published byPauline Lyons Modified over 9 years ago
1
PATHFINDING WITH A* Presented by Joseph Siefers February 19 th, 2008
2
Outline Introduction to Pathfinding Search Terminology Search Methods Uninformed Search Informed Search A* Search: How it Works A* Optimizations Conclusion
3
Introduction Effective pathfinding is the key to a good game …unless your studio wants to be the laughing stalk of gamers worldwide: http://www.youtube.com/watch?v=wsNK-eisKuU http://www.youtube.com/watch?v=wsNK-eisKuU http://www.youtube.com/watch?v=EH0JRFkpnU0&feature=related http://www.youtube.com/watch?v=EH0JRFkpnU0&feature=related But it is difficult to do. Efficient search strategy/algorithms A* is the “star of the search”
4
Case Study—The 8-Puzzle
5
Case Study: The 8-Puzzle From the set of AI exercises know as “Toy Problems” Why? Easy to define and understand. Sufficiently complex to analyze search methods.
6
Case Study: The 8-Puzzle Rules of the game: Move free space {left, up, down, right} within boundaries of puzzle. 123 46 785 123 46 785 13 426 785 LeftUp 123 486 75 123 46 785 DownRight
7
Search Terminology
8
Search Tree Node 123 46 785 123 46 785 13 426 785 LeftUp 123 486 75 123 46 785 DownRight
9
Search Terminology 123 46 785 123 46 785 13 426 785 LeftUp 123 486 75 123 46 785 DownRight “Initial State”
10
Search Terminology Successor Function 123 46 785 123 46 785 13 426 785 Left Up 123 486 75 123 46 785 Down Right “Successors”
11
Search Terminology Branching Factor (b) 123 46 785 123 46 785 13 426 785 Left Up 123 486 75 123 46 785 Down Right b=4
12
Search Terminology Step Cost 123 46 785 123 46 785 13 426 785 123 486 75 123 46 785 +1 23 146 785 123 746 85 13 426 785 (…)
13
Search Terminology Path Cost g(n) 123 46 785 123 46 785 13 426 785 123 486 75 123 46 785 +1 23 146 785 123 746 85 13 426 785 (…) g(n) = 1
14
Search Terminology Path Cost g(n) 123 46 785 123 46 785 13 426 785 123 486 75 123 46 785 +1 23 146 785 123 746 85 13 426 785 (…) g(n) = 2
15
Search Terminology Goal State 318 64 725 (…) 123 456 78 123 456 78
16
Search Terminology “The Fringe” Open/Closed lists “Algorithms which ignore their history are doomed to repeat it.” –AIMA pg 82
17
Search Strategies
18
Uninformed Search Strategies Uninformed Search Blindly search tree “Driving without a map”
19
Uninformed Search Strategies Breadth First Search nodes in “hierarchical order” FIFO Image Credit: Wikimedia Commons
20
Uninformed Search Strategies Let’s see breadth-first search in action! “Pathdemo” by Bryan Stout
21
Uninformed Search Strategies Breadth-First in Action
22
Uninformed Search Strategy Overall Result:
23
Uninformed Search Strategies Depth First Repeatedly traverse one path to completion
24
Unformed Search Strategies Depth-First in Action? —“No Dice”
25
Uninformed Search Strategies Problems: Not practical: (estimated with b= 10, a search rate of 10 5 nodes/sec, and 1 KiB/node) Credit: AIMA fig 3.11, pg 74
26
Search Strategies Informed Search Traverse search tree “intelligently” “Driving with a map” A heuristic function = “the map”
27
Informed Search Strategies Heuristic function h(n) Estimate path cost to goal Key to improving search problems NEVER overestimate— “be optimistic”
28
Heuristics Admissibility “Relaxed” Problems Simplify constraints Reduces complexity Example: 8-Puzzle ? Initial StateGoal State 413 25 786 123 456 78
29
A* Search: Introduction A * search: Extremely fast Provably optimal (given an admissible heuristic) Flexible and Adaptable
30
A* Search: How it Works Estimated Overall Path Cost = How far I think I have to go + How far I have come
31
A* Search: How it Works Node evaluation function Heuristic function Current Path Cost
32
A* Search: How it works A* Algorithm Pseudocode 1. Let P= the starting point 2. Assign f, g and h values to P. 3. Add P to the Open list. 4. Let B = the best node (lowest f) from the Open list a. If B is the goal node, quit (path found) b. If the Open list is empty, quit (path impossible) A* Algorithm Pseudocode 1. Let P= the starting point 2. Assign f, g and h values to P. 3. Add P to the Open list. 4. Let B = the best node (lowest f) from the Open list a. If B is the goal node, quit (path found) b. If the Open list is empty, quit (path impossible)
33
A* Search: How it works 5. Expand B a. Generate f,g,h values for the successors of B b. Add successors to open list, appropriately 6. Repeat from step 4 5. Expand B a. Generate f,g,h values for the successors of B b. Add successors to open list, appropriately 6. Repeat from step 4
34
A* in Map Problems Example Problem—“The hurried traveler”
35
A* Map Problem Heuristics A* efficiency dependent on choice of heuristic Euclidean Distance Always admissible Manhattan Distance “City Blocks” Admissible for discrete map problems h = |dx-sx| + |dy-sy|
36
A* Map Problem Heuristics Manhattan vs. Euclidean distance comparison Image Credit: Wikimedia Commons
37
A* Search: Map Problem Testing Interesting parameters in “Pathdemo” Heuristic weight Sample heuristic functions Manhattan Distance Diagonal Shortcut Euclidean Max
41
A* Search: Compare and Contrast Manhattan distance: Weight 0
42
A* Search: Compare and Contrast Manhattan distance: Weight 1
43
A* Search: Compare and Contrast Manhattan distance: Weight 2
44
A* Search: Compare and Contrast Manhattan distance: Weight 3
45
A* Search: A Look Back… Breadth-First Search A*, Manhattan, W=3 75% LESS NODES
46
A* Optimizations Don’t pathfind Common solution Quick straight line check “Flood insurance” Measure flooding Visually on map
47
A* Optimizations Visual representation of flooding Image Credit: AIGPW Figure 3.4.1
48
A* Optimizations Don’t pathfind Common solution “Flood insurance” Measure flooding and reduce Visually on map Sometimes futile… Limit map designs?
49
A* Optimizations Memory Pooling Allocating memory CPU intensive How much memory? Specific to each game Find “perfect balance” Statistical Analysis Current technology makes pooling practical
50
A* Optimizations Open/Closed list implementation “Priority queue” Heap O(lg n) operations Even this might not be fast enough Hash Table O(1) operations Problems fine-tuning “Cheap List”
51
Optimization Tools Performance metric for search algorithms Intel VTune In-Code Timers Approximate execution time Multithreading Issues Other threads might be busy and slowing Pathfinding Valuable “Standard Path” No tool stands by itself
52
Conclusion A* solves difficult pathfinding problems Ubiquitous across gaming industry Shows up in every type of game A* is highly dependent on a good heuristic Breadth-first if bad heuristic A* can be resource-intensive A* is not a “one-size fits all” solution Plan on spending time optimizing Solved problem
53
Thank you! Thanks for listening!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.