implemented 1 by 1 path finding algorithm