Download presentation
Presentation is loading. Please wait.
Published byPenelope Carpenter Modified over 9 years ago
1
The A* and applications to Games Sources: My own Joseph Siefers presentation 2008
2
CASE STUDY—THE 8-PUZZLE
3
Case Study: The 8-Puzzle http://www.permadi.com/java/puzzle8/ http://www.permadi.com/java/puzzle8/
4
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 Down Right
5
SEARCH TERMINOLOGY
6
Search Terminology Search Tree Node 123 46 785 123 46 785 13 426 785 LeftUp 123 486 75 123 46 785 Dow n Right
7
Search Terminology 123 46 785 123 46 785 13 426 785 LeftUp 123 486 75 123 46 785 Dow n Right “Initial State”
8
Search Terminology Successor Function 123 46 785 123 46 785 13 426 785 Lef t Up 123 486 75 123 46 785 Down Right “Successors”
9
Search Terminology Branching Factor (b) 123 46 785 123 46 785 13 426 785 Lef t Up 123 486 75 123 46 785 Down Right b=4
10
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 (…)
11
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
12
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
13
Search Terminology Goal State 318 64 725 (…) 123 456 78 123 456 78
14
The Search Problem http://www.youtube.com/watch?v=EH0JRFkpnU0&feature=related http://www.youtube.com/watch?v=EH0JRFkpnU0&feature=related Starting from a node n find the shortest path to a goal node g 10 15 20 ? 15 5 18 25 33
15
Greedy Algorithm Greedy algorithm: from the candidate nodes select the one that has a path with minimum cost from the starting node 10 15 20 ? 15 5 18 25 33 Two problems: O(b*n), n = # of edges (so bad) Not optimal (might be OK) Caution: Enemy Nations storyEnemy Nations
16
Djikstra Algorithm T Given a Graph G = (V,E) and T a subset of V, the fringe of T, is defined as: Fringe(T) = { (w,x) in E : w T and x V − T} Djikstra’s algorithm pick the edge v in Fringe(T) that has minimum distance to the starting node g(v) is minimum
17
Example What does Djikstra’s algorithm will do? (minimizing g(n)) Problem: Visit too many nodes, some clearly out of the question
18
Complexity Actual complexity is O(|E|log 2 |E|) Is this good? Actually it is bad for very large graphs! Branching factor: b …. # nodes = b (# levels) Another Example: think of the search space in chess
19
Uninformed Search Strategies estimated with b= 10, a search rate of 10 5 nodes/sec, and 1 KiB/node 1 mebibyte is 2 20 bytes 1 tebibyte = 2 40 bytes 1 pebibyte = 2 50 bytes 1 exbibyte = 2 60 bytes Credit: AIMA fig 3.11, pg 74
20
Better Solution: Take a ‘hunch”! Use heuristics to guide the search –Heuristic: estimation or “hunch” of how to search for a solution We define a heuristic function: h(n) = “estimate of the cost of the cheapest path from the starting node to the goal node”
21
Lets Try A Heuristic Heuristic: minimize h(n) = “Euclidean distance to destination” Problem: not optimal (through Rimmici Viicea and Pitesti is shorter)
22
The A* Search Constraint: we want to still be able to generate the path with minimum cost A* is an algorithm that: –Uses heuristic to guide search –While ensuring that it will compute a path with minimum cost A* computes the function f(n) = g(n) + h(n) “actual cost” “estimated cost”
23
A* f(n) = g(n) + h(n) –g(n) = “cost from the starting node to reach n” –h(n) = “estimate of the cost of the cheapest path from n to the goal node” 10 15 20 15 5 18 25 33 n g(n) h(n)
24
Example A*: minimize f(n) = g(n) + h(n)
25
A* Map Problem Heuristics Manhattan vs. Euclidean distance comparison Image Credit: Wikimedia Commons http://www.vision.ee.ethz.ch/~cvcourse/astar/AStar.html
26
Uninformed Search Strategies Breadth-First in Action
27
A* Search: Compare and Contrast Manhattan distance: Weight 0
28
A* Search: Compare and Contrast Manhattan distance: Weight 1
29
A* Search: Compare and Contrast Manhattan distance: Weight 2
30
A* Search: Compare and Contrast Manhattan distance: Weight 3
31
A* Search: A Look Back… Breadth-First SearchA*, Manhattan, W=3 75% LESS NODES!
32
A* in Games Path finding –Frequently used –Though sometimes even A* speed improvements are not sufficient –Additional improvements are required A* can be used for planning moves computer-controlled player (e.g., chess) F.E.A.R. uses A* to plan its search
33
A* Optimizations Some games don’t pathfind Quick straight line check E.g., Diablo 2 “Flood Approaches” –Measure flooding Visually on map
34
A* Optimizations Visual representation of flooding Image Credit: AIGPW Figure 3.4.1
35
A* Optimizations Memory Pooling –pre-allocating a number of memory blocks with the same size –Allocating memory CPU intensive –How much memory? Specific to each game Find “perfect balance” –Statistical Analysis –Current technology makes pooling practical
36
How to Create Good Heuristics Relax the conditions of the problem –This will result in admissible heuristics! Lets look at an 8-puzzle game: http://www.permadi.com/java/puzzle8/ Possible heuristics?
37
Example: Good Heuristics in 8-Puzzle Game Heuristic: a tile A can be moved to any tile B –h1(n) = “number of misplaced tiles in board n” Heuristic: a tile A can be moved to a tile B if B is adjacent to A –h2(n) = “sum of distances of misplaced tiles to goal positions in board n” Some experimental results reported in Russell & Norvig (2002): –A* with h2 performs up to 10 times better than A* with h1 –A* with h2 performs up to 36,000 times better than a classical uninformed search algorithm (iterative deepening)
38
Properties of Heuristics The heuristic h must be admissible (tree search): –h(n) cost(n) where cost(n) = “actual cost to reach goal” Is h1 admissible? Is h2 admissible? The heuristic h must be consistent (graph search) –For each child p of n: h(n) cost(n,p) + h(p) –h(G) = 0 // G is a goal –Is h1 consistent? Is h2 consistent? Property: If h is consistent then h is admissible –But the opposite is not necessarily true
39
What about a game in real time? The Super Mario competition Remake of game classic API was provided to control Mario Use whatever means to control the AI Winner of 2009 competition used A*
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.