I'm no expert, but check out the A* algorithm, you can find more info on it here:

http://terraqueous.f2o.org/dgdev/viewtopic.php?t=348