0% found this document useful (0 votes)
0 views9 pages

Topic5 PathFinding Algorithm

The document discusses the challenges and strategies of pathfinding in computer games, emphasizing the importance of efficient agent movement and obstacle avoidance. It covers various methods such as Navigation Meshes and Waypoints for simplifying game world geometry, as well as different pathfinding approaches including directed and undirected algorithms, with a focus on the A* algorithm. Additionally, it explores the potential of machine learning techniques, like Neural Networks and Genetic Algorithms, to enhance pathfinding capabilities and address resource limitations in real-time scenarios.

Uploaded by

kennylatimore4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views9 pages

Topic5 PathFinding Algorithm

The document discusses the challenges and strategies of pathfinding in computer games, emphasizing the importance of efficient agent movement and obstacle avoidance. It covers various methods such as Navigation Meshes and Waypoints for simplifying game world geometry, as well as different pathfinding approaches including directed and undirected algorithms, with a focus on the A* algorithm. Additionally, it explores the potential of machine learning techniques, like Neural Networks and Genetic Algorithms, to enhance pathfinding capabilities and address resource limitations in real-time scenarios.

Uploaded by

kennylatimore4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

TOPIC 5 A.

I PATHFINDING IN GAMES

Table of Contents
TOPIC 5 A.I PATHFINDING IN GAMES................................................................................................1
Pathfinding in Games............................................................................................................................1
Game World Geometry..........................................................................................................................2
Navigation Meshes...........................................................................................................................2
Waypoints.........................................................................................................................................2
Graph Theory.........................................................................................................................................4
Pathfinding............................................................................................................................................4
Approaches to Pathfinding...............................................................................................................5
Undirected....................................................................................................................................5
Directed........................................................................................................................................5
Machine Learning..................................................................................................................................6
Learning Algorithms..............................................................................................................................7
Neural Networks...............................................................................................................................7
Genetic Algorithms...........................................................................................................................8
How Learning Algorithms Can Solve Pathfinding Problems...............................................................8

Pathfinding in Games

• One of the greatest challenges in the design of realistic Artificial Intelligence (AI) in computer
games is agent movement.
• Pathfinding strategies are usually employed as the core of any AI movement system.
• Pathfinding strategies have the responsibility of finding a path from any coordinate in the game
world to another.
• Systems such as this take in a starting point and a destination; they then find a series of points
that together comprise a path to the destination.
• Pathfinding generally refers to find the shortest route between two end points. Examples of such
problems include transit planning, telephone traffic routing, maze navigation and robot path
planning.
• As the importance of game industry increases, pathfinding has become a popular and frustrating
problem in game industry.
• Games like role-playing games and real-time strategy games often have characters sent on
missions from their current location to a predetermined or player determined destination.

1 PKasyoka
• Pathfinding for a non-player character uses up a lot of CPU power and memory.
• Pathfinding depends on the game environment where the obstacle may be static or dynamic.
• The most common issue of pathfinding in a computer game is how to avoid obstacles cleverly
and seek out the most efficient path over different terrain.

Game World Geometry


• Typically the world geometry in a game is stored in a structure called a map.
• Maps usually contain all the polygons that make up the game environment.
• In a lot of cases, in order to cut down the search space of the game world for the pathfinder the
games map is broken down and simplified.
• The pathfinder then uses this simplified representation of the map to determine the best path
from the starting point to the desired destination in the map.

The most common forms of simplified representations are :


1) Navigation Meshes;
2) Waypoints.

Navigation Meshes
• A navigation mesh is a set of convex polygons that describe the “walkable ” surface of a 3D
environment.
• Algorithms have been developed to abstract the information required to generate Navigation
Meshes for any given map.
• Navigation Meshes generated by such algorithms are composed of convex polygons which
when assembled together represent the shape of the map analogous to a floor plan.
• The polygons in a mesh have to be convex since this guarantees that the AI agent can move in a
single straight line from any point in one polygon to the center point of any adjacent polygon.
• Each of the convex polygons can then be used as nodes for a pathfinding algorithm.

Waypoints
• Is a collection of nodes (points of visibility) with links between them.
• Travelling from one waypoint to another is a sub problem with a simple solution.

2 PKasyoka
• All places reachable from waypoints should be reachable from any waypoint by travelling along
one or more other waypoints, thus creating a grid or path that the AI agent can walk on.
• If an AI agent wants to get from A to B it walks to the closest waypoint seen from position A,
then uses a pre-calculated route to walk to the waypoint closest to position B and then tries to
find its path from there.
• Usually the designer manually places these waypoint nodes in a map to get the most efficient
representation.
• This system has the benefit of representing the map with the least amount of nodes for the
pathfinder to deal with. Like Navigation Meshes,
• Waypoints are useful for creating efficient obstacle free pathways through static maps but are
unable to deal with dynamic worlds (or worlds that change).

Figure 1

Table 1

3 PKasyoka
Figure 1 shows how a simple scene might be represented with waypoints.
Table 1 shows the routing information contained within each waypoint.
The path from (A) to (B) can be executed as follows:
• A straight-line path from (A) to the nearest waypoint is calculated (P1) then a straight-line path
is calculated from (B) to the nearest waypoint (P2).
• These waypoints are 6 and 3 respectively. Then looking at the linking information, a
pathfinding system will find the path as follows { P1, waypoint 6, waypoint 5, waypoint 2,
waypoint 3, P2 }

Graph Theory
• Pathfinding algorithms can be used once the geometry of a game world has been encoded as a
map and pre-processed to produce either a Navigation Mesh or a set of Waypoints.
• Since the polygons in the navigation mesh and the points in the waypoint system are all
connected in some way they are like points or nodes in a graph.
• So all the pathfinding algorithm has to do is transverse the graph until it finds the endpoint it is
looking for. Conceptually, a graph G is composed of two sets, and can be written as G = (V,E)
where:
V – Vertices: A set of discreet points in n-space, but this usually corresponds to a 3D map.
E – Edges: A set of connections between the vertices, which can be either directed or not

Pathfinding
• In many game designs AI is about moving agents/bots around in a virtual world.
• It is of no use to develop complex systems for high-level decision making if an agent cannot
find its way around a set of obstacles to implement that decision.
• On the other hand if an AI agent can understand how to move around the obstacles in the virtual
world even simple decision-making structures can look impressive.
• Thus the pathfinding system has the responsibility of understanding the possibilities for
movement within the virtual world.
• A pathfinder will define a path through a virtual world to solve a given set of constraints. An
example of a set of constraints might be to find the shortest path to take an agent from its
current position to the target position.

4 PKasyoka
• Pathfinding systems typically use the pre-processed representations of the virtual world as their
search space.

Approaches to Pathfinding
Pathfinding can be divided into two main categories:
a) Undirected and
b) Directed .

Undirected
• This approach is analogous to a rat in a maze running around blindly trying to find a way out.
• The rat spends no time planning a way out and puts all its energy into moving around.
• Thus the rat might never find a way out and so uses most of the time going down dead ends.
• Breadth-first search and Depth-first search respectively, they are well known search algorithms

Directed
• Directed approaches to pathfinding all have one thing in common in that they do not go blindly
through the maze.
• In other words they all have some method of assessing their progress from all the adjacent
nodes before picking one of them.
• This is referred to as assessing the cost of getting to the adjacent node. Typically the cost in
game maps is measured by the distance between the nodes.
• Most of the algorithms used will find a solution to the problem but not always the most efficient
solution i.e. the shortest path.
The main strategies for directed pathfinding algorithms are:

a) Uniform cost search: modifies the search to always choose the lowest cost next node. This
minimises the cost of the path so far, it is optimal and complete, but can be very inefficient.
b) Heuristic search: estimates the cost from the next node to the goal. This cuts the search cost
considerably but it is neither optimal nor complete.
Examples of directed algorithms are:
i. Dijkstra and
ii. A* respectively

5 PKasyoka
• Dijkstra’s algorithm uses the uniform cost strategy to find the optimal path while the A*
algorithm combines both strategies thereby minimizing the total path cost.
• Thus A* returns an optimal path and is generally much more efficient than Dijkstra making it
the backbone behind almost all pathfinding designs in computer games.
• Since A* is the most commonly used algorithm in the pathfinding arena it will be outlined in
more detail later in this report.

A* Pathfinding Algorithm
• A* (pronounced a-star) is a directed algorithm, meaning that it does not blindly search for a
path.
• Instead it assesses the best direction to explore, sometimes backtracking to try alternatives.
• This means that A* will not only find a path between two points (if one exists!) but it will find
the shortest path if one exists and do so relatively quickly.

Limitations Of A*
• A* requires a large amount of CPU resources, if there are many nodes to search through as is
the case in large maps which are becoming popular in the newer games.
• In sequential programs this may cause a slight delay in the game.
• This delay is compounded if A* is searching for paths for multiple AI agents and/or when the
agent has to move from one side of the map to the other.
• This drain on CPU resources may cause the game to freeze until the optimal path is found.

Machine Learning
• A possible solution to Limitations Of A* is to use machine learning to assimilate pathfinding
behaviour.
• Machine learning if done correctly, allows generalisation for situations that did not crop up in
the training process.
• It should also allow the game development team to develop the AI component concurrently with
the other components of the game.

6 PKasyoka
Machine learning techniques can be broken into the following three groups:
a) Optimisation :
• Learning by optimisation involves parameritising the desired behaviour of the AI agent and
presenting a performance measure for this desired behaviour.
• Genetic Algorithms are the most commonly used technique for optimisation.
b) Training:
• Learning by training involves presenting the AI agent with a set of input vectors and then
comparing the output from the AI agent to the desired output.
• The difference between the two outputs is known as the error.
• The training involves modifying the internal state of the agent to minimise this error.
c) Imitation:
• Learning by imitation involves letting the AI agent observe how a human player plays the game.
• The AI agent then attempts to imitate what it has observed.

Learning Algorithms
There are two machine learning approaches that have been used in commercial computer games with
some degree of success.
• Artificial Neural Networks (ANNs)
• Genetic Algorithms (GAs).

Neural Networks
• An artificial neural network is an information-processing system that has certain performance
characteristics in common with biological neural networks.
• An artificial neural network is characterised by (a) the pattern of connections between neurons
i.e. the architecture, (b) the method of determining the weights on the connections
(Training and Learning algorithm) (c) the activation function.

7 PKasyoka
Genetic Algorithms
• The genetic algorithm, described in works by filling a system with organisms each with
randomly selected genes that control how the organism behaves in the system.
• Then a fitness function is applied to each organism to find the two fittest organisms for this
system.
• These two organisms then each contribute some of their genes to a new organism, their
offspring, which is then added to the population.
• The fitness function depends on the problem, but in any case, it is a function that takes an
individual as an input and returns a real number as an output.

How Learning Algorithms Can Solve Pathfinding Problems


The main problems associated with real-time pathfinding are:
• Handling dynamic objects
• Using up too many resources especially on game consoles, which have limited memory
• Leave the AI until the end of the development process
Learning algorithms offer the possibility of a general pathfinding Application Programming Interface
(API) that would allow an agent to learn how to find its way around the game world.

Dynamic problem:
• Having continuous real-time sensors the AI agent should be able to learn to use this information
via a neural network to steer around obstacles and adjust to a changing environment.
• The agent should be able to make reasonable decisions when it encounters a situation that did
not arise during training.
• Genetic algorithms can be used to train the neural network online as new elements are added to
the game.

8 PKasyoka
Resource problem
• Neural networks do not require large amounts of memory and can handle continuous inputs in
real-time as the data processing mainly involves addition and multiplication which are among
the fastest processes a computer can perform.

Assignment:
• Discuss two common forms of simplified representations of a typical world geometry as used in
computer game

REFERENCES

• Cain, Timothy, “Practical Optimizations for A*”, AI Game Programming Wisdom, Charles
River Media, 2002
• Graham, Ross; McCabe, Hugh; and Sheridan, Stephen (2003) "Pathfinding in Computer
Games," The ITB Journal: Vol. 4: Iss. 2, Article 6.doi:10.21427/D7ZQ9J

9 PKasyoka

You might also like