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;
}
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;
}
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;
}
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);
}
}
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()));
}
}
}
Aggregations