/** * Evaluate a potential cashin mission for a given unit and path. * * @param aiUnit The <code>AIUnit</code> to do the mission. * @param path A <code>PathNode</code> to take to the target. * @return A score for the proposed mission. */ public static int scorePath(AIUnit aiUnit, PathNode path) { Location loc; if (path == null || (loc = extractTarget(aiUnit, path)) == null || (loc instanceof Colony && invalidFullColonyReason(aiUnit, loc.getColony()) != null)) return Integer.MIN_VALUE; return aiUnit.getUnit().getTreasureAmount() / (path.getTotalTurns() + 1); }
/** * Extract a valid target for this mission from a path. * * @param aiUnit A <code>AIUnit</code> to perform the mission. * @param path A <code>PathNode</code> to extract a target from, (uses the unit location if null). * @return A target for this mission, or null if none found. */ public static Location extractTarget(AIUnit aiUnit, PathNode path) { if (path == null) return null; final Location loc = path.getLastNode().getLocation(); Colony colony = loc.getColony(); return (loc instanceof Europe && invalidReason(aiUnit, loc) == null) ? loc : (colony != null && invalidReason(aiUnit, colony) == null) ? colony : null; }