Download presentation
Presentation is loading. Please wait.
Published byAugust Peters Modified over 9 years ago
1
1 CO2301 - Games Development 1 Week 8 A* Gareth Bellaby
2
2 Best first searches Best first algorithm is estimate of distance to goal Dijkstra's algorithm is cost A* algorithm is cost + estimate
3
3 A* algorithm Combines cost with a prediction of how close the goal is. A* is an efficient pathfinding algorithm.
4
4 A* algorithm As with Dijkstra's Algorithm the algorithm itself is on the web site in "algorithms.doc" since it is too long to put up in a PowerPoint presentation. Note that the open list is a priority queue. Also note that the algorithm removes items from the closed list if a better route to a node is found during the course of the search.
5
5 A* algorithm f(n) = g(n) + h(n) f(n) is the evaluation function, i.e. the score assigned to node. g(n) is the actual cost of getting to n from the start. h(n) is the heuristic estimate of getting from n to the goal.
6
6 A* example - heuristic Use a simple heuristic: count the total number of squares to the destination. This is called the Manhattan distance. Simply sum together the number of squares horizontally and vertically. start 1 1 2 2 3 234
7
7 A* example - cost Need to include the actual cost incurred for moving to a particular square. Cost is 1 for a white square, 2 for a green square and the wall is impassable.
8
8 A* example 1 Red: start/end Black: wall Green: forest Apply the rules in the order N, E, S, W
9
9 A* example 1 - accumulated cost 5 Cost of the square + cost of the route taken to the square. Obviously the accumulated cost depends on the exact route taken. 3 7 3 4 5 6 5 6 6 1 2 0 1
10
10 A* example 1 - heuristic 1 Red: start/end Black: wall Green: forest Apply the rules in the order N, E, S, W (So the cost to the square above the wood is 4 because the route was through the wood - a lower cost route does exist) 3 1 2 3 2 1 2 2 3 0 2 3 3 4 2 3 4 3 4 2 3 4
11
11 A* example 1 Red: start/end Black: wall Green: forest Apply the rules in the order N, E, S, W (So the cost to the square above the wood is 4 because the route was through the wood - a lower cost route does exist) 1+3 4 1+3 4 2+4 6 3+2 5 2+4 6 5+1 6 4+3 7 6+0 6
12
12 A* example 2 Red: start/end Black: wall Green: forest Apply the rules in the order N, E, S, W
13
13 A* example 2 Red: start/end Black: wall Green: forest Apply the rules in the order N, E, S, W 1+4 5 2+3 5 1+2 3 3+3 6 2+5 7 3+2 5 4+1 5 5+0 5
14
14 A* example 3 Red: start/end Black: wall Green: forest Apply the rules in the order N, E, S, W
15
15 A* example 3 Red: start/end Black: wall Green: forest Apply the rules in the order N, E, S, W 1+4 5 2+3 5 1+2 3 2+5 7 2+3 5 3+4 7 3+2 5 4+1 5 4+3 7 4+3 7 5+0 5
16
16 Admissibility If a grid is used, and the only allowed movement is horizontally or vertically, then the Manhattan distance is: admissible, i.e. it never overestimates the distance. the best possible heuristic that can be used.
17
17 Admissibility In A* proper the heuristic estimate must be admissible, i.e. it never uses a heuristic that overestimates the distance. A* is guaranteed to find the optimal solution, but only if the heuristic estimate is admissible. Why?
18
18 A* algorithm If A* uses a heuristic that overestimates the distance then the value calculated by the heuristic can be larger than the cost. Consider the boundary conditions. At the extreme, overestimating the heuristic is equivalent to ignoring the cost. If the cost is ignored then the algorithm is just based on the heuristic. This is the best-first search algorithm.
19
19 A* algorithm Now, consider the other extreme. If the heuristic estimation is ignored then the algorithm is just based on cost. This is Dijkstra's algorithm. The best situation is one where the heuristic evaluation approaches the cost but is never actually overestimated.
20
20 The graceful decay of admissibility In A* proper the heuristic estimate must be admissible, i.e. it never uses a heuristic that overestimates the distance. A* is guaranteed to find the optimal solution, but only if the heuristic estimate is admissible. Games pathfinding often ignores this: emphasising speed over optimality.
21
21 The graceful decay of admissibility If your heuristic rarely over-estimates the real distance to goal by more than a certain value (lets call it d) then the A* algorithm will rarely find a solution which costs more than d over the cost of the optimal solution. Graceful decay of admissability. Be strict about admissability at the beginning of the search but as the search is assumed to get closer to the destination relax the admissability criterion.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.