Efficient Path Finding For Tile-Based Games
Efficient Path Finding For Tile-Based Games
ABSTRACT
In this paper we investigate different heuristics
used in an A* (A Star) algorithm. This algorithm
can be used to achieve efficient path finding within
tile-based games. Path finding is a computationally
expensive problem that is solved by searching. We
investigate different optimisation techniques and
further develop techniques which can be
incorporated within the existing algorithm. These
techniques make path finding for 2D static and
dynamic environments faster with less use of
memory.
INTRODUCTION
Often tile-based games have characters that are
controlled by players. Whenever a player issues a
command, it is intended that they behave
intelligently in a manner consistent with their roles.
This may include carrying a box, painting a wall,
etc. But to do these tasks, they have to move from
one place to another. This requires a realistic
looking path between the two locations. As the
number of characters increases, multiple
simultaneously paths may be required. In general,
human movement is an artificial intelligence (AI)
or robotics problem for which there exists a general
solution, Exhaustive Search, which is inefficient.
Therefore, the aim of this study is to investigate the
A* algorithm from the artificial intelligence which
can be used for efficient path finding. Moreover,
we will develop a tool to find an optimal solution to
the path finding problem.
In modern tile-based games, most of the resources
are used in the enhancement of graphics and
physics and very few are available for AI.
Therefore, it is assumed that very limited resources
are available (with respect to memory and
BACKGROUND
Path finding is an AI robotics problem that cannot
be solved without searching. The main problem in
path finding is obstacle avoidance. One of the ways
to approach this problem is by ignoring the
obstacles until one encounters them (Stout, 1996).
This is a simple step-taking algorithm that requires
the units current position and its destination
position to evaluate a direction vector and
information as to whether the units neighbouring
region is clear or blocked. This algorithm finds the
path along with the movement but the paths
generated by this are unrealistic, computationally
expensive and require lots of memory. Therefore it
becomes necessary to have entire knowledge of
path before the movement is applied. This is also
necessary in the case where there are weighted
regions and finding the cheapest path is important.
Various algorithms exist from conventional AI that
can be used for path searching before its execution.
These algorithms are presented in terms of changes
in the state or traversal of nodes in a graph or a
tree. Russell et al (1995) suggested these
algorithms and broadly classified them into two
classes. One class is uninformed search algorithms
such as: Breadth First Search (BFS), Bidirectional
BFS, Depth First Search (DFS), Iterative
Deepening DFS, etc. These algorithms have no
additional information beyond the problem
definition and they keep on generating
neighbouring states or nodes blindly unless they
find the goal. These algorithms do not consider
weighted regions, are computationally expensive,
requires more memory and may not yield paths in
real time. However, they are simple to implement.
The other class of algorithms uses problem specific
knowledge or heuristics to find an efficient
solution. These include algorithms such as
Dijkstra's algorithm, Best First Search (BeFS) and
2.
3.
The A* Algorithm
The A* forms the core of the study. It needs
information regarding memory (storage),
environment (search space) and start and end
locations. As discussed, we partitioned the space
into a rectangular grid with the same height and
width as the size of the environment. This
partitioning is carried out in two levels of
inheritance as suggested by Higgins (2002). This
Memory Management
A* requires memory for extraction of nodes and so
it is important to have a memory manager which
provides an efficient way of dynamic memory
allocation for A* nodes. We implement this by
using the buffering technique (Figure 5). In
buffering, a piece of memory is kept aside by the
system to be used for dedicated task. Here we
reserve this for the storage of A* nodes.
For A*, it is a good way to manage nodes because
A* requires lot of nodes to progress its search.
Initially, when a request is made, a piece of
memory is dedicated before A* starts execution.
During the course of execution, if all the memory
gets exhausted, a new buffer is created to progress.
The size of this buffer is allowed to change so that
less memory is wasted. This size mainly depends
on the complexity of the environment and therefore
requires tuning before it is used in an application.
A Sample Test
We checked the developed heuristic on a
predefined set of start and end locations in an
environment which has large static obstacles. The
following figures (9, 10 and 11) show and compare
the type of path generated by using different
heuristic functions for same start and end location.
Clearly from figures 9 and 10, the paths generated
are the same, but this is not always the case. The
Euclidean distance heuristic requires A* to search
more nodes in order to generate the shortest path.
This is evident from figure 9 which shows the
nodes searched in different colour from the original
grid colour.
REFERENCES
Figure 10: Path finding example using Manhattan
distance heuristic. (Optimal path)