Top Banner
A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between two points. The basic assumption is that the search area is tiled (e.g. square tile) and that the animat moves from the center of one tile to the center of the next tile.
11

A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

Mar 15, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

A* Pathfinding

The A* pathfinding algorithm is anexhaustive search algorithm which isguaranteed to find the shortest pathbetween two points.

The basic assumption is that thesearch area is tiled (e.g. square tile)and that the animat moves from thecenter of one tile to the center of thenext tile.

Page 2: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

A* Algorithm

Add the starting square to the open list. Repeat the following:

Look for the lowest F cost square on the open list. We refer to this as thecurrent square.

Switch it to the closed list. For each square adjacent to this current square

• If it is not walkable or if it is on the closed list, ignore it.• If it is not on the open list, add it to the open list. Make the current

square the parent of this square. Record the F, G, and H costs of thesquare.

• If it is on the open list already, check to see if this path to that square isbetter, using G cost as the measure. If so, change the parent of thesquare to the current square, and recalculate the G and F scores of thesquare.

Stop when you:• Add the target square to the closed list, in which case the path has been

found or• Fail to find the target square, and the open list is empty. In this case,

there is no path. Save the path. Working backwards from the target square, go from each square to

its parent square until you reach the starting square.

Source: A* Pathfinding for Beginners, Patrick Lester, http://www.policyalmanac.org/games/aStarTutorial.htm

Page 3: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

The Search Area

StartingPoint Target

Obstacle

What is the shortest path from the starting point to the target?

Tiles

Page 4: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

Data StructuresParent Pointer

Closed List

Open List

Scores

Scores:F = G + HG = the movement cost to move from the starting point to the given square following the generated path.H = the estimated movement cost to move from the given square to the target.

Page 5: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

First Iterations

Page 6: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

First Iterations

Page 7: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

First Iterations

not added – would cut across the corner of the wall

Page 8: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

Final Iterations

Page 9: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

Final Iterations

Page 10: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

Another Example

Source: AI for Game Developers, D. Bourg and G. Seemann, O’Reilly, 2004

Page 11: A* Pathfinding - University of Rhode Island · A* Pathfinding The A* pathfinding algorithm is an exhaustive search algorithm which is guaranteed to find the shortest path between

Another Example