Program: 55654
Project: 55654
Buggy source:
private int[] calculateBuildingCounts(int numberOfWeaponSmiths,int maxFishermen,int maxGoldMelts,int maxWineGrower,int maxBigTemples,long grassTiles){
  int[] buildingCounts=new int[EBuildingType.NUMBER_OF_BUILDINGS];
  for (int i=0; i < buildingCounts.length; i++) {
    buildingCounts[i]=0;
  }
  buildingCounts[EBuildingType.COALMINE.ordinal]=numberOfWeaponSmiths;
  buildingCounts[EBuildingType.IRONMINE.ordinal]=Math.round(numberOfWeaponSmiths / COAL_MINE_TO_IRON_MINE_RATIO + 1);
  buildingCounts[EBuildingType.IRONMELT.ordinal]=numberOfWeaponSmiths;
  buildingCounts[EBuildingType.WEAPONSMITH.ordinal]=numberOfWeaponSmiths;
  buildingCounts[EBuildingType.BARRACK.ordinal]=(int)Math.ceil((double)numberOfWeaponSmiths / WEAPON_SMITH_TO_BARRACKS_RATIO);
  buildingCounts[EBuildingType.TOOLSMITH.ordinal]=1;
  int numberOfFisher=Math.min((int)(numberOfWeaponSmiths / WEAPON_SMITH_TO_FISHER_HUT_RATIO),maxFishermen);
  buildingCounts[EBuildingType.FISHER.ordinal]=numberOfFisher;
  int numberOfRemainingWeaponSmiths=Math.max(0,numberOfWeaponSmiths - (int)(numberOfFisher * WEAPON_SMITH_TO_FISHER_HUT_RATIO));
  int numberOfFarms=(int)Math.ceil(numberOfRemainingWeaponSmiths / WEAPON_SMITH_TO_FARM_RATIO);
  buildingCounts[EBuildingType.FARM.ordinal]=numberOfFarms;
  buildingCounts[EBuildingType.BAKER.ordinal]=(int)Math.ceil(numberOfFarms / FARM_TO_BAKER_RATIO);
  buildingCounts[EBuildingType.MILL.ordinal]=(int)Math.ceil(numberOfFarms / FARM_TO_MILL_RATIO);
  buildingCounts[EBuildingType.WATERWORKS.ordinal]=(int)Math.ceil(numberOfFarms / FARM_TO_WATERWORKS_RATIO);
  buildingCounts[EBuildingType.SLAUGHTERHOUSE.ordinal]=(int)Math.ceil(numberOfFarms / FARM_TO_SLAUGHTER_RATIO);
  buildingCounts[EBuildingType.PIG_FARM.ordinal]=(int)Math.ceil(numberOfFarms / FARM_TO_PIG_FARM_RATIO);
  int lumberJacksForWeaponSmiths=Math.max(8,(int)(numberOfWeaponSmiths / WEAPON_SMITH_TO_LUMBERJACK_RATIO));
  int maxLumberJacksForMap=Math.round((float)grassTiles / GRASS_TO_LUMBERJACK_RATIO);
  int numberOfLumberJacks=Math.max(MIN_LUMBERJACK_COUNT,Math.min(maxLumberJacksForMap,lumberJacksForWeaponSmiths));
  buildingCounts[EBuildingType.LUMBERJACK.ordinal]=numberOfLumberJacks;
  buildingCounts[EBuildingType.FORESTER.ordinal]=Math.max((int)(numberOfLumberJacks / LUMBERJACK_TO_FORESTER_RATIO),1);
  buildingCounts[EBuildingType.SAWMILL.ordinal]=Math.max((int)(numberOfLumberJacks / LUMBERJACK_TO_SAWMILL_RATIO),1);
  buildingCounts[EBuildingType.STONECUTTER.ordinal]=Math.max((int)(numberOfLumberJacks / LUMBERJACK_TO_STONE_CUTTER_RATIO),1);
  if (maxGoldMelts > 0) {
    buildingCounts[EBuildingType.GOLDMELT.ordinal]=maxGoldMelts;
    buildingCounts[EBuildingType.GOLDMINE.ordinal]=1;
  }
  if (maxBigTemples > 0) {
    buildingCounts[EBuildingType.BIG_TEMPLE.ordinal]=maxBigTemples;
  }
  if (maxWineGrower > 0) {
    buildingCounts[EBuildingType.WINEGROWER.ordinal]=maxWineGrower;
    buildingCounts[EBuildingType.TEMPLE.ordinal]=maxWineGrower;
  }
  if (isEnoughSpace(buildingCounts,grassTiles)) {
    return buildingCounts;
  }
 else   if (numberOfWeaponSmiths > MIN_SMITHS_BEFORE_WINE_AND_GOLD_REDUCTION) {
    return calculateBuildingCounts(numberOfWeaponSmiths - 1,maxFishermen,maxGoldMelts,maxWineGrower,maxBigTemples,grassTiles);
  }
 else   if (maxWineGrower > MIN_WINE_GROWER_BEFORE_GOLD_REDUCTION) {
    return calculateBuildingCounts(numberOfWeaponSmiths,maxFishermen,maxGoldMelts,maxWineGrower - 1,maxBigTemples,grassTiles);
  }
 else   if (maxGoldMelts > 1) {
    return calculateBuildingCounts(numberOfWeaponSmiths,maxFishermen,maxGoldMelts - 1,maxWineGrower,maxBigTemples,grassTiles);
  }
 else   if (maxWineGrower > 1) {
    return calculateBuildingCounts(numberOfWeaponSmiths,maxFishermen,maxGoldMelts,maxWineGrower - 1,maxBigTemples,grassTiles);
  }
 else   if (maxBigTemples == 1) {
    return calculateBuildingCounts(numberOfWeaponSmiths,maxFishermen,maxGoldMelts,maxWineGrower,0,grassTiles);
  }
 else {
    return calculateBuildingCounts(numberOfWeaponSmiths - 1,maxFishermen,maxGoldMelts,maxWineGrower,0,grassTiles);
  }
}

Fixed version (ground truth):
private int[] calculateBuildingCounts(int numberOfWeaponSmiths,int maxFishermen,int maxGoldMelts,int maxWineGrowers,int maxBigTemples,long grassTiles){
  int[] buildingCounts=new int[EBuildingType.NUMBER_OF_BUILDINGS];
  for (int i=0; i < buildingCounts.length; i++) {
    buildingCounts[i]=0;
  }
  buildingCounts[EBuildingType.COALMINE.ordinal]=numberOfWeaponSmiths;
  buildingCounts[EBuildingType.IRONMINE.ordinal]=Math.round(numberOfWeaponSmiths / COAL_MINE_TO_IRON_MINE_RATIO + 1);
  buildingCounts[EBuildingType.IRONMELT.ordinal]=numberOfWeaponSmiths;
  buildingCounts[EBuildingType.WEAPONSMITH.ordinal]=numberOfWeaponSmiths;
  buildingCounts[EBuildingType.BARRACK.ordinal]=(int)Math.ceil((double)numberOfWeaponSmiths / WEAPON_SMITH_TO_BARRACKS_RATIO);
  buildingCounts[EBuildingType.TOOLSMITH.ordinal]=1;
  int numberOfFisher=Math.min((int)(numberOfWeaponSmiths / WEAPON_SMITH_TO_FISHER_HUT_RATIO),maxFishermen);
  buildingCounts[EBuildingType.FISHER.ordinal]=numberOfFisher;
  int numberOfRemainingWeaponSmiths=Math.max(0,numberOfWeaponSmiths - (int)(numberOfFisher * WEAPON_SMITH_TO_FISHER_HUT_RATIO));
  int numberOfFarms=(int)Math.ceil(numberOfRemainingWeaponSmiths / WEAPON_SMITH_TO_FARM_RATIO);
  buildingCounts[EBuildingType.FARM.ordinal]=numberOfFarms;
  buildingCounts[EBuildingType.BAKER.ordinal]=(int)Math.ceil(numberOfFarms / FARM_TO_BAKER_RATIO);
  buildingCounts[EBuildingType.MILL.ordinal]=(int)Math.ceil(numberOfFarms / FARM_TO_MILL_RATIO);
  buildingCounts[EBuildingType.WATERWORKS.ordinal]=(int)Math.ceil(numberOfFarms / FARM_TO_WATERWORKS_RATIO);
  buildingCounts[EBuildingType.SLAUGHTERHOUSE.ordinal]=(int)Math.ceil(numberOfFarms / FARM_TO_SLAUGHTER_RATIO);
  buildingCounts[EBuildingType.PIG_FARM.ordinal]=(int)Math.ceil(numberOfFarms / FARM_TO_PIG_FARM_RATIO);
  int lumberJacksForWeaponSmiths=Math.max(8,(int)(numberOfWeaponSmiths / WEAPON_SMITH_TO_LUMBERJACK_RATIO));
  int maxLumberJacksForMap=Math.round((float)grassTiles / GRASS_TO_LUMBERJACK_RATIO);
  int numberOfLumberJacks=Math.max(MIN_LUMBERJACK_COUNT,Math.min(maxLumberJacksForMap,lumberJacksForWeaponSmiths));
  buildingCounts[EBuildingType.LUMBERJACK.ordinal]=numberOfLumberJacks;
  buildingCounts[EBuildingType.FORESTER.ordinal]=Math.max((int)(numberOfLumberJacks / LUMBERJACK_TO_FORESTER_RATIO),1);
  buildingCounts[EBuildingType.SAWMILL.ordinal]=Math.max((int)(numberOfLumberJacks / LUMBERJACK_TO_SAWMILL_RATIO),1);
  buildingCounts[EBuildingType.STONECUTTER.ordinal]=Math.max((int)(numberOfLumberJacks / LUMBERJACK_TO_STONE_CUTTER_RATIO),1);
  if (maxGoldMelts > 0) {
    buildingCounts[EBuildingType.GOLDMELT.ordinal]=maxGoldMelts;
    buildingCounts[EBuildingType.GOLDMINE.ordinal]=1;
  }
  if (maxBigTemples > 0) {
    buildingCounts[EBuildingType.BIG_TEMPLE.ordinal]=maxBigTemples;
  }
  if (maxWineGrowers > 0) {
    buildingCounts[EBuildingType.WINEGROWER.ordinal]=maxWineGrowers;
    buildingCounts[EBuildingType.TEMPLE.ordinal]=maxWineGrowers;
  }
  if (isEnoughSpace(buildingCounts,grassTiles)) {
    return buildingCounts;
  }
 else   if (numberOfWeaponSmiths > MIN_SMITHS_BEFORE_WINE_AND_GOLD_REDUCTION) {
    return calculateBuildingCounts(numberOfWeaponSmiths - 1,maxFishermen,maxGoldMelts,maxWineGrowers,maxBigTemples,grassTiles);
  }
 else   if (maxWineGrowers > MIN_WINE_GROWER_BEFORE_GOLD_REDUCTION) {
    return calculateBuildingCounts(numberOfWeaponSmiths,maxFishermen,maxGoldMelts,maxWineGrowers - 1,maxBigTemples,grassTiles);
  }
 else   if (maxGoldMelts > 1) {
    return calculateBuildingCounts(numberOfWeaponSmiths,maxFishermen,maxGoldMelts - 1,maxWineGrowers,maxBigTemples,grassTiles);
  }
 else   if (maxWineGrowers > 1) {
    return calculateBuildingCounts(numberOfWeaponSmiths,maxFishermen,maxGoldMelts,maxWineGrowers - 1,maxBigTemples,grassTiles);
  }
 else   if (maxBigTemples > 1) {
    return calculateBuildingCounts(numberOfWeaponSmiths,maxFishermen,maxGoldMelts,maxWineGrowers,0,grassTiles);
  }
 else   if (maxWineGrowers > 0) {
    return calculateBuildingCounts(numberOfWeaponSmiths,maxFishermen,maxGoldMelts,maxWineGrowers - 1,0,grassTiles);
  }
 else   if (maxFishermen > 0) {
    return calculateBuildingCounts(numberOfWeaponSmiths,maxFishermen - 1,maxGoldMelts,maxWineGrowers,0,grassTiles);
  }
 else   if (numberOfWeaponSmiths > 0) {
    return calculateBuildingCounts(numberOfWeaponSmiths - 1,maxFishermen,maxGoldMelts,maxWineGrowers,0,grassTiles);
  }
 else {
    return new int[EBuildingType.NUMBER_OF_BUILDINGS];
  }
}