Search in sources :

Example 66 with Territory

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);
}
Also used : Territory(games.strategy.engine.data.Territory) ProTerritory(games.strategy.triplea.ai.pro.data.ProTerritory) ArrayList(java.util.ArrayList) Unit(games.strategy.engine.data.Unit)

Example 67 with Territory

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;
}
Also used : Territory(games.strategy.engine.data.Territory) ProTerritory(games.strategy.triplea.ai.pro.data.ProTerritory) UnitSupportAttachment(games.strategy.triplea.attachments.UnitSupportAttachment) ArrayList(java.util.ArrayList) Unit(games.strategy.engine.data.Unit)

Example 68 with Territory

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;
}
Also used : Territory(games.strategy.engine.data.Territory)

Example 69 with Territory

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;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList)

Example 70 with Territory

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;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList)

Aggregations

Territory (games.strategy.engine.data.Territory)420 Unit (games.strategy.engine.data.Unit)254 TripleAUnit (games.strategy.triplea.TripleAUnit)195 PlayerID (games.strategy.engine.data.PlayerID)164 ArrayList (java.util.ArrayList)160 Test (org.junit.jupiter.api.Test)140 Route (games.strategy.engine.data.Route)137 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)118 GameData (games.strategy.engine.data.GameData)94 HashSet (java.util.HashSet)87 UnitType (games.strategy.engine.data.UnitType)65 HashMap (java.util.HashMap)65 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)50 Collection (java.util.Collection)47 IntegerMap (games.strategy.util.IntegerMap)45 Set (java.util.Set)41 ProTerritory (games.strategy.triplea.ai.pro.data.ProTerritory)39 TerritoryAttachment (games.strategy.triplea.attachments.TerritoryAttachment)37 List (java.util.List)36 ProPurchaseTerritory (games.strategy.triplea.ai.pro.data.ProPurchaseTerritory)34