use of games.strategy.engine.data.Territory in project triplea by triplea-game.
the class ProTransportUtils method getUnitsToTransportThatCantMoveToHigherValue.
public static List<Unit> getUnitsToTransportThatCantMoveToHigherValue(final PlayerID player, final Unit transport, final Set<Territory> territoriesToLoadFrom, final List<Unit> unitsToIgnore, final Map<Territory, ProTerritory> moveMap, final Map<Unit, Set<Territory>> unitMoveMap, final double value) {
final List<Unit> unitsToIgnoreOrHaveBetterLandMove = new ArrayList<>(unitsToIgnore);
if (!TransportTracker.isTransporting(transport)) {
// Get all units that can be transported
final List<Unit> units = new ArrayList<>();
for (final Territory loadFrom : territoriesToLoadFrom) {
units.addAll(loadFrom.getUnits().getMatches(ProMatches.unitIsOwnedTransportableUnitAndCanBeLoaded(player, transport, true)));
}
units.removeAll(unitsToIgnore);
// Check to see which have higher land move value
for (final Unit u : units) {
if (unitMoveMap.get(u) != null) {
for (final Territory t : unitMoveMap.get(u)) {
if (moveMap.get(t) != null && moveMap.get(t).getValue() > value) {
unitsToIgnoreOrHaveBetterLandMove.add(u);
break;
}
}
}
}
}
return getUnitsToTransportFromTerritories(player, transport, territoriesToLoadFrom, unitsToIgnoreOrHaveBetterLandMove);
}
use of games.strategy.engine.data.Territory in project triplea by triplea-game.
the class ProTransportUtils method getUnitsToTransportFromTerritories.
// TODO: this needs fixed to consider whether a valid route exists to load all units
public static List<Unit> getUnitsToTransportFromTerritories(final PlayerID player, final Unit transport, final Set<Territory> territoriesToLoadFrom, final List<Unit> unitsToIgnore, final Predicate<Unit> validUnitMatch) {
final List<Unit> selectedUnits = new ArrayList<>();
// Get units if transport already loaded
if (TransportTracker.isTransporting(transport)) {
selectedUnits.addAll(TransportTracker.transporting(transport));
} else {
// Get all units that can be transported
final List<Unit> units = new ArrayList<>();
for (final Territory loadFrom : territoriesToLoadFrom) {
units.addAll(loadFrom.getUnits().getMatches(validUnitMatch));
}
units.removeAll(unitsToIgnore);
// Sort units by attack
units.sort((o1, o2) -> {
// Very rough way to add support power
final Set<UnitSupportAttachment> supportAttachments1 = UnitSupportAttachment.get(o1.getType());
int maxSupport1 = 0;
for (final UnitSupportAttachment usa : supportAttachments1) {
if (usa.getAllied() && usa.getOffence() && usa.getBonus() > maxSupport1) {
maxSupport1 = usa.getBonus();
}
}
final int attack1 = UnitAttachment.get(o1.getType()).getAttack(player) + maxSupport1;
final Set<UnitSupportAttachment> supportAttachments2 = UnitSupportAttachment.get(o2.getType());
int maxSupport2 = 0;
for (final UnitSupportAttachment usa : supportAttachments2) {
if (usa.getAllied() && usa.getOffence() && usa.getBonus() > maxSupport2) {
maxSupport2 = usa.getBonus();
}
}
final int attack2 = UnitAttachment.get(o2.getType()).getAttack(player) + maxSupport2;
return attack2 - attack1;
});
// Get best units that can be loaded
selectedUnits.addAll(selectUnitsToTransportFromList(transport, units));
}
return selectedUnits;
}
use of games.strategy.engine.data.Territory in project triplea by triplea-game.
the class ProUtils method getClosestEnemyLandTerritoryDistance.
public static int getClosestEnemyLandTerritoryDistance(final GameData data, final PlayerID player, final Territory t) {
final Set<Territory> landTerritories = data.getMap().getNeighbors(t, 9, ProMatches.territoryCanPotentiallyMoveLandUnits(player, data));
final List<Territory> enemyLandTerritories = CollectionUtils.getMatches(landTerritories, Matches.isTerritoryOwnedBy(getPotentialEnemyPlayers(player)));
int minDistance = 10;
for (final Territory enemyLandTerritory : enemyLandTerritories) {
final int distance = data.getMap().getDistance(t, enemyLandTerritory, ProMatches.territoryCanPotentiallyMoveLandUnits(player, data));
if (distance < minDistance) {
minDistance = distance;
}
}
return (minDistance < 10) ? minDistance : -1;
}
use of games.strategy.engine.data.Territory in project triplea by triplea-game.
the class ProUtils method getLiveAlliedCapitals.
public static List<Territory> getLiveAlliedCapitals(final GameData data, final PlayerID player) {
final List<Territory> capitals = new ArrayList<>();
final List<PlayerID> players = getAlliedPlayers(player);
for (final PlayerID alliedPlayer : players) {
capitals.addAll(TerritoryAttachment.getAllCurrentlyOwnedCapitals(alliedPlayer, data));
}
capitals.retainAll(CollectionUtils.getMatches(capitals, Matches.territoryIsNotImpassableToLandUnits(player, data)));
capitals.retainAll(CollectionUtils.getMatches(capitals, Matches.isTerritoryAllied(player, data)));
return capitals;
}
use of games.strategy.engine.data.Territory in project triplea by triplea-game.
the class ProUtils method getLiveEnemyCapitals.
public static List<Territory> getLiveEnemyCapitals(final GameData data, final PlayerID player) {
final List<Territory> enemyCapitals = new ArrayList<>();
final List<PlayerID> enemyPlayers = getEnemyPlayers(player);
for (final PlayerID otherPlayer : enemyPlayers) {
enemyCapitals.addAll(TerritoryAttachment.getAllCurrentlyOwnedCapitals(otherPlayer, data));
}
enemyCapitals.retainAll(CollectionUtils.getMatches(enemyCapitals, Matches.territoryIsNotImpassableToLandUnits(player, data)));
enemyCapitals.retainAll(CollectionUtils.getMatches(enemyCapitals, Matches.isTerritoryOwnedBy(getPotentialEnemyPlayers(player))));
return enemyCapitals;
}
Aggregations