Skip to content

Commit

Permalink
Fix division by zero and check for isFinite() to fix comparator issue. (
Browse files Browse the repository at this point in the history
#12697)

* Add check for isFinite() to diagnose comparator issue.

This would verify whether #12693 is caused by non-finite values.

* Fix NaN due to division by zero.

* Uncommit file accidentally committed.
  • Loading branch information
asvitkine authored Jul 5, 2024
1 parent 969993b commit 991e5f0
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package games.strategy.triplea.ai.pro.util;

import com.google.common.base.Preconditions;
import games.strategy.engine.data.GameData;
import games.strategy.engine.data.GamePlayer;
import games.strategy.engine.data.GameState;
Expand Down Expand Up @@ -230,10 +231,12 @@ private static double calculateAttackEfficiency(
minPower = powerDifference;
}
}

if (unit.getUnitAttachment().getIsAir()) {
minPower *= 10;
}
return (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;
}
}

0 comments on commit 991e5f0

Please sign in to comment.