When You Wish Upon A *
The A* (astar) algorithm will find a path between two nodes in a graph. It uses a cost function f(n) to estimate how close a node is to the goal select what nodes to explore for a way to the goal. The cost function is the sum of two parts, f(n) = g(n) + f(n). Algorithm g(n) is the cost to get from the start to node n.
 h(n) is a guess of how costly it will go from the node n to the goal node.
 f(n) is g(n)+h(n). The lower this is the better chance that the node is on or close to the final path so we should explore the nodes with the lowest f(n) first.
 Open is a list of all the nodes that we have noticed but have not explored yet. We have calculated f(n) on it and when we are looking for the next node to check we take the one from the open list with the lowest f(n) value.
 Closed list a list with all the nodes we have explored already. That is we have calculated f() for all nodes it is linked to.
 Let P be starting node.
 Assign f,g and h values to P.
 Add P to the open list.
 Let B be the best node from the open list. Best is the node with the lowest f value.
 If there is no node in B, quit and there is no path.
 If B is the goal node, then quit and return the path.
 Loop all linked nodes to B and for each node C.
 Assign f,g and h values to P.
 If C is in open or closed list check
 if the new path is better (lower f) update the path
 else
 Add C to open list.
 Move B to the closed list.
Reference
