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