@Override public MainGridWithUiSettings loadMainGrid(PlayerSetting[] playerSettings, EMapStartResources startResources) throws MapLoadException { return mapLoader.loadMainGrid(playerSettings, startResources); }
@Override public MainGridWithUiSettings loadMainGrid(PlayerSetting[] playerSettings) throws MapLoadException { return mapLoader.loadMainGrid(playerSettings); }
@Test public void testSpeed() throws MapLoadException, InterruptedException { MatchConstants.init(new NetworkTimer(true), 0); MainGrid grid = MapUtils.getBigMap().loadMainGrid(null).getMainGrid(); MainGridDataAccessor gridAccessor = new MainGridDataAccessor(grid); short width = gridAccessor.getWidth(); short height = gridAccessor.getHeight(); BitSet notBlockingSet = new BitSet(width * height); LandscapeGrid landscapeGrid = gridAccessor.getLandscapeGrid(); for (short y = 0; y < height; y++) { for (short x = 0; x < width; x++) { notBlockingSet.set(x + y * width, !landscapeGrid.getLandscapeTypeAt(x, y).isBlocking); } } Thread.sleep(500L); MilliStopWatch watch = new MilliStopWatch(); PartitionCalculatorAlgorithm partitioner = new PartitionCalculatorAlgorithm(0, 0, width, height, notBlockingSet, IBlockingProvider.DEFAULT_IMPLEMENTATION); partitioner.calculatePartitions(); System.out.println("\n\n\n\nnumber of partitions: " + partitioner.getNumberOfPartitions()); watch.stop("partitioning test needed:"); } }
@Test public void testIfSavegameOfSavegameEqualsSavegame() throws IOException, MapLoadException, ClassNotFoundException, InterruptedException { final byte playerId = 0; final int targetTimeMinutes = 30; MapLoader map = MapUtils.getMountainlake(); ReplayUtils.PlayMapResult directSavegameReplay = ReplayUtils.playMapToTargetTimes(map, playerId, targetTimeMinutes); assertDirectSavegameReplay(1, directSavegameReplay); MapLoader savegame = directSavegameReplay.getSavegames()[0]; Thread.sleep(2000L); // loading + saving might happend in less than a second => make sure the next savegame is saved with a different name System.out.println("Loading savegame..."); MatchConstants.init(new NetworkTimer(true), 0L); MainGridWithUiSettings loadedMap = savegame.loadMainGrid(PlayerSetting.createDefaultSettings(playerId, (byte) savegame.getMaxPlayers())); MainGrid mainGrid = loadedMap.getMainGrid(); PlayerState playerState = loadedMap.getPlayerState(playerId); mainGrid.initForPlayer(playerId, playerState.getFogOfWar()); MapLoader savegameOfSavegame; try { System.out.println("Creating savegame of savegame..."); savegameOfSavegame = MapUtils.saveMainGrid(mainGrid, playerId, playerState.getUiState()); assertNotNull(savegameOfSavegame); } finally { mainGrid.stopThreads(); JSettlersGame.clearState(); } // compare direct savegame with replayed savegame. MapUtils.compareMapFiles(savegame, savegameOfSavegame); }
@Test public void testCompareOldAndNew() throws MapLoadException { MatchConstants.init(new NetworkTimer(true), 0); MainGrid grid = MapUtils.getBigMap().loadMainGrid(null).getMainGrid(); MainGridDataAccessor gridAccessor = new MainGridDataAccessor(grid); short width = gridAccessor.getWidth(); short height = gridAccessor.getHeight(); BitSet notBlockingSet = new BitSet(width * height); LandscapeGrid landscapeGrid = gridAccessor.getLandscapeGrid(); for (short y = 0; y < height; y++) { for (short x = 0; x < width; x++) { notBlockingSet.set(x + y * width, !landscapeGrid.getLandscapeTypeAt(x, y).isBlocking); } } PartitionCalculatorAlgorithm partitioner = new PartitionCalculatorAlgorithm(0, 0, width, height, notBlockingSet, IBlockingProvider.DEFAULT_IMPLEMENTATION); partitioner.calculatePartitions(); // System.out.println("\n\n\n\nnumber of partitions: " + partitioner.getNumberOfPartitions()); for (short y = 0; y < height; y++) { for (short x = 0; x < width; x++) { assertEquals(gridAccessor.getLandscapeGrid().getBlockedPartitionAt(x, y), partitioner.getPartitionAt(x, y)); } } } }