calculates the shortest route in 4 directions