Project 2
Student id: h15
To select another student or project, return to the Project Page.
Title: A* Pathfinding Algorithm
Author: Tammy Huynh
Date:
Table of Contents
Chapter 1: Introduction
-A to B
-Connect The Dots: Graphs
-Bro #1: Dijkstra’s Algorithm
-Bro #2: Best-First Search Algorithm
-A* Is Born
-Weighted Tiles
-Suboptimal Path
-Comparisons
Chapter 1: Introduction
-A to B
-Connect The Dots: Graphs
A to B
Okay, so I have this dilemma: How do I get from A to B as quickly as possible?



Connect The Dots: Graphs
A graph is a collection of nodes or vertices, connected by edges. A square has 4 nodes and 4 edges:





Chapter 2: Meet the Algorithms
-Bro #1: Dijkstra’s Algorithm
-Bro #2: Best-First Search Algorithm
-A* Is Born
Bro #1: Dijkstra’s Algorithm
Dijkstra's Algorithm is like a dog who's slow but very thorough in his search.

Now, if we haven’t reached the nodes yet, how do we know that information? Ah, that’s a good point. Really, we don’t know, so we will initialize all of the nodes, except A, with an infinite distance and say that they have no parent. Giving them an infinite distance may seem weird, but this ensures that we update it the first time we find a path to it (since the cost we find to it will definitely be less than infinity).

(1) Find an unvisited node
closest to our current node
(2) Go to that node and mark it as visited.
This means that we have found the shortest path from A to the current node.
Thus, if the new node is our goal, we can stop the algorithm. The steps
following it are to ensure that we also get the shortest path from A to its
neighbors. But really, if we reached the end, we don’t care about them anymore.
But if this wasn’t the goal, go on to 3)
(3) Look at all of the neighbors
of this new node. If the cost of the path going from A to the neighbor in which
we pass through the current node is shorter than any previous distance to the
neighbor, update it with the shorter path (cost and parent). Another way to look
at this is that the cost from A to the particular neighbor we’re looking at is
the cost from A to the current tile + the cost of the current tile to the
particular neighbor.













Bro #2: Best-First Search Algorithm
Best-First Search is like a speedy bunny who is so focuses on the end goal that he ends up ignoring potentially better paths.

In Best-First, the heuristic is the estimated cost from the current node to the end node B. There are various ways to get the heuristic value, but the most common way is with the Manhattan method. This method counts the distance traversed only horizontally and vertically to get to the end, ignoring any diagonal movement and obstacles. This distance, also called the taxicab distance, is named after the New York borough Manhattan, which is known for its grid-like streets.








A* Is Born


He takes into account both the cost from the start to the current node and the cost from the current node to the end.
F = G + H
Where
G = cost from the start to the current node
H = estimated cost from the current node to the end
G will be calculated the same way as in Dijkstra’s while H will be calculated the same way as in Best-First with the Manhattan distance. Remember, we say H, the heuristic value, is an estimate because there are many things that it doesn’t take into account, like obstacles. We’ll go back to the steps outlined for Dijkstra’s, except we will update it so that we inspect the nodes with the lowest F cost first.
To begin the algorithm, we place A on the visited list and then repeat the following steps until we run out of nodes to visit:
(1) Find an unvisited node with the lowest F cost.
(2) Go to that node and
mark it as visited. If the new node is our goal, stop the algorithm; else, go on
to 3)
(3) Look at all of the neighbors of this new node. If the G cost of
the path going from A to the neighbor in which we pass through the current node
is shorter than any previous distance to the neighbor, update it with the
shorter path (cost and parent).








Chapter 3: More on A*
-Weighted Tiles
-Suboptimal Path
-Comparisons
Weighted Tiles
Let’s say we decide to add a river to our map. We can cross it, but it takes a lot of effort to, so we decide to add an extra value of 30 on top of the normal 10 for going horizontal or 14 to go diagonal. This will make the algorithm skirt around the river to find a less costly way to get to B.


Suboptimal Path
Hey, A*! You’re doing so well! What if we add to this river? Let’s go back to where it’ll change. At some point, we’ll get here:




Comparison
Besides that occasional mishap, which can be fixed with different implementations, A* is a good combination of Dijkstra’s and Best-First. Let’s do a comparison of the algorithms. Below is a run-through of the three algorithms on a large map. It’s important to note that diagonals are not counted as neighbors here, so we can only move directly horizontally or vertically. Dijkstra’s spends more time exploring the map and gets the correct shortest path. Meanwhile, Best-First, doesn’t spend as much time exploring but also doesn’t find the shortest path. Instead, he bumps into the wall before correcting himself. Lastly, A* spends only a bit of time exploring and finds the correct path.
End: Expanding Horizons
There’s quite a lot you can do with pathfinding! In this post, I showed you three pathfinding algorithms: Dijkstra’s, Best-First, and A*. We focused on A* because it combines the efficiency of Dijkstra’s with the speed of Best-First. A* is the most popular pathfinding algorithm in game development. If you’re interested in learning more, start checking out how weights can affect your units’ movements. For example, you can add them to particular terrain tiles like we did above with the river or subtract them from tiles acting as stairs/teleporters, which take you closer to the target. Also, your tiles don’t have to be squares. You can use hexagonal shapes, and the algorithms still work the same. That actually makes the math easier since the distance to each neighbor is equal. Additionally, it’ll be good to consider movement restrictions, such as those dealing with cutting corners or units that takes[i.n.] up more than one tile space. I recommend checking out the sources below too. RedBlobGames[i.n.] provides great interactive visuals on the algorithms. The author doesn’t use diagonal neighbors in his examples (so only a max of four neighbors for a node), but don’t be confused! The algorithms work the same way!
That’s all for now! Happy pathfinding!
Sources[i.n.]
Patrick Lester (2005, Jul 18) A* Pathfinding for Beginners. Retrieved fromw http://www.policyalmanac.org/games/aStarTutorial.htm.
Amit Patel (2016, Jun). Introduction to A*. Retrieved from http://www.redblobgames.com/pathfinding/a-star/introduction.html.
Kevin Thompson (n.d.). Taxicab Geometry. Retrieved from http://taxicabgeometry.altervista.org/general/definitions.html.
hakimio (2012, Feb 23). Hexagonal Grid: Path-finding Using A* Algorithm. Retrieved from https://tbswithunity3d.wordpress.com/2012/02/23/hexagonal-grid-path-finding-using-a-algorithm/
Peer review
The post addresses the topic of path finding algorithms in mathematics, and by extension, computer science. Its audience seems best fit to be those who have an understanding of some fundamental concepts from these disciplines, but are seeking a friendly introduction to path finding algorithms. (specifically Dijkstra's, Best-First, and A*)
The structure and style of the post is exceptionally well thought through and does a very good job of giving life to a potentially drab topic. Specifically the modular structure is effective at building an inexperienced reader's knowledge, while the anthropomorphizing of the different algorithms allows their 'personalities' to give insight into how they might be used in separate circumstances.
The current flow of the article is in a good place (as touched on above), however I think the arc could be further developed to emphasize that A* is the focal point of the document. It feels as though it is being discussed as an equal to the other two approaches, and if it weren't for textual clues such as 'bro #1' and 'bro #2' when referring to the other two algorithms, its differentiation in importance in the document is not immediately obvious. I think this could be improved in two ways. At present, the exposition of the document doesn't hint that A* is of greater focus than the other two algorithms -- other than it chronologically following the other two. Providing some explicit discussion of the 'roadmap' might allow for the reader to better understand why we are building to A*. Secondly, the underlying xml structure could be reworked to drive this home if Dijkstra's and BF were included in the 'background' section rather than in the 'answer' section.
Overall it appears that the nuts and bolts of the genre are being properly adhered to, and stylistically I imagine the cartoons will add the glue to help make accessible the details behind the topics. Given the primitive state of the document, it is difficult in a few passages to be sure if some confusion I experienced was due to sections that have yet to be proofread, or if better explanations should be developed. I highlighted a few areas with notes that could benefit if the latter is the case. Lastly, I noticed you aren't using the 'important_idea' tag. It doesn't seem to take away from the work, however you might find it useful for areas in which you are driving home the differences between various path-finding implementations.
Instructor Note
Wow, this is a really cool project. I can tell you put a *ton* of work into it. It is fascinating to see the vast differences between your post, which relies primarily on visuals, and other group members, who focus more on textual tools like analogies, etc. You really went above and beyond here and I appreciate that level of commitment. One issue, though, is that your document is not actually valid according to the schema. The main reasons for this are that you have a bunch of empty "hr" elements. I'm not sure what these are meant to be and I don't remember talking about them with your group. the second is that you use section headers inside of some areas like important ideas, etc., which is technically not allowed by the schema (though this is my fault, since section header should be global). I see from your design entry that the hr tag was a formatting issue--you wanted a horizontal line. It is interesting that these formatting issues didn't present themselves when your group met about the format and changes to the schema. Overall, though, this is really excellent work and a model project.