//
// Tucker Balch's A* in pseudo-code
//


Functions and variables:

	node.G   : the cost of the optimal path from the initial state to node
	H(X,Y)   : heuristic underestimate of the cost from X to Y
	push(X)  : saves node X in a priority queue sorted by cost
	pop(X)   : removes the lowest-cost node from the queue
	initial  : initial state
	goal     : goal state

algorithm:

	for all states i
		visited[i] = NOT_VISITED;
	initial.G = 0;
	initial.cost = initial.G + H(initial,goal);
	push(initial);
	pop(current);
	while (current != goal && current != null)
		{
		for each possible action i from current
			{
			if (visited[i] != VISITED)
				{
				visited[i] = VISITED;
				i.backpointer = current; // to remember trajectory
				i.G = current.G + 1; // or sqrt(2) if diagonal
				i.cost = i.G + H(i,goal);
				push(i)
				}
			}
		pop(current);
		}
	if (current == null)
		ERROR, no solution
	if (current == goal)
		success!
		find path by following backpointers