Search in sources :

Example 66 with GameData

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

the class BattleCalculatorTest method testAaCasualtiesLowLuckMixed.

@Test
public void testAaCasualtiesLowLuckMixed() {
    final GameData data = bridge.getData();
    makeGameLowLuck(data);
    setSelectAaCasualties(data, false);
    // 6 bombers and 6 fighters
    final Collection<Unit> planes = bomber(data).create(6, british(data));
    planes.addAll(fighter(data).create(6, british(data)));
    final Collection<Unit> defendingAa = territory("Germany", data).getUnits().getMatches(Matches.unitIsAaForAnything());
    // don't allow rolling, 6 of each is deterministic
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { ScriptedRandomSource.ERROR }));
    final DiceRoll roll = DiceRoll.rollAa(CollectionUtils.getMatches(planes, Matches.unitIsOfTypes(UnitAttachment.get(defendingAa.iterator().next().getType()).getTargetsAa(data))), defendingAa, bridge, territory("Germany", data), true);
    final Collection<Unit> casualties = BattleCalculator.getAaCasualties(false, planes, planes, defendingAa, defendingAa, roll, bridge, null, null, null, territory("Germany", data), null, false, null).getKilled();
    assertEquals(2, casualties.size());
    // should be 1 fighter and 1 bomber
    assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber()));
    assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber().negate()));
}
Also used : TestMapGameData(games.strategy.triplea.xml.TestMapGameData) GameData(games.strategy.engine.data.GameData) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

Example 67 with GameData

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

the class BattleCalculatorTest method testAaCasualtiesLowLuckMixedWithRolling.

@Test
public void testAaCasualtiesLowLuckMixedWithRolling() {
    final GameData data = bridge.getData();
    makeGameLowLuck(data);
    setSelectAaCasualties(data, false);
    // 7 bombers and 7 fighters
    // 2 extra units, roll once
    final Collection<Unit> planes = bomber(data).create(7, british(data));
    planes.addAll(fighter(data).create(7, british(data)));
    final Collection<Unit> defendingAa = territory("Germany", data).getUnits().getMatches(Matches.unitIsAaForAnything());
    // one roll, a hit
    final ScriptedRandomSource randomSource = new ScriptedRandomSource(new int[] { 0 });
    bridge.setRandomSource(randomSource);
    final DiceRoll roll = DiceRoll.rollAa(CollectionUtils.getMatches(planes, Matches.unitIsOfTypes(UnitAttachment.get(defendingAa.iterator().next().getType()).getTargetsAa(data))), defendingAa, bridge, territory("Germany", data), true);
    // make sure we rolled once
    assertEquals(1, randomSource.getTotalRolled());
    final Collection<Unit> casualties = BattleCalculator.getAaCasualties(false, planes, planes, defendingAa, defendingAa, roll, bridge, null, null, null, territory("Germany", data), null, false, null).getKilled();
    assertEquals(3, casualties.size());
    // a second roll for choosing which unit
    assertEquals(2, randomSource.getTotalRolled());
    // should be 2 fighters and 1 bombers
    assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber()));
    assertEquals(2, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber().negate()));
}
Also used : TestMapGameData(games.strategy.triplea.xml.TestMapGameData) GameData(games.strategy.engine.data.GameData) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

Example 68 with GameData

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

the class BattleCalculatorTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    final GameData data = TestMapGameData.REVISED.getGameData();
    bridge = getDelegateBridge(british(data), data);
}
Also used : TestMapGameData(games.strategy.triplea.xml.TestMapGameData) GameData(games.strategy.engine.data.GameData) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 69 with GameData

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

the class BattleCalculatorTest method testAaCasualtiesLowLuckMixedWithRollingForBombers.

@Test
public void testAaCasualtiesLowLuckMixedWithRollingForBombers() {
    final GameData data = bridge.getData();
    makeGameLowLuck(data);
    setSelectAaCasualties(data, false);
    // 6 bombers, 7 fighters
    final Collection<Unit> planes = bomber(data).create(6, british(data));
    planes.addAll(fighter(data).create(7, british(data)));
    final Collection<Unit> defendingAa = territory("Germany", data).getUnits().getMatches(Matches.unitIsAaForAnything());
    // 1 roll for the extra fighter
    final ScriptedRandomSource randomSource = new ScriptedRandomSource(new int[] { 0, ScriptedRandomSource.ERROR });
    bridge.setRandomSource(randomSource);
    final DiceRoll roll = DiceRoll.rollAa(CollectionUtils.getMatches(planes, Matches.unitIsOfTypes(UnitAttachment.get(defendingAa.iterator().next().getType()).getTargetsAa(data))), defendingAa, bridge, territory("Germany", data), true);
    // make sure we rolled once
    assertEquals(1, randomSource.getTotalRolled());
    final Collection<Unit> casualties = BattleCalculator.getAaCasualties(false, planes, planes, defendingAa, defendingAa, roll, bridge, null, null, null, territory("Germany", data), null, false, null).getKilled();
    assertEquals(3, casualties.size());
    // should be 2 fighters and 1 bombers
    assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber()));
    assertEquals(2, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber().negate()));
}
Also used : TestMapGameData(games.strategy.triplea.xml.TestMapGameData) GameData(games.strategy.engine.data.GameData) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

Example 70 with GameData

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

the class ClientModel method startGameInNewThread.

private void startGameInNewThread(final byte[] gameData, final Map<String, INode> players, final boolean gameRunning) {
    final GameData data;
    try {
        // this normally takes a couple seconds, but can take
        // up to 60 seconds for a freaking huge game
        data = IoUtils.readFromMemory(gameData, GameDataManager::loadGame);
    } catch (final IOException ex) {
        ClientLogger.logQuietly("Failed to load game", ex);
        return;
    }
    objectStreamFactory.setData(data);
    final Map<String, String> playerMapping = playersToNodes.entrySet().stream().filter(e -> e.getValue().equals(messenger.getLocalNode().getName())).collect(Collectors.toMap(Map.Entry::getKey, e -> IGameLoader.CLIENT_PLAYER_TYPE));
    final Set<IGamePlayer> playerSet = data.getGameLoader().createPlayers(playerMapping);
    final Messengers messengers = new Messengers(messenger, remoteMessenger, channelMessenger);
    game = new ClientGame(data, playerSet, players, messengers);
    new Thread(() -> {
        SwingUtilities.invokeLater(() -> JOptionPane.getFrameForComponent(ui).setVisible(false));
        try {
            // game will be null if we loose the connection
            if (game != null) {
                try {
                    data.getGameLoader().startGame(game, playerSet, false);
                    data.testLocksOnRead();
                } catch (final Exception e) {
                    ClientLogger.logError("Failed to start Game", e);
                    game.shutDown();
                    messenger.shutDown();
                    gameLoadingWindow.doneWait();
                    // an ugly hack, we need a better
                    // way to get the main frame
                    GameRunner.clientLeftGame();
                }
            }
            if (!gameRunning) {
                ((IServerReady) remoteMessenger.getRemote(CLIENT_READY_CHANNEL)).clientReady();
            }
        } finally {
            gameLoadingWindow.doneWait();
        }
    }, "Client Game Launcher").start();
}
Also used : ClientGame(games.strategy.engine.framework.ClientGame) ClientMessenger(games.strategy.net.ClientMessenger) IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) TRIPLEA_STARTED(games.strategy.engine.framework.CliProperties.TRIPLEA_STARTED) TRIPLEA_HOST(games.strategy.engine.framework.CliProperties.TRIPLEA_HOST) Map(java.util.Map) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) SetMapClientAction(games.strategy.engine.framework.network.ui.SetMapClientAction) INode(games.strategy.net.INode) PlayerListing(games.strategy.engine.framework.message.PlayerListing) Collection(java.util.Collection) Set(java.util.Set) Logger(java.util.logging.Logger) GameRunner(games.strategy.engine.framework.GameRunner) Component(java.awt.Component) Collectors(java.util.stream.Collectors) TRIPLEA_PORT(games.strategy.engine.framework.CliProperties.TRIPLEA_PORT) IChatPanel(games.strategy.engine.chat.IChatPanel) UnifiedMessenger(games.strategy.engine.message.unifiedmessenger.UnifiedMessenger) IChannelMessenger(games.strategy.engine.message.IChannelMessenger) CountDownLatch(java.util.concurrent.CountDownLatch) GameData(games.strategy.engine.data.GameData) List(java.util.List) ChangeToAutosaveClientAction(games.strategy.engine.framework.network.ui.ChangeToAutosaveClientAction) EventThreadJOptionPane(games.strategy.util.EventThreadJOptionPane) TRIPLEA_NAME(games.strategy.engine.framework.CliProperties.TRIPLEA_NAME) WaitWindow(games.strategy.engine.framework.ui.background.WaitWindow) SwingAction(games.strategy.ui.SwingAction) Setter(lombok.Setter) Getter(lombok.Getter) ChangeGameOptionsClientAction(games.strategy.engine.framework.network.ui.ChangeGameOptionsClientAction) Messengers(games.strategy.net.Messengers) HashMap(java.util.HashMap) Action(javax.swing.Action) MacFinder(games.strategy.net.MacFinder) RemoteName(games.strategy.engine.message.RemoteName) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) IMessengerErrorListener(games.strategy.net.IMessengerErrorListener) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) SwingUtilities(javax.swing.SwingUtilities) ClientLogin(games.strategy.engine.framework.startup.login.ClientLogin) ClientOptions(games.strategy.engine.framework.startup.ui.ClientOptions) IMessenger(games.strategy.net.IMessenger) GameDataManager(games.strategy.engine.framework.GameDataManager) IoUtils(games.strategy.io.IoUtils) ClientSetting(games.strategy.triplea.settings.ClientSetting) Nonnull(javax.annotation.Nonnull) GetGameSaveClientAction(games.strategy.engine.framework.network.ui.GetGameSaveClientAction) ChangeGameToSaveGameClientAction(games.strategy.engine.framework.network.ui.ChangeGameToSaveGameClientAction) TRIPLEA_CLIENT(games.strategy.engine.framework.CliProperties.TRIPLEA_CLIENT) Interruptibles(games.strategy.util.Interruptibles) SaveGameFileChooser(games.strategy.engine.framework.ui.SaveGameFileChooser) IOException(java.io.IOException) Chat(games.strategy.engine.chat.Chat) JOptionPane(javax.swing.JOptionPane) IServerReady(games.strategy.engine.framework.startup.launcher.IServerReady) GameObjectStreamFactory(games.strategy.engine.framework.GameObjectStreamFactory) TimeUnit(java.util.concurrent.TimeUnit) ClientLogger(games.strategy.debug.ClientLogger) IRemoteMessenger(games.strategy.engine.message.IRemoteMessenger) ChannelMessenger(games.strategy.engine.message.ChannelMessenger) IGameLoader(games.strategy.engine.framework.IGameLoader) CouldNotLogInException(games.strategy.net.CouldNotLogInException) Preconditions(com.google.common.base.Preconditions) ChatPanel(games.strategy.engine.chat.ChatPanel) IClientMessenger(games.strategy.net.IClientMessenger) IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) Messengers(games.strategy.net.Messengers) GameData(games.strategy.engine.data.GameData) IOException(java.io.IOException) ClientGame(games.strategy.engine.framework.ClientGame) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) CouldNotLogInException(games.strategy.net.CouldNotLogInException)

Aggregations

GameData (games.strategy.engine.data.GameData)204 Unit (games.strategy.engine.data.Unit)100 PlayerID (games.strategy.engine.data.PlayerID)92 Territory (games.strategy.engine.data.Territory)92 ArrayList (java.util.ArrayList)83 TripleAUnit (games.strategy.triplea.TripleAUnit)64 HashSet (java.util.HashSet)50 CompositeChange (games.strategy.engine.data.CompositeChange)40 List (java.util.List)36 HashMap (java.util.HashMap)32 Set (java.util.Set)32 Route (games.strategy.engine.data.Route)31 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)30 Collection (java.util.Collection)29 UnitType (games.strategy.engine.data.UnitType)26 Change (games.strategy.engine.data.Change)24 Test (org.junit.jupiter.api.Test)23 Resource (games.strategy.engine.data.Resource)22 TestMapGameData (games.strategy.triplea.xml.TestMapGameData)22 Map (java.util.Map)21