You are on page 1of 2

What is pathfinding? Pathfinding is the operation of calculating and creating a path for AI to follow. Whether it be movement paths, story paths, or even behavior paths. All it entails is the calculation from one point to another by an algorithm, usually A*, to create the most optimal path to your destination. This operation is calculated before the execution of its results, making it a preprocessed operation, where obstacle avoidance is real-time.

What is a path? A path is any sequence of steps that once followed will lead an AI to its final destination. Usually, very straight forward in the idea of the movement from one world point to another according to the path found by the algorithm. However, more complicated AIs could use a path for interacting with the player in dialogue or even the narrative in the story like the Mass Effect series.

What is a node? A node is point along the path. Most literally a point in world space, but can be more abstract like plot points or decision points. But in its most simplistic form, it's a point that a path can follow towards its destination. There are many different characteristics that can be added to nodes like travel weight, navigability, or even distance from the start and finish points of any particular path.

How Does Dijkstra's Algorithm work?

Dijkstra’s Algorithm is the predecessor to A* and was a game changer in terms of making

pathfinding more efficient. The two ways that it made more efficient paths is by giving a value to nodes

and the advancement of checking each neighbor of every child node and gradually spreading out until the end is reached. The algorithm takes the best features of it's predecessors: breadth-first and depth- first. This use of the best from each gives Dijkstra’s a more efficient search pattern as it checks each child node of each sibling and checking the neighbors around each child until the end goal is found.

But that's not all, in addition, Dijkstra’s gives nodes numerical values so that you can help direct

the flow of a path. For example, if you want an AI to travel along a road and not just walk through the swamp, you can give the swamp a higher traversing value so it becomes more costly to walk across, thus insuring that the most efficient path is one that has the lowest traversing value from start to finish. This gives so much more power to pathfinding by using these advancements.

However, Dijkstra’s does have some short comings which lead to the development of A*. The

biggest issue was that, since Dijkstra's does not know where the end of the path is, it just blooms out in all directions from the starting point and once it finds the end, it calculates the lowest travel cost from the start to the end. This is very inefficient when compared to A*, because A* uses the distance from the goal in its calculations to give a more efficient calculation because it knows which direction will close the gap from the start to the finish.

What does “F = G + H” mean?

This is the equation that makes A* more efficient at calculating a path than Dijkstra's. This

equation means: “The travel value of a node is equal to its distance away from the starting point plus its distance way from the ending point.” And that's what makes A* the industry standard, the ability to

know the direction of the end point and use that to direct the focus of the search towards the end point rather than in an ever blooming formation from the start. What is G? G is the distance from the starting point to the node's position. It is calculated by using trigonometry. Because the most common node, geometrically, is a square, you can use the principals of isosceles triangles to calculate distance in any direction. Traveling in the cardinal directions usually cost 10 while diagonal directions cost 14 because of the length of the hypotenuse of isosceles triangles

by using the Pythagorean theorem. This ensures that the distance from any point to another follows the mathematically shortest path because it is the path with the smallest G cost, by using diagonals instead of two cardinal positions in coordination to make a diagonal.

What is H? H is the value that made Dijkstra's not as efficient as A*. Similar to G, it is a value that is calculated by looking at the distance from the end to that particular node. But this is where A* algorithms can differ. Because, there are many ways of calculating the H cost of any particular node. My preferred method is to use the formula “14x + 10(y-x) = H or 14y + 10(x-y) = H”. This allows the algorithm to move diagonally until it reaches the same cardinal line as the end point. This ensures that algorithm knows the most efficient path towards the end point and uses that to calculate the H value of every node when calculating a path. This ensures that the F cost, the combination of G and H, reflects any particular nodes true value when trying to calculate the most efficient path from any two nodes.

by using the Pythagorean theorem. This ensures that the distance from any point to another follows

Why does this mean A* solves the problem of pathfinding? Pathfinding is the process of finding the shortest path between two points. If you know where you are starting from and where you are going to finish, then all you have to do is calculate the shortest

path. You don't have to worry about if you are “hopefully” moving towards the end point because you

know where you are heading. But this does not mean that A* is perfect. Like how I use a particular formula to calculate H, there are many other methods and formulas to calculate for H or the addition of travel costs and so forth that can be used to complicate and be improved with different methods.