A-Based Pathfinding in Modern Computer Games
A-Based Pathfinding in Modern Computer Games
net/publication/267809499
CITATIONS READS
154 41,700
2 authors:
All content following this page was uploaded by Xiao Cui on 09 March 2015.
point n, h(n) represents the estimated cost from point n to roadmap of North America, showing all roads annotated
the destination, and f(n)=g(n)+h(n). Fig. 1 lays out the with driving distances, an A* implementation can
algorithm step-by-step. compute the optimal travel route but this might be an
A* has several useful properties which have been proved expensive computation because of the sheer size of the
by Hart, Nilsson and Raphael in 1968 [4]. First, A* is roadmap. However, a hierarchical path finding would
guaranteed to find a path from the start to the goal if never work at such a low level of detail. Using
there exists a path. And it is optimal if h(n) is an abstraction can quickly find a route. The problem
admissible heuristic, which means h(n) is always less described above might be solved more efficiently by
than or equal to the actual cheapest path cost from n to planning a large-scale route at the city level first and then
the goal. The third property of A* is that it makes the planning the inter routes at each city passing through.
most efficient use of the heuristic. That is, no search
method which uses the same heuristic function to find an
optimal path examines fewer nodes than A*.
Although A* is the most popular choice for pathfinding
in computer games, how to apply it in a computer game
depends on the nature of the game and its internal
representation of the world. For example, in a
rectangular grid of 1000×1000 squares, there are 1
million possible squares to search. To find a path in that
kind of map simply takes a lot of work. Thus, reducing
the search space may significantly speed up A*. Several
optimizations are discussed in Section 3.
3. A* Optimizations
Fig. 2 Five ways to represent search space [5].
The following sub-sections discuss several potential
optimizations of A* from four different perspectives and A much faster A*-based search algorithm giving nearly
reviews some popular A*-based algorithms. solutions named HPA* is described in [6]. This is a
domain-independent approach. The hierarchy can be
3.1 Search Space extended to more than two levels, making it more
scalable for large problem spaces. A three-step process is
In any game environment, AI characters need to use an applied. The first step is to travel to the border of the
underlying data structure – a search space representation neighborhood that contains the start location. Then, the
– to plan a path to any given destination. Finding the second step is to search for a path from the border of the
most appropriate data structure to represent the search start neighborhood to the border of the goal
space for the game world is absolutely critical to neighborhood. This step is done at an abstract level,
achieving realistic-looking movement and acceptable where search is simpler and faster. The last step is to
pathfinding performance. As you can see in the above complete the path by travelling from the border of the
example, a simpler search space will mean that A* has goal neighborhood to the goal position. HPA* has been
less work to do, and less work will allow the algorithm to proved that it is 10 times faster than a low-level A* in [6].
run faster. Examples of such representations include The potential problem of this technique is that the cost
rectangular grid (Fig. 2a), quadtree (Fig. 2c), convex increases significantly when adding a new abstraction
polygons (Fig. 2d), points of visibility (Fig. 2e), and layer.
generalized cylinders (Fig. 2f).
The following sub-sections review two popular A*-based 3.1.2 Navigation Mesh (NavMesh)
algorithms which optimize A* algorithm by reducing the
search space. NavMesh is another popular technique for AI pathfinding
in 3D worlds. A NavMesh is a set of convex polygons
3.1.1 Hierarchical Pathfinding A* (HPA*) that describe the “walkable” surface of a 3D environment.
It is a simple, highly intuitive floor plan that AI
Hierarchical pathfinding is an extremely powerful characters can use for navigation and pathfinding in the
technique that speeds up the pathfinding process. The game world.
complexity of the problem can be reduced by breaking Fig. 3b shows an example of NavMesh. A character
up the world hierarchically. Consider the problem of moves from the starting point in pol2 to the desired
travelling from Los Angeles to Toronto. Given a detailed destination in pol4. In this case, the starting point is not
IJCSNS International Journal of Computer Science and Network Security, VOL.11 No.1, January 2011 127
in the same polygon as the desired point. Thus, the search using various heuristic costs while trying to
character needs to determine the next polygon it will go overcome a large obstacle.
to. Repeat this step until both the character and the goal When the heuristic equals to zero (shown in Fig. 4a), A*
are located in the same polygon. Then, the character can algorithm turns to Dijkstra’s algorithm. All the
move to the destination in a straight line. neighboring nodes are expanded. When the heuristic uses
Compared with a waypoint graph as shown in Fig. 3a, the Euclidean distance to the goal (shown in Fig. 4b),
NavMesh approach is guaranteed to find a near optimal only the nodes that look like better options are examined.
path by searching much less data. And the pathfinding When the heuristic is overestimated a little (shown in Fig.
behavior in a NavMesh is superior to that in a waypoint 4c), the search pushes hard on the closest nodes to the
graph [7]. goal. Thus, overestimating the heuristic cost a little may
result in exploring much fewer nodes than
non-overestimation heuristic approaches. However, how
much should the cost be overestimated is a tricky
problem. No general solution exists at present.
3.3 Memory
Although A* is about as good a search algorithm as you
can find so far, it must be used wisely; otherwise, it
might be wasteful of resources. A* algorithm requires a
huge amount of memory to track the progress of each
search especially when searching on large and complex
environments. Reducing the required memory for
pathfinding is a tricky problem in game AI. There has
been a lot of work on this area.
minimum memory mainly depends on the complexity of group of units goes around forest to get to another
the environment. Thus, tuning is required before this position, half of them get stuck in the trees as shown in
strategy is applied to a particular application. Fig. 5. Such situations always happen especially when
Another alternative to reduce space requirements in A* is the density of forest increases.
to compute the whole path in small pieces. This is the
core concept behind IDA* (Iterative Deepening A*),
which is a very popular variant of A* algorithm. In IDA*,
a path is cut off when its total cost f(n) exceeds a
maximum cost threshold. IDA* starts with a threshold
equal to f(start_node), in this case, the threshold is equal
to h(start_node) because g(start_node)=0. Then,
neighboring nodes are expanded until either a solution is
found that scores below the threshold or no solution is
found. In this case, the threshold is increased by one, and
another search is triggered. The main advantage of IDA*
over A* is that memory usage is significantly reduced.
multiplayer online is another example which involves techniques described in this paper have been widely used
real-time pathfinding intensively, like World of in current game industry. The reason why they are
WardCraft. reviewed in this paper is that they are the hottest topics in
the academic domain of pathfinding and many
4.2 Comparison between Map Representations researchers are struggling to bring them into real games.
It is expected that this research help game industry has a
Waypoint graph is a popular technique to represent map basic understanding about the future research direction in
locations. Waypoints are a set of points that refer to the pathfinding.
coordinates in the physic space. It is designed for
navigation purpose and has been applied to a wide range
of areas. Most game engines support pathfinding on a
waypoint graph. Although it works well for most 2D
games, it requires tons of waypoints to achieve an
adequate movement in a 3D game because of the
complexity of the environment. Thus, a new technique
called NavMesh is created. As mentioned in Section
3.1.2, NavMesh only requires a couple of polygons to
represent the map. It results in a much more quickly
pathfinding because less data is examined.
Five reasons why NavMesh works better than waypoint
approaches in 3D games using World of WarCraft as an
example are addressed by Tozour in 2008 [8]. It shows
the difference between waypoints approaches and
NavMesh when representing a complex 3D environment.
It uses the town of Halaa in World of WarCraft as an (a) Navigating from A to B using waypoint graph.
example as shown in Fig. 7. In Fig. 7a, it uses 28
waypoints to represent the possible locations while on
the other hand, as shown in Fig. 7b, only 14 convex
polygons are used. The movement in Fig. 7b also acts
much more like an actual human than the movement in
Fig. 7a.
5. Conclusion
This paper systematically reviews several popular
A*-based algorithms and techniques according to the
optimization of A*. It shows a clearly relational map
between A* algorithm and its variants. The core of
pathfinding algorithm is only a small piece of the puzzle
in game AI. The most challenge is how to use the
algorithm to solve tricky problems. A* algorithm is the (b) Navigating from A to B on NavMesh.
most popular algorithm in pathfinding. It is hard-pressed
Fig. 7 Comparison between wapoing graph and NavMesh [8].
to find a better algorithm since A* is provably optimal. A
lot of effort has been put into speeding it up by
References
optimizing it from different perspectives. The ways to [1] B. Stout, “Smart moves: intelligent path-finding,” in Game
improve the performance of A* search include Developer Magazine, pp.28-35, 1996.
optimizing the underlying search space, reducing the [2] Stanford Theory Group, “Amit’s A* page”,
memory usage, improving heuristic functions and http://theory.stanford.edu/~amitp/GameProgramming/ASta
introducing new data structures. rComparison.html, accessed October 12, 2010.
A potential research is to continue optimizing A* [3] N.Nilsson, Artificial Intelligence: A New Synthesis,
algorithm from these perspectives or to combine multiple Morgan Kaufmann Publishers, San Francisco, 1998.
optimization techniques into one single solution. Another [4] P. Hart, N. Nilsson, and B. Raphael, “A formal basis for
the heuristic determination of minimum cost paths,” IEEE
way to make some contribution to the game AI
Trans.Syst.Sci.Cybernet., vol.4, no.2, pp.100-107, 1968
community is to apply these techniques described above
to the real computer games because not all of the
130 IJCSNS International Journal of Computer Science and Network Security, VOL.11 No.1, January 2011