Search in sources :

Example 71 with Territory

use of games.strategy.engine.data.Territory in project triplea by triplea-game.

the class ProUtils method getPlayerProduction.

public static double getPlayerProduction(final PlayerID player, final GameData data) {
    int production = 0;
    for (final Territory place : data.getMap().getTerritories()) {
        // Match will Check if terr is a Land Convoy Route and check ownership of neighboring Sea Zone, or if contested
        if (place.getOwner().equals(player) && Matches.territoryCanCollectIncomeFrom(player, data).test(place)) {
            production += TerritoryAttachment.getProduction(place);
        }
    }
    production *= Properties.getPuMultiplier(data);
    return production;
}
Also used : Territory(games.strategy.engine.data.Territory)

Example 72 with Territory

use of games.strategy.engine.data.Territory in project triplea by triplea-game.

the class Utils method findNearest.

static Route findNearest(final Territory start, final Predicate<Territory> endCondition, final Predicate<Territory> routeCondition, final GameData data) {
    Route shortestRoute = null;
    for (final Territory t : data.getMap().getTerritories()) {
        if (endCondition.test(t)) {
            final Predicate<Territory> routeOrEnd = routeCondition.or(Matches.territoryIs(t));
            final Route r = data.getMap().getRoute(start, t, routeOrEnd);
            if (r != null) {
                if (shortestRoute == null || r.numberOfSteps() < shortestRoute.numberOfSteps()) {
                    shortestRoute = r;
                }
            }
        }
    }
    return shortestRoute;
}
Also used : Territory(games.strategy.engine.data.Territory) Route(games.strategy.engine.data.Route)

Example 73 with Territory

use of games.strategy.engine.data.Territory in project triplea by triplea-game.

the class Utils method findUnitTerr.

/**
 * Return Territories containing any unit depending on unitCondition
 * Differs from findCertainShips because it doesn't require the units be owned.
 */
static List<Territory> findUnitTerr(final GameData data, final Predicate<Unit> unitCondition) {
    // Return territories containing a certain unit or set of Units
    final List<Territory> shipTerr = new ArrayList<>();
    final Collection<Territory> neighbors = data.getMap().getTerritories();
    for (final Territory t2 : neighbors) {
        if (t2.getUnits().anyMatch(unitCondition)) {
            shipTerr.add(t2);
        }
    }
    return shipTerr;
}
Also used : Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList)

Example 74 with Territory

use of games.strategy.engine.data.Territory in project triplea by triplea-game.

the class WeakAi method populateTransportUnloadNonCom.

private static void populateTransportUnloadNonCom(final GameData data, final List<Collection<Unit>> moveUnits, final List<Route> moveRoutes, final PlayerID player) {
    final Route amphibRoute = getAmphibRoute(player, data);
    if (amphibRoute == null) {
        return;
    }
    final Territory lastSeaZoneOnAmphib = amphibRoute.getAllTerritories().get(amphibRoute.numberOfSteps() - 1);
    final Territory landOn = amphibRoute.getEnd();
    final Predicate<Unit> landAndOwned = Matches.unitIsLand().and(Matches.unitIsOwnedBy(player));
    final List<Unit> units = lastSeaZoneOnAmphib.getUnits().getMatches(landAndOwned);
    if (units.size() > 0) {
        // just try to make the move, the engine will stop us if it doesnt work
        final Route route = new Route();
        route.setStart(lastSeaZoneOnAmphib);
        route.add(landOn);
        moveUnits.add(units);
        moveRoutes.add(route);
    }
}
Also used : Territory(games.strategy.engine.data.Territory) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Route(games.strategy.engine.data.Route)

Example 75 with Territory

use of games.strategy.engine.data.Territory in project triplea by triplea-game.

the class WeakAi method populateTransportLoad.

private void populateTransportLoad(final GameData data, final List<Collection<Unit>> moveUnits, final List<Route> moveRoutes, final List<Collection<Unit>> transportsToLoad, final PlayerID player) {
    if (!isAmphibAttack(player, data)) {
        return;
    }
    final Territory capitol = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(player, data);
    if (capitol == null || !capitol.getOwner().equals(player)) {
        return;
    }
    List<Unit> unitsToLoad = capitol.getUnits().getMatches(Matches.unitIsInfrastructure().negate());
    unitsToLoad = CollectionUtils.getMatches(unitsToLoad, Matches.unitIsOwnedBy(getPlayerId()));
    for (final Territory neighbor : data.getMap().getNeighbors(capitol)) {
        if (!neighbor.isWater()) {
            continue;
        }
        final List<Unit> units = new ArrayList<>();
        for (final Unit transport : neighbor.getUnits().getMatches(Matches.unitIsOwnedBy(player))) {
            int free = TransportTracker.getAvailableCapacity(transport);
            if (free <= 0) {
                continue;
            }
            final Iterator<Unit> iter = unitsToLoad.iterator();
            while (iter.hasNext() && free > 0) {
                final Unit current = iter.next();
                final UnitAttachment ua = UnitAttachment.get(current.getType());
                if (ua.getIsAir()) {
                    continue;
                }
                if (ua.getTransportCost() <= free) {
                    iter.remove();
                    free -= ua.getTransportCost();
                    units.add(current);
                }
            }
        }
        if (units.size() > 0) {
            final Route route = new Route();
            route.setStart(capitol);
            route.add(neighbor);
            moveUnits.add(units);
            moveRoutes.add(route);
            transportsToLoad.add(neighbor.getUnits().getMatches(Matches.unitIsTransport()));
        }
    }
}
Also used : UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Route(games.strategy.engine.data.Route)

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