A* (star) Algorithm
http://web.mit.edu/eranki/www/tutorials/search/
It's the leading pathfinding algorithm! Not a BFS nor a DFS, it's a combination of Dijkstra's algorithm and best fit.
The general idea is :
f = g + h
f is the cost function of the node.
g if the cost it took to get the target node, pretty much the paths it passed by from the start node.
h is the cost to get to the target node.
Following is the pseudo code:
while the open list is not empty
find the node with the least f on the open list, call it "q"
pop q off the open list
generate q's 8 successors and set their parents to q
for each successor
if successor is the goal, stop the search
successor.g = q.g + distance between successor and q
successor.h = distance from goal to successor
successor.f = successor.g + successor.h
if a node with the same position as successor is in the OPEN list \
which has a lower f than successor, skip this successor
if a node with the same position as successor is in the CLOSED list \
which has a lower f than successor, skip this successor
otherwise, add the node to the open list
end
push q on the closed list
end