Search in sources :

Example 6 with RulesAttachment

use of games.strategy.triplea.attachments.RulesAttachment in project triplea by triplea-game.

the class ProPurchaseUtils method findPurchaseTerritories.

public static Map<Territory, ProPurchaseTerritory> findPurchaseTerritories(final PlayerID player) {
    ProLogger.info("Find all purchase territories");
    final GameData data = ProData.getData();
    // Find all territories that I can place units on
    final RulesAttachment ra = player.getRulesAttachment();
    List<Territory> ownedAndNotConqueredFactoryTerritories;
    if (ra != null && ra.getPlacementAnyTerritory()) {
        ownedAndNotConqueredFactoryTerritories = data.getMap().getTerritoriesOwnedBy(player);
    } else {
        ownedAndNotConqueredFactoryTerritories = CollectionUtils.getMatches(data.getMap().getTerritories(), ProMatches.territoryHasInfraFactoryAndIsNotConqueredOwnedLand(player, data));
    }
    ownedAndNotConqueredFactoryTerritories = CollectionUtils.getMatches(ownedAndNotConqueredFactoryTerritories, ProMatches.territoryCanMoveLandUnits(player, data, false));
    // Create purchase territory holder for each factory territory
    final Map<Territory, ProPurchaseTerritory> purchaseTerritories = new HashMap<>();
    for (final Territory t : ownedAndNotConqueredFactoryTerritories) {
        final int unitProduction = getUnitProduction(t, data, player);
        final ProPurchaseTerritory ppt = new ProPurchaseTerritory(t, data, player, unitProduction);
        purchaseTerritories.put(t, ppt);
        ProLogger.debug(ppt.toString());
    }
    return purchaseTerritories;
}
Also used : ProPlaceTerritory(games.strategy.triplea.ai.pro.data.ProPlaceTerritory) ProPurchaseTerritory(games.strategy.triplea.ai.pro.data.ProPurchaseTerritory) Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProPurchaseTerritory(games.strategy.triplea.ai.pro.data.ProPurchaseTerritory) RulesAttachment(games.strategy.triplea.attachments.RulesAttachment)

Example 7 with RulesAttachment

use of games.strategy.triplea.attachments.RulesAttachment in project triplea by triplea-game.

the class ProPurchaseUtils method getUnitProduction.

private static int getUnitProduction(final Territory territory, final GameData data, final PlayerID player) {
    final Predicate<Unit> factoryMatch = Matches.unitIsOwnedAndIsFactoryOrCanProduceUnits(player).and(Matches.unitIsBeingTransported().negate()).and((territory.isWater() ? Matches.unitIsLand() : Matches.unitIsSea()).negate());
    final Collection<Unit> factoryUnits = territory.getUnits().getMatches(factoryMatch);
    final TerritoryAttachment ta = TerritoryAttachment.get(territory);
    final boolean originalFactory = (ta != null && ta.getOriginalFactory());
    final boolean playerIsOriginalOwner = factoryUnits.size() > 0 && player.equals(getOriginalFactoryOwner(territory, player));
    final RulesAttachment ra = player.getRulesAttachment();
    if (originalFactory && playerIsOriginalOwner) {
        if (ra != null && ra.getMaxPlacePerTerritory() != -1) {
            return Math.max(0, ra.getMaxPlacePerTerritory());
        }
        return Integer.MAX_VALUE;
    }
    if (ra != null && ra.getPlacementAnyTerritory()) {
        return Integer.MAX_VALUE;
    }
    return TripleAUnit.getProductionPotentialOfTerritory(territory.getUnits().getUnits(), territory, player, data, true, true);
}
Also used : TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) RulesAttachment(games.strategy.triplea.attachments.RulesAttachment)

Example 8 with RulesAttachment

use of games.strategy.triplea.attachments.RulesAttachment in project triplea by triplea-game.

the class PactOfSteel2Test method testDirectOwnershipTerritories.

@Test
public void testDirectOwnershipTerritories() {
    final Territory norway = gameData.getMap().getTerritory("Norway");
    final Territory easternEurope = gameData.getMap().getTerritory("Eastern Europe");
    final Territory eastBalkans = gameData.getMap().getTerritory("East Balkans");
    final Territory ukraineSsr = gameData.getMap().getTerritory("Ukraine S.S.R.");
    final Territory belorussia = gameData.getMap().getTerritory("Belorussia");
    final PlayerID british = GameDataTestUtil.british(gameData);
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final PlayerID russians = GameDataTestUtil.russians(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(russians);
    // this National Objective russia has to own at least 3 of the 5 territories by itself
    final RulesAttachment russianEasternEurope = RulesAttachment.get(russians, "objectiveAttachmentRussians1_EasternEurope");
    final Collection<Territory> terrs = new ArrayList<>();
    terrs.add(norway);
    terrs.add(easternEurope);
    terrs.add(eastBalkans);
    terrs.add(ukraineSsr);
    terrs.add(belorussia);
    assertEquals(5, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertFalse(russianEasternEurope.isSatisfied(null, bridge));
    norway.setOwner(british);
    easternEurope.setOwner(russians);
    eastBalkans.setOwner(russians);
    ukraineSsr.setOwner(germans);
    belorussia.setOwner(germans);
    assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(1, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertFalse(russianEasternEurope.isSatisfied(null, bridge));
    ukraineSsr.setOwner(british);
    belorussia.setOwner(british);
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(3, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertFalse(russianEasternEurope.isSatisfied(null, bridge));
    norway.setOwner(russians);
    ukraineSsr.setOwner(germans);
    belorussia.setOwner(germans);
    assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(3, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertTrue(russianEasternEurope.isSatisfied(null, bridge));
    ukraineSsr.setOwner(russians);
    assertEquals(1, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(4, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertTrue(russianEasternEurope.isSatisfied(null, bridge));
    belorussia.setOwner(russians);
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(5, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertTrue(russianEasternEurope.isSatisfied(null, bridge));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) RulesAttachment(games.strategy.triplea.attachments.RulesAttachment) Test(org.junit.jupiter.api.Test)

Aggregations

RulesAttachment (games.strategy.triplea.attachments.RulesAttachment)8 Territory (games.strategy.engine.data.Territory)5 ArrayList (java.util.ArrayList)5 Unit (games.strategy.engine.data.Unit)3 GameData (games.strategy.engine.data.GameData)2 PlayerID (games.strategy.engine.data.PlayerID)2 TripleAUnit (games.strategy.triplea.TripleAUnit)2 AbstractTriggerAttachment (games.strategy.triplea.attachments.AbstractTriggerAttachment)2 ICondition (games.strategy.triplea.attachments.ICondition)2 TerritoryAttachment (games.strategy.triplea.attachments.TerritoryAttachment)2 TriggerAttachment (games.strategy.triplea.attachments.TriggerAttachment)2 HashSet (java.util.HashSet)2 Change (games.strategy.engine.data.Change)1 CompositeChange (games.strategy.engine.data.CompositeChange)1 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)1 Resource (games.strategy.engine.data.Resource)1 UnitType (games.strategy.engine.data.UnitType)1 IDelegateBridge (games.strategy.engine.delegate.IDelegateBridge)1 ProPlaceTerritory (games.strategy.triplea.ai.pro.data.ProPlaceTerritory)1 ProPurchaseTerritory (games.strategy.triplea.ai.pro.data.ProPurchaseTerritory)1