} /** * Select a new destination for the pirate. * @param pirate free sea pirate */ private void selectDestination(ISeaPirate pirate) { Point2D destination; if (pirate instanceof INonFreeSeaPirate && ((INonFreeSeaPirate) pirate).roamingNearCity().isPresent()) { ICity city = ((INonFreeSeaPirate) pirate).roamingNearCity().get(); destination = mapService.getRandomPointAtSeaNear(city.getCoordinates()); } else { destination = mapService.getLocationAtOtherEndOfMap(pirate.getShip().getLocation()); } // make sure that the source of the pirate location is in the graph Point2D adjustedDestination = aStarHeuristicProvider.findClosest(destination); aStarHeuristicProvider.addTargetNodeToHeuristic(adjustedDestination); logger.debug("Source point of pirate is {}", pirate.getShip().getLocation()); seafaringService.travelNotBetweenCities(pirate.getShip(), adjustedDestination); }