setting up  the pathfinding algorithm