private int GetDistanceFromGoal(TravelWorld world, int currentLoc, int goal, out bool realDistance) { if (currentLoc == goal) { realDistance = true; return(0); } var path = world.findCheapestCleartPath(currentLoc, goal); if (path != null) { realDistance = true; return(path.Count); } else { realDistance = false; path = world.findCheapestPath(currentLoc, goal); if (path == null) { return(int.MaxValue); } else { return(path.Count); } } }