use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class InitializationDelegate method initDestroyerArtillery.
private static void initDestroyerArtillery(final IDelegateBridge bridge) {
final GameData data = bridge.getData();
final boolean addArtilleryAndDestroyers = Properties.getUseDestroyersAndArtillery(data);
if (!isWW2V2(data) && addArtilleryAndDestroyers) {
final CompositeChange change = new CompositeChange();
final ProductionRule artillery = data.getProductionRuleList().getProductionRule("buyArtillery");
final ProductionRule destroyer = data.getProductionRuleList().getProductionRule("buyDestroyer");
final ProductionFrontier frontier = data.getProductionFrontierList().getProductionFrontier("production");
if (artillery != null && !frontier.getRules().contains(artillery)) {
change.add(ChangeFactory.addProductionRule(artillery, frontier));
}
if (destroyer != null && !frontier.getRules().contains(destroyer)) {
change.add(ChangeFactory.addProductionRule(destroyer, frontier));
}
final ProductionRule artilleryIndustrialTechnology = data.getProductionRuleList().getProductionRule("buyArtilleryIndustrialTechnology");
final ProductionRule destroyerIndustrialTechnology = data.getProductionRuleList().getProductionRule("buyDestroyerIndustrialTechnology");
final ProductionFrontier frontierIndustrialTechnology = data.getProductionFrontierList().getProductionFrontier("productionIndustrialTechnology");
if (artilleryIndustrialTechnology != null && !frontierIndustrialTechnology.getRules().contains(artilleryIndustrialTechnology)) {
change.add(ChangeFactory.addProductionRule(artilleryIndustrialTechnology, frontierIndustrialTechnology));
}
if (destroyerIndustrialTechnology != null && !frontierIndustrialTechnology.getRules().contains(destroyerIndustrialTechnology)) {
change.add(ChangeFactory.addProductionRule(destroyerIndustrialTechnology, frontierIndustrialTechnology));
}
if (!change.isEmpty()) {
bridge.getHistoryWriter().startEvent("Adding destroyers and artillery production rules");
bridge.addChange(change);
}
}
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class InitializationDelegate method initShipyards.
private static void initShipyards(final IDelegateBridge bridge) {
final GameData data = bridge.getData();
final boolean useShipyards = Properties.getUseShipyards(data);
if (useShipyards) {
final CompositeChange change = new CompositeChange();
final ProductionFrontier frontierShipyards = data.getProductionFrontierList().getProductionFrontier("productionShipyards");
/*
* Find the productionRules, if the unit is NOT a sea unit, add it to the ShipYards prod rule.
*/
final ProductionFrontier frontierNonShipyards = data.getProductionFrontierList().getProductionFrontier("production");
final Collection<ProductionRule> rules = frontierNonShipyards.getRules();
for (final ProductionRule rule : rules) {
final String ruleName = rule.getName();
final IntegerMap<NamedAttachable> ruleResults = rule.getResults();
final NamedAttachable named = ruleResults.keySet().iterator().next();
if (!(named instanceof UnitType)) {
continue;
}
final UnitType unit = data.getUnitTypeList().getUnitType(named.getName());
final boolean isSea = UnitAttachment.get(unit).getIsSea();
if (!isSea) {
final ProductionRule prodRule = data.getProductionRuleList().getProductionRule(ruleName);
change.add(ChangeFactory.addProductionRule(prodRule, frontierShipyards));
}
}
bridge.getHistoryWriter().startEvent("Adding shipyard production rules - land/air units");
bridge.addChange(change);
}
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class ProTerritoryValueUtils method findEnemyCapitalsAndFactoriesValue.
private static Map<Territory, Double> findEnemyCapitalsAndFactoriesValue(final PlayerID player, final int maxLandMassSize, final List<Territory> territoriesThatCantBeHeld, final List<Territory> territoriesToAttack) {
// Get all enemy factories and capitals (check if most territories have factories and if so remove them)
final GameData data = ProData.getData();
final List<Territory> allTerritories = data.getMap().getTerritories();
final Set<Territory> enemyCapitalsAndFactories = new HashSet<>(CollectionUtils.getMatches(allTerritories, ProMatches.territoryHasInfraFactoryAndIsOwnedByPlayersOrCantBeHeld(player, ProUtils.getPotentialEnemyPlayers(player), territoriesThatCantBeHeld)));
final int numPotentialEnemyTerritories = CollectionUtils.countMatches(allTerritories, Matches.isTerritoryOwnedBy(ProUtils.getPotentialEnemyPlayers(player)));
if (enemyCapitalsAndFactories.size() * 2 >= numPotentialEnemyTerritories) {
enemyCapitalsAndFactories.clear();
}
enemyCapitalsAndFactories.addAll(ProUtils.getLiveEnemyCapitals(data, player));
enemyCapitalsAndFactories.removeAll(territoriesToAttack);
// Find value for each enemy capital and factory
final Map<Territory, Double> enemyCapitalsAndFactoriesMap = new HashMap<>();
for (final Territory t : enemyCapitalsAndFactories) {
// Get factory production if factory
int factoryProduction = 0;
if (ProMatches.territoryHasInfraFactoryAndIsLand().test(t)) {
factoryProduction = TerritoryAttachment.getProduction(t);
}
// Get player production if capital
double playerProduction = 0;
final TerritoryAttachment ta = TerritoryAttachment.get(t);
if (ta != null && ta.isCapital()) {
playerProduction = ProUtils.getPlayerProduction(t.getOwner(), data);
}
// Calculate value
final int isNeutral = t.getOwner().isNull() ? 1 : 0;
final int landMassSize = 1 + data.getMap().getNeighbors(t, 6, ProMatches.territoryCanPotentiallyMoveLandUnits(player, data)).size();
final double value = Math.sqrt(factoryProduction + Math.sqrt(playerProduction)) * 32 / (1 + 3 * isNeutral) * landMassSize / maxLandMassSize;
enemyCapitalsAndFactoriesMap.put(t, value);
}
return enemyCapitalsAndFactoriesMap;
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class ProTerritoryValueUtils method findLandValue.
private static double findLandValue(final Territory t, final PlayerID player, final int maxLandMassSize, final Map<Territory, Double> enemyCapitalsAndFactoriesMap, final List<Territory> territoriesThatCantBeHeld, final List<Territory> territoriesToAttack) {
if (territoriesThatCantBeHeld.contains(t)) {
return 0.0;
}
// Determine value based on enemy factory land distance
final List<Double> values = new ArrayList<>();
final GameData data = ProData.getData();
final Set<Territory> nearbyEnemyCapitalsAndFactories = findNearbyEnemyCapitalsAndFactories(t, enemyCapitalsAndFactoriesMap);
for (final Territory enemyCapitalOrFactory : nearbyEnemyCapitalsAndFactories) {
final int distance = data.getMap().getDistance(t, enemyCapitalOrFactory, ProMatches.territoryCanPotentiallyMoveLandUnits(player, data));
if (distance > 0) {
values.add(enemyCapitalsAndFactoriesMap.get(enemyCapitalOrFactory) / Math.pow(2, distance));
}
}
values.sort(Collections.reverseOrder());
double capitalOrFactoryValue = 0;
for (int i = 0; i < values.size(); i++) {
// Decrease each additional factory value by half
capitalOrFactoryValue += values.get(i) / Math.pow(2, i);
}
// Determine value based on nearby territory production
double nearbyEnemyValue = 0;
final Set<Territory> nearbyTerritories = data.getMap().getNeighbors(t, 2, ProMatches.territoryCanPotentiallyMoveLandUnits(player, data));
final List<Territory> nearbyEnemyTerritories = CollectionUtils.getMatches(nearbyTerritories, ProMatches.territoryIsEnemyOrCantBeHeld(player, data, territoriesThatCantBeHeld));
nearbyEnemyTerritories.removeAll(territoriesToAttack);
for (final Territory nearbyEnemyTerritory : nearbyEnemyTerritories) {
final int distance = data.getMap().getDistance(t, nearbyEnemyTerritory, ProMatches.territoryCanPotentiallyMoveLandUnits(player, data));
if (distance > 0) {
double value = TerritoryAttachment.getProduction(nearbyEnemyTerritory);
if (nearbyEnemyTerritory.getOwner().isNull()) {
// find neutral value
value = findTerritoryAttackValue(player, nearbyEnemyTerritory) / 3;
} else if (ProMatches.territoryIsAlliedLandAndHasNoEnemyNeighbors(player, data).test(nearbyEnemyTerritory)) {
// reduce value for can't hold amphib allied territories
value *= 0.1;
}
if (value > 0) {
nearbyEnemyValue += (value / Math.pow(2, distance));
}
}
}
final int landMassSize = 1 + data.getMap().getNeighbors(t, 6, ProMatches.territoryCanPotentiallyMoveLandUnits(player, data)).size();
double value = nearbyEnemyValue * landMassSize / maxLandMassSize + capitalOrFactoryValue;
if (ProMatches.territoryHasInfraFactoryAndIsLand().test(t)) {
// prefer territories with factories
value *= 1.1;
}
return value;
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class ProTerritoryValueUtils method findTerritoryAttackValue.
public static double findTerritoryAttackValue(final PlayerID player, final Territory t) {
final GameData data = ProData.getData();
final int isEnemyFactory = ProMatches.territoryHasInfraFactoryAndIsEnemyLand(player, data).test(t) ? 1 : 0;
double value = 3 * TerritoryAttachment.getProduction(t) * (isEnemyFactory + 1);
if (!t.isWater() && t.getOwner().isNull()) {
final double strength = ProBattleUtils.estimateStrength(t, new ArrayList<>(t.getUnits().getUnits()), new ArrayList<>(), false);
// Estimate TUV swing as number of casualties * cost
final double tuvSwing = -(strength / 8) * ProData.minCostPerHitPoint;
value += tuvSwing;
}
return value;
}
Aggregations