/** * Sets up the map. Make every region neutral with 2 armies to start with. Adds wastelands (> 2 * armies on a neutral) if wastelandSize > 0. * * @param initMap : the map object that hasn't been set up yet, i.e. no armies yet * @param wastelandSize : the amount of armies that a wasteland contains * @return : the fully initialized and setup Map object */ public static Map setupMap(Map initMap, int wastelandSize) { Map map = initMap; for (Region region : map.regions) { region.setPlayerName("neutral"); region.setArmies(2); } if (wastelandSize > 0) { int nrOfWastelands = (int) (map.getSuperRegions().size() / 2); // amount of wastelands is half of the amount of superRegions for (int i = 0; i < nrOfWastelands; i++) { double rand = Math.random(); int index = (int) (rand * map.getRegions().size()); Region wasteland = map.getRegions().get(index); if (wasteland.getArmies() > 2 && !roomForWasteland(wasteland.getSuperRegion())) { i--; continue; } wasteland.setArmies(wastelandSize); } } return map; }
/** * @param map * @return : the string representation of given map's regions */ private static String getRegionsString(Map map) { String regionsString = "setup_map regions"; for (Region region : map.regions) { int id = region.getId(); int superRegionId = region.getSuperRegion().getId(); regionsString = regionsString.concat(" " + id + " " + superRegionId); } return regionsString; }