Search in sources :

Example 1 with GameMap

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

the class AirThatCantLandUtil method removeAirThatCantLand.

void removeAirThatCantLand(final PlayerID player, final boolean spareAirInSeaZonesBesideFactories) {
    final GameData data = bridge.getData();
    final GameMap map = data.getMap();
    for (final Territory current : getTerritoriesWhereAirCantLand(player)) {
        final Predicate<Unit> ownedAir = Matches.unitIsAir().and(Matches.alliedUnit(player, data));
        final Collection<Unit> air = current.getUnits().getMatches(ownedAir);
        final boolean hasNeighboringFriendlyFactory = map.getNeighbors(current, Matches.territoryHasAlliedIsFactoryOrCanProduceUnits(data, player)).size() > 0;
        final boolean skip = spareAirInSeaZonesBesideFactories && current.isWater() && hasNeighboringFriendlyFactory;
        if (!skip) {
            removeAirThatCantLand(player, current, air);
        }
    }
}
Also used : Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) GameMap(games.strategy.engine.data.GameMap) Unit(games.strategy.engine.data.Unit)

Example 2 with GameMap

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

the class GameDataExporter method connections.

private void connections(final GameData data) {
    xmlfile.append("        <!-- Territory Connections -->\n");
    final GameMap map = data.getMap();
    final List<Connection> reverseConnectionTracker = new ArrayList<>();
    for (final Territory ter : map.getTerritories()) {
        for (final Territory nb : map.getNeighbors(ter)) {
            if (!reverseConnectionTracker.contains(new Connection(ter, nb))) {
                xmlfile.append("        <connection t1=\"").append(ter.getName()).append("\" t2=\"").append(nb.getName()).append("\"/>\n");
                reverseConnectionTracker.add(new Connection(nb, ter));
            }
        }
    }
}
Also used : Territory(games.strategy.engine.data.Territory) GameMap(games.strategy.engine.data.GameMap) ArrayList(java.util.ArrayList)

Example 3 with GameMap

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

the class RulesAttachment method setBattle.

private void setBattle(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length < 5) {
        throw new GameParseException("battle must have at least 5 fields, attacker:defender:resultType:round:territory1..." + thisErrorMsg());
    }
    final PlayerID attacker = getData().getPlayerList().getPlayerId(s[0]);
    if (attacker == null && !s[0].equalsIgnoreCase("any")) {
        throw new GameParseException("no player named: " + s[0] + thisErrorMsg());
    }
    final PlayerID defender = getData().getPlayerList().getPlayerId(s[1]);
    if (defender == null && !s[1].equalsIgnoreCase("any")) {
        throw new GameParseException("no player named: " + s[1] + thisErrorMsg());
    }
    if (!s[2].equalsIgnoreCase("any")) {
        throw new GameParseException("battle allows the following for resultType: any" + thisErrorMsg());
    }
    if (!s[3].equalsIgnoreCase("currentRound")) {
        try {
            getInt(s[3].split("-")[0]);
            getInt(s[3].split("-")[1]);
        } catch (final Exception e) {
            throw new GameParseException("round must either be currentRound or two numbers like: 2-4" + thisErrorMsg());
        }
    }
    final ArrayList<Territory> terrs = new ArrayList<>();
    final GameMap map = getData().getMap();
    // this loop starts on 4, so do not replace with an enhanced for loop
    for (int i = 4; i < s.length; i++) {
        final Territory t = map.getTerritory(s[i]);
        if (t == null) {
            throw new GameParseException("no such territory called: " + s[i] + thisErrorMsg());
        }
        terrs.add(t);
    }
    m_battle.add(Tuple.of((s[0] + ":" + s[1] + ":" + s[2] + ":" + s[3]), terrs));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) GameMap(games.strategy.engine.data.GameMap) ArrayList(java.util.ArrayList) GameParseException(games.strategy.engine.data.GameParseException) GameParseException(games.strategy.engine.data.GameParseException)

Example 4 with GameMap

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

the class ParserTest method testTerritoriesConnected.

@Test
public void testTerritoriesConnected() {
    final GameMap map = gameData.getMap();
    assertEquals(1, map.getDistance(map.getTerritory("canada"), map.getTerritory("us")));
}
Also used : GameMap(games.strategy.engine.data.GameMap) Test(org.junit.jupiter.api.Test)

Example 5 with GameMap

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

the class SpecialMoveDelegate method allowAirborne.

private static boolean allowAirborne(final PlayerID player, final GameData data) {
    if (!TechAbilityAttachment.getAllowAirborneForces(player, data)) {
        return false;
    }
    final int airborneDistance = TechAbilityAttachment.getAirborneDistance(player, data);
    final Set<UnitType> airborneBases = TechAbilityAttachment.getAirborneBases(player, data);
    final Set<UnitType> airborneTypes = TechAbilityAttachment.getAirborneTypes(player, data);
    if (airborneDistance <= 0 || airborneBases.isEmpty() || airborneTypes.isEmpty()) {
        return false;
    }
    final GameMap map = data.getMap();
    final Collection<PlayerID> alliesForBases = data.getRelationshipTracker().getAllies(player, true);
    final Collection<Territory> territoriesWeCanLaunchFrom = CollectionUtils.getMatches(map.getTerritories(), Matches.territoryHasUnitsThatMatch(getAirborneMatch(airborneBases, alliesForBases)));
    return !territoriesWeCanLaunchFrom.isEmpty();
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) GameMap(games.strategy.engine.data.GameMap) UnitType(games.strategy.engine.data.UnitType)

Aggregations

GameMap (games.strategy.engine.data.GameMap)9 Territory (games.strategy.engine.data.Territory)8 PlayerID (games.strategy.engine.data.PlayerID)3 ArrayList (java.util.ArrayList)3 Unit (games.strategy.engine.data.Unit)2 Test (org.junit.jupiter.api.Test)2 GameData (games.strategy.engine.data.GameData)1 GameParseException (games.strategy.engine.data.GameParseException)1 UnitType (games.strategy.engine.data.UnitType)1 PlayerAttachment (games.strategy.triplea.attachments.PlayerAttachment)1 IntegerMap (games.strategy.util.IntegerMap)1 Tuple (games.strategy.util.Tuple)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1