use of games.strategy.triplea.delegate.GameDelegateBridge in project triplea by triplea-game.
the class OddsCalculator method calculate.
private AggregateResults calculate(final int count) {
isRunning = true;
final long start = System.currentTimeMillis();
final AggregateResults aggregateResults = new AggregateResults(count);
final BattleTracker battleTracker = new BattleTracker();
// CasualtySortingCaching can cause issues if there is more than 1 one battle being calced at the same time (like if
// the AI and a human
// are both using the calc)
// TODO: first, see how much it actually speeds stuff up by, and if it does make a difference then convert it to a
// per-thread, per-calc
// caching
final List<Unit> attackerOrderOfLosses = OrderOfLossesInputPanel.getUnitListByOrderOfLoss(this.attackerOrderOfLosses, attackingUnits, gameData);
final List<Unit> defenderOrderOfLosses = OrderOfLossesInputPanel.getUnitListByOrderOfLoss(this.defenderOrderOfLosses, defendingUnits, gameData);
for (int i = 0; i < count && !cancelled; i++) {
final CompositeChange allChanges = new CompositeChange();
final DummyDelegateBridge bridge1 = new DummyDelegateBridge(attacker, gameData, allChanges, attackerOrderOfLosses, defenderOrderOfLosses, keepOneAttackingLandUnit, retreatAfterRound, retreatAfterXUnitsLeft, retreatWhenOnlyAirLeft);
final GameDelegateBridge bridge = new GameDelegateBridge(bridge1);
final MustFightBattle battle = new MustFightBattle(location, attacker, gameData, battleTracker);
battle.setHeadless(true);
battle.setUnits(defendingUnits, attackingUnits, bombardingUnits, (amphibious ? attackingUnits : new ArrayList<>()), defender, territoryEffects);
bridge1.setBattle(battle);
battle.fight(bridge);
aggregateResults.addResult(new BattleResults(battle, gameData));
// restore the game to its original state
gameData.performChange(allChanges.invert());
battleTracker.clear();
battleTracker.clearBattleRecords();
}
aggregateResults.setTime(System.currentTimeMillis() - start);
isRunning = false;
cancelled = false;
return aggregateResults;
}
Aggregations