Search in sources :

Example 76 with PlayerID

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

the class PoliticalStateOverview method drawPoliticsUi.

/**
 * does the actual adding of elements to this panel.
 */
private void drawPoliticsUi() {
    this.setLayout(new GridBagLayout());
    // draw horizontal labels
    int currentCell = 1;
    final Insets insets = new Insets(5, 2, 5, 2);
    for (final PlayerID p : data.getPlayerList()) {
        this.add(getPlayerLabel(p), new GridBagConstraints(currentCell++, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insets, 0, 0));
    }
    // draw vertical labels and dividers
    currentCell = 1;
    for (final PlayerID p : data.getPlayerList()) {
        this.add(new JSeparator(), new GridBagConstraints(0, currentCell++, 20, 1, 0.1, 0.1, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        this.add(getPlayerLabel(p), new GridBagConstraints(0, currentCell++, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, insets, 0, 0));
    }
    // draw cells
    int x = 1;
    int y = 2;
    for (final PlayerID verticalPlayer : data.getPlayerList()) {
        for (final PlayerID horizontalPlayer : data.getPlayerList()) {
            if (horizontalPlayer.equals(verticalPlayer)) {
                this.add(new JLabel(PoliticalStateOverview.LABEL_SELF), new GridBagConstraints(x++, y, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, insets, 0, 0));
            } else {
                this.add(getRelationshipLabel(verticalPlayer, horizontalPlayer), new GridBagConstraints(x++, y, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insets, 0, 0));
            }
        }
        y = y + 2;
        x = 1;
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) JSeparator(javax.swing.JSeparator)

Example 77 with PlayerID

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

the class WW2V3Year41Test method testMoveParatroopersAsNonPartroops.

@Test
public void testMoveParatroopersAsNonPartroops() {
    // move a bomber and a paratrooper
    // one step, but as a normal movement
    final PlayerID germans = germans(gameData);
    final Territory germany = territory("Germany", gameData);
    final Territory nwe = territory("Northwestern Europe", gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("CombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    TechAttachment.get(germans).setParatroopers("true");
    List<Unit> paratrooper = germany.getUnits().getMatches(Matches.unitIsAirTransportable());
    paratrooper = paratrooper.subList(0, 1);
    final List<Unit> bomberAndParatroop = new ArrayList<>(paratrooper);
    bomberAndParatroop.addAll(germany.getUnits().getMatches(Matches.unitIsAirTransport()));
    // move to nwe, this is a valid move, and it not a partroop move
    move(bomberAndParatroop, new Route(germany, nwe));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 78 with PlayerID

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

the class WW2V3Year41Test method testAirCanLandWithAlliedFighters.

@Test
public void testAirCanLandWithAlliedFighters() {
    // germany owns madagascar, with 2 fighters in it
    // also 1 carrier, and 1 allied fighter in sz 40
    // the fighters should not be able to move from madagascar
    // to sz 40, since with the allied fighter, their is no room
    // on the carrier
    final Territory madagascar = territory("French Madagascar", gameData);
    final PlayerID germans = germans(gameData);
    madagascar.setOwner(germans);
    final Territory sz40 = territory("40 Sea Zone", gameData);
    addTo(sz40, carrier(gameData).create(1, germans));
    addTo(sz40, fighter(gameData).create(1, italians(gameData)));
    addTo(madagascar, fighter(gameData).create(2, germans));
    final Route route = gameData.getMap().getRoute(madagascar, sz40);
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("CombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    // don't allow kamikaze
    bridge.setRemote(dummyPlayer);
    final String error = moveDelegate(gameData).move(madagascar.getUnits().getUnits(), route);
    assertError(error);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 79 with PlayerID

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

the class WW2V3Year41Test method testDefencelessTransportsDie.

@Test
public void testDefencelessTransportsDie() {
    final PlayerID british = british(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(british);
    bridge.setStepName("CombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    final Territory uk = territory("United Kingdom", gameData);
    final Territory sz5 = territory("5 Sea Zone", gameData);
    // remove the sub
    removeFrom(sz5, sz5.getUnits().getMatches(Matches.unitIsSub()));
    when(dummyPlayer.retreatQuery(any(), anyBoolean(), any(), any(), any())).thenAnswer(new Answer<Territory>() {

        @Override
        public Territory answer(final InvocationOnMock invocation) throws Throwable {
            throw new IllegalStateException("Should not be asked to retreat:" + invocation.getArgument(4));
        }
    });
    bridge.setRemote(dummyPlayer);
    move(uk.getUnits().getMatches(Matches.unitIsAir()), gameData.getMap().getRoute(uk, sz5));
    // move units for amphib assault
    moveDelegate(gameData).end();
    bridge.setStepName("Combat");
    // cook the dice so that 1 british fighters hits, and nothing else
    // this will leave 1 transport alone in the sea zone
    bridge.setRandomSource(new ScriptedRandomSource(1, 5, 5, 5, 5, 5, 5, 5, 5));
    battleDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    battleDelegate(gameData).start();
    // make sure the transports died
    assertTrue(sz5.getUnits().getMatches(Matches.unitIsOwnedBy(germans(gameData))).isEmpty());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Test(org.junit.jupiter.api.Test)

Example 80 with PlayerID

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

the class WW2V3Year41Test method testLoadedTransportAttackKillsLoadedUnits.

@Test
public void testLoadedTransportAttackKillsLoadedUnits() {
    final PlayerID british = british(gameData);
    final MoveDelegate moveDelegate = moveDelegate(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(british);
    bridge.setStepName("britishCombatMove");
    when(dummyPlayer.selectAttackSubs(any())).thenReturn(true);
    bridge.setRemote(dummyPlayer);
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    final Territory sz9 = territory("9 Sea Zone", gameData);
    final Territory sz7 = territory("7 Sea Zone", gameData);
    final Territory uk = territory("United Kingdom", gameData);
    final Route sz9ToSz7 = new Route(sz9, territory("8 Sea Zone", gameData), sz7);
    // move the transport to attack, this is suicide but valid
    final List<Unit> transports = sz9.getUnits().getMatches(Matches.unitIsTransport());
    move(transports, sz9ToSz7);
    // load the transport
    load(uk.getUnits().getMatches(Matches.unitIsLandTransportable()), new Route(uk, sz7));
    moveDelegate(gameData).end();
    final ScriptedRandomSource randomSource = new ScriptedRandomSource(new int[] { 0, 1 });
    bridge.setRandomSource(randomSource);
    bridge.setStepName("britishBattle");
    final BattleDelegate battleDelegate = battleDelegate(gameData);
    battleDelegate.setDelegateBridgeAndPlayer(bridge);
    assertEquals(2, TransportTracker.transporting(transports.get(0)).size());
    battleDelegate.start();
    // battle already fought
    // make sure the infantry die with the transport
    assertTrue(sz7.getUnits().getMatches(Matches.unitOwnedBy(british)).isEmpty(), sz7.getUnits().toString());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Aggregations

PlayerID (games.strategy.engine.data.PlayerID)323 Territory (games.strategy.engine.data.Territory)163 Unit (games.strategy.engine.data.Unit)133 Test (org.junit.jupiter.api.Test)122 TripleAUnit (games.strategy.triplea.TripleAUnit)104 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)94 GameData (games.strategy.engine.data.GameData)90 ArrayList (java.util.ArrayList)79 UnitType (games.strategy.engine.data.UnitType)74 Route (games.strategy.engine.data.Route)67 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)46 HashSet (java.util.HashSet)44 Change (games.strategy.engine.data.Change)29 CompositeChange (games.strategy.engine.data.CompositeChange)29 IntegerMap (games.strategy.util.IntegerMap)29 List (java.util.List)29 HashMap (java.util.HashMap)28 Collection (java.util.Collection)27 Resource (games.strategy.engine.data.Resource)25 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)23