예제 #1
0
  /**
   * 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;
  }
예제 #2
0
  /**
   * Determines how much rounds a game can take before it's a draw, depending on map size
   *
   * @param map : the created map
   * @return : the maximum number of rounds for this game
   */
  public static int determineMaxRounds(Map map) {

    return (int)
        Math.max(
            60,
            map.getRegions().size()
                * 2.5); // minimum of 60, otherwise 2.5 times the number of regions
  }
예제 #3
0
 /**
  * @param map
  * @return : the string representation of given map's wastelands
  */
 private static String getWastelandsString(Map map) {
   String wastelandsString = "setup_map wastelands";
   for (Region region : map.getRegions()) {
     if (region.getArmies() > 2) {
       int id = region.getId();
       wastelandsString = wastelandsString.concat(" " + id);
     }
   }
   return wastelandsString;
 }