From 06b6f122c06bfa7eb0b8a45d7209815af660f284 Mon Sep 17 00:00:00 2001 From: asvitkine Date: Fri, 5 Jul 2024 14:18:12 -0400 Subject: [PATCH] Fix NaN due to division by zero. --- .../java/games/strategy/net/IpFinder.java | 27 +++++++++++++++++++ .../ai/pro/util/ProSortMoveOptionsUtils.java | 4 +-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/game-app/game-core/src/main/java/games/strategy/net/IpFinder.java b/game-app/game-core/src/main/java/games/strategy/net/IpFinder.java index d0f05216c63..d23f444e03d 100644 --- a/game-app/game-core/src/main/java/games/strategy/net/IpFinder.java +++ b/game-app/game-core/src/main/java/games/strategy/net/IpFinder.java @@ -8,9 +8,12 @@ import java.net.NetworkInterface; import java.net.SocketException; import java.net.UnknownHostException; +import java.sql.Array; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.stream.Collectors; /** * nekromancer@users.sourceforge.net Utility class for finding the local ip address of a machine @@ -41,7 +44,31 @@ private IpFinder() {} * @return java.net.InetAddress the ip address to use */ public static InetAddress findInetAddress() throws SocketException, UnknownHostException { + for (var x : NetworkInterface.networkInterfaces().collect(Collectors.toList())) { + if (x.inetAddresses().collect(Collectors.toList()).isEmpty()) { + continue; + } + System.err.println(x.getName()); + System.err.println(x.getDisplayName()); + System.err.println(x.isVirtual()); + System.err.println(x.isPointToPoint()); + System.err.println(x.isUp()); + System.err.println(x.getMTU()); + System.err.println(x.supportsMulticast()); + System.err.println(x.getParent()); + System.err.println(x.getHardwareAddress()); + System.err.println(x.getInterfaceAddresses()); + + for (var y : x.inetAddresses().collect(Collectors.toList())) { + System.err.println(x + " / " + y); + System.err.println(y.isLinkLocalAddress()); + System.err.println(y.isAnyLocalAddress()); + System.err.println(y.isMCOrgLocal()); + } + } + return NetworkInterface.networkInterfaces() + .filter(not(x -> x.getDisplayName().contains("VirtualBox Host-Only Ethernet Adapter"))) .map(NetworkInterface::getInetAddresses) .map(Collections::list) .flatMap(Collection::stream) diff --git a/game-app/game-core/src/main/java/games/strategy/triplea/ai/pro/util/ProSortMoveOptionsUtils.java b/game-app/game-core/src/main/java/games/strategy/triplea/ai/pro/util/ProSortMoveOptionsUtils.java index f85a13084a9..9b9dbf35709 100644 --- a/game-app/game-core/src/main/java/games/strategy/triplea/ai/pro/util/ProSortMoveOptionsUtils.java +++ b/game-app/game-core/src/main/java/games/strategy/triplea/ai/pro/util/ProSortMoveOptionsUtils.java @@ -231,11 +231,11 @@ private static double calculateAttackEfficiency( minPower = powerDifference; } } - if (unit.getUnitAttachment().getIsAir()) { minPower *= 10; } - double result = (double) minPower / proData.getUnitValue(unit.getType()); + final double unitValue = proData.getUnitValue(unit.getType()); + final double result = unitValue == 0.0 ? 0.0 : (double) minPower / unitValue; Preconditions.checkState(Double.isFinite(result)); return result; }