Skip to content

Commit

Permalink
Fix NaN due to division by zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
asvitkine committed Jul 5, 2024
1 parent 63148a8 commit 06b6f12
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions game-app/game-core/src/main/java/games/strategy/net/IpFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* [email protected] Utility class for finding the local ip address of a machine
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 06b6f12

Please sign in to comment.