Skip to content

Commit

Permalink
Change Settings for the Decimals to the Wins and Draw Results and Inc…
Browse files Browse the repository at this point in the history
…rease the Maximum Run Count in the Battle-Simulator (2.6.14513) triplea-game#11980

Signed-off-by: df414rv <[email protected]>
  • Loading branch information
df414rv committed Nov 7, 2023
1 parent 2480d2b commit 71ff9e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@
import org.triplea.swing.jpanel.GridBagConstraintsFill;

@Slf4j
class BattleCalculatorPanel extends JPanel {
public class BattleCalculatorPanel extends JPanel {
private static final long serialVersionUID = -3559687618320469183L;
private static final String NO_EFFECTS = "*None*";
public static final int MAX_NUMBER_OF_RUNS = 100_000;
private final JLabel attackerWin = new JLabel();
private final JLabel defenderWin = new JLabel();
private final JLabel draw = new JLabel();
Expand Down Expand Up @@ -150,9 +151,9 @@ class BattleCalculatorPanel extends JPanel {
attackerCombo.setRenderer(new PlayerRenderer());
defendingUnitsPanel = new PlayerUnitsPanel(data, uiContext, true);
attackingUnitsPanel = new PlayerUnitsPanel(data, uiContext, false);
numRuns.setColumns(4);
numRuns.setColumns(5);
numRuns.setMin(1);
numRuns.setMax(20000);
numRuns.setMax(MAX_NUMBER_OF_RUNS);

final int simulationCount =
Properties.getLowLuck(data.getProperties())
Expand Down Expand Up @@ -616,9 +617,11 @@ private void updateStats() {
// For "unrestricted" average methods, this cannot happen as we ensure that at least 1 round
// is simulated. However, the ...IfAbcWon() methods restrict that set of results which might
// become empty. In this case we display N/A (not applicable) instead of NaN (not a number).
attackerWin.setText(formatPercentage(results.get().getAttackerWinPercent()));
defenderWin.setText(formatPercentage(results.get().getDefenderWinPercent()));
draw.setText(formatPercentage(results.get().getDrawPercent()));
attackerWin.setText(
formatPercentage(results.get().getAttackerWinPercent(), numRuns.getValue()));
defenderWin.setText(
formatPercentage(results.get().getDefenderWinPercent(), numRuns.getValue()));
draw.setText(formatPercentage(results.get().getDrawPercent(), numRuns.getValue()));
final boolean isLand = isLand();
final List<Unit> mainCombatAttackers =
CollectionUtils.getMatches(
Expand Down Expand Up @@ -676,8 +679,14 @@ private Territory findPotentialBattleSite() {
return location;
}

private static String formatPercentage(final double percentage) {
return new DecimalFormat("#%.##").format(percentage);
private static String formatPercentage(final double percentage, int numberOfRounds) {
if (numberOfRounds < 10_000) {
return new DecimalFormat("0%.##").format(percentage);
} else if (numberOfRounds < 100_000) {
return new DecimalFormat("0%.0#").format(percentage);
} else {
return new DecimalFormat("0%.00").format(percentage);
}
}

private static String formatValue(final double value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import games.strategy.engine.framework.lookandfeel.LookAndFeel;
import games.strategy.triplea.UrlConstants;
import games.strategy.triplea.odds.calculator.BattleCalculatorPanel;
import games.strategy.triplea.settings.lobby.LobbySelectionViewFactory;
import java.util.Collection;
import javax.swing.JComponent;
Expand Down Expand Up @@ -72,7 +73,10 @@ public SelectionComponent<JComponent> newSelectionComponent() {
"Default battle simulation count in dice games") {
@Override
public SelectionComponent<JComponent> newSelectionComponent() {
return intValueRange(ClientSetting.battleCalcSimulationCountDice, 10, 100000);
return intValueRange(
ClientSetting.battleCalcSimulationCountDice,
10,
BattleCalculatorPanel.MAX_NUMBER_OF_RUNS);
}
},

Expand Down

0 comments on commit 71ff9e3

Please sign in to comment.