Implementation of the A* search algorithm.