|
Welcome to "A* Pathfinding" the second set in our AI Programming series. This entry in the series continues from the topics discussed in "Behavior Systems" by exploring the world of pathfinding focusing primarily on the A* pathfinding algorithm. Pathfinding is the process of plotting out the shortest or most efficient path between two given points. A* (pronounced ay-star) is a particular pathfinding search algorithm used in many software applications for calculating this path. In determining the path, the A* algorithm takes a "distance-to-goal + path-cost" score into consideration.
Note: The code presented in A* Pathfinding builds upon the code created in the Behavior Systems video. For the sake of convenience, this original code is overviewed in A* Pathfinding. However, if you are not yet comfortable with the basics of programming simple actor movement, you would do well to start with Behavior Systems first, as the code from the first volume is NOT included here in A* Pathfinding.
|
Learn through the creation of five unique behaviors
The goal of this video is to provide an introductory insight into the key concepts behind pathfinding, with special focus on using A*, and to provide a clear demonstration of how the algorithm works. To handle this task effectively, the lecture is divided into 3 fundamental areas:
- Building navigable node graphs
- Navigating a node graph using the A* algorithm
- Practical application of A* navigation in a simple game demo
|
|
Pathfinding is really just a way to tell an AI system to find the most efficient way to navigate from one point to another. However, before you can achieve this, you need to establish the points themselves. In pathfinding systems, these points are generally called "nodes." These nodes are all connected together in some fashion to create a network, which we refer to as a "node graph." You can think of this node graph as a series of interconnected waypoints. The AI search algorithm will navigate throughout these points to move from one node to another, by way of the most efficient path of neighboring nodes.
To facilitate experimentation and interaction while working with pathfinding algorithms, we begin our lecture by teaching you how to write a visual node graph editor. This editor allows a user to quickly and intuitively place nodes in a 2D field and connect them together to form a final node graph. These node graphs can also be edited within the application, with nodes being repositioned or reconnected to form an infinite variety of patterns and navigation possibilities. The editor also supports loading and saving of node graphs, allowing for maximum flexibility when testing out various pathfinding algorithms.
The benefit is that once we get into coding the pathfinding behavior, the completed node graph editor can be used as a tool to quickly test a variety of different node layouts. This helps you not only to see how the pathfinding system is working, but also provides an easy way to see where improvements or tweaks to the system can be made to customize the behavior, by watching how the AI actor moves from the start point to the goal.
|
|
Once you have the knowledge and means to create your own navigable node graphs, it's time to take a look at navigating them through pathfinding. While the A* algorithm is the primary focus of this video, we build up to it by discussing some of the more fundamental pathfinding algorithms from which A* is derived. Starting with breadth-first and depth-first navigation, we quickly take you through Dijkstra's algorithm, and finally up to A*.
You'll see how weighted graphs are used by A* to determine path efficiency from one node to the next, and how edge relaxation can be employed to stop excess calculations along inefficient paths. We also show you how A* uses an estimation calculation known the heuristic, which speeds up calculation by taking an estimate of the distance from any given point to the final goal node, and using that estimate as a basis for comparison.
|
|
To complete the lecture, we take everything learned up to this point and combine it with the behavior system concepts explored in the first part of the series, "Behavior Systems." In doing this, we create a simple game demo, in which we have a state-based AI-driven Enemy actor. The Enemy actor begins the demo in a "Wander" state, meaning that it is using the A* search algorithm, along with a series of randomly selected goal nodes, to patrol the level, following a node graph designed to chart out out the level's navigable areas.
Surrounding the Enemy actor is a visible radius, which serves as the limit of the Enemy's visual range. If the player enters this radius, either actively or by standing too close to the Enemy's path while in the Wander state, the Enemy switches to a "Seek Player" state, in which the Enemy actor begins using the A* algorithm to find the best path to the player. This path is constantly updating based on the player's position, giving the impression that the Enemy is chasing the player around the level, while still navigating throughout the level's underlying node graph. This pursuit will continue until the enemy comes into contact with the player.
Once the Enemy actor touches the player, we assume that the Enemy is heavily damaged by the contact, and it switches to a new state called "Seek Health." In this state, the behavior of the AI changes, as it now uses the A* algorithm to find the best path to a stationary health pickup. Once the health pickup is retrieved, the Enemy actor reenters the Wander state, and the whole cycle begins again.
Using this example, we can see how the combination of a state-based behavior system, with pathfinding navigation, can give the illusion of complex AI with sophisticated decision-making capabilities and believable reactions.
|
|
|
|
Watch The 'AI Programming: Pathfinding with A*' Intro
Sounds Great! - but I still have questions...
It is assumed that you have a solid foundation in C# and XNA before beginning these videos. If you are just starting out with C# and XNA, the XNA Xtreme 101 Bundle would be a good primer before jumping into these videos
You NEED the following:
- A computer with the Windows operating system that supports Visual C# 2008 Express and is capable of running our VTMs.
- A copy of Visual C# 2008 Express. Don’t worry, it’s free.
- XNA Game Studio.
- The XviD codec installed.
- A stable Internet connection, preferably broadband.
The following prerequisites are optional, based on which game assets you want to create yourself,
and whether you want to play the game on an Xbox 360.
- Some sort of paint software
- Sound recording/editing software
- Xbox 360 Controller for your PC (This is not required, but HIGHLY recommended)
- An Xbox 360 with hard drive and subscription to the Creator’s Club
No, the content will not play on a regular DVD player, it is intended for use in a PC that has a DVD-ROM drive.
You may view the video files with the XviD codec, which can be downloaded for free from www.xvid.org.
In order to protect our content from illegal distribution and to safeguard
your investment, we have implemented a video watermark system. The
faint video watermark is on some of the videos, and will contain your
name and address. The information on the watermarks will be used as
evidence should the videos be illegally distributed.
Yes, we do, but only your account must be verified through PayPal and your shipping address must be confirmed.
The only forms of payment we accept are credit card and PayPal.
Your DVD's must be custom encoded at our facilities to include your personal watermark.
This process can take anywhere from 1 to 5 business days to complete, though most orders are shipped within 48 hours.
Shipping in the US is approximately $15. This as a production and shipping fee,
helping to cover not only the actual shipment, but also the process of encoding, burning, and printing.
We only ship to the verified billing address. If other arrangements for shipping are required, we will need to verify the new location.
This verification process is in place for your security, and for the security of our content.
|