A* version. no IDA. Fixed bug in heuristicDistance