From: "Enrico Weigelt, metux IT consult" <enrico.weig...@gr13.net>

---
 src/net/sf/freecol/common/model/Unit.java     | 25 ++++++++++++-------------
 src/net/sf/freecol/server/ai/REFAIPlayer.java |  7 +++++--
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/net/sf/freecol/common/model/Unit.java 
b/src/net/sf/freecol/common/model/Unit.java
index 737c629ea18..d20ac2928f6 100644
--- a/src/net/sf/freecol/common/model/Unit.java
+++ b/src/net/sf/freecol/common/model/Unit.java
@@ -2870,20 +2870,19 @@ public class Unit extends GoodsLocation
      * @return The nearest {@code Colony}, or null if none found.
      */
     public Colony getClosestColony(List<Colony> colonies) {
-        return getClosestColony(colonies.stream());
-    }
+        Colony best_colony = null;
+        int best_turns = 0;
 
-    /**
-     * Get the colony that can be reached by this unit in the least number
-     * of turns.
-     *
-     * @param colonies A stream of {@code Colony}s.
-     * @return The nearest {@code Colony}, or null if none found.
-     */
-    public Colony getClosestColony(Stream<Colony> colonies) {
-        final Comparator<Colony> comp = cachingIntComparator(col ->
-            (col == null) ? MANY_TURNS-1 : this.getTurnsToReach(col));
-        return minimize(concat(Stream.of((Colony)null), colonies), comp);
+        for (Colony c : colonies) {
+            if (c == null) continue;
+            int turns = this.getTurnsToReach(c);
+            if (best_colony == null || turns < best_turns) {
+                best_colony = c;
+                best_turns = turns;
+            }
+        }
+
+        return best_colony;
     }
 
     /**
diff --git a/src/net/sf/freecol/server/ai/REFAIPlayer.java 
b/src/net/sf/freecol/server/ai/REFAIPlayer.java
index 0c73f5bedf3..eb613431d95 100644
--- a/src/net/sf/freecol/server/ai/REFAIPlayer.java
+++ b/src/net/sf/freecol/server/ai/REFAIPlayer.java
@@ -649,8 +649,11 @@ public class REFAIPlayer extends EuropeanAIPlayer {
             }
 
             // Go defend the nearest colony needing defence
-            Colony best = u.getClosestColony(map(getBadlyDefended(),
-                                                 AIColony::getColony));
+            List<Colony> baddef = new ArrayList<>();
+            for (AIColony aic : getBadlyDefended())
+                baddef.add(aic.getColony());
+
+            Colony best = u.getClosestColony(baddef);
             if (best != null
                 && (m = getDefendSettlementMission(aiu, best)) != null) {
                 lb.add(" GO-DEFEND-", best.getName(), " " , m);
-- 
2.11.0.rc0.7.gbe5a750


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to