Program: 55740
Project: 55740
Buggy source:
private void destroyBuildings(){
  for (  ShortPoint2D stoneCutterPosition : aiStatistics.getBuildingPositionsOfTypeForPlayer(STONECUTTER,playerId)) {
    if (aiStatistics.getBuildingAt(stoneCutterPosition).cannotWork()) {
      int numberOfStoneCutters=aiStatistics.getNumberOfBuildingTypeForPlayer(STONECUTTER,playerId);
      if (numberOfStoneCutters == 1) {
        ShortPoint2D nearestStone=aiStatistics.getStonesForPlayer(playerId).getNearestPoint(stoneCutterPosition);
        if (nearestStone != null) {
          taskScheduler.scheduleTask(new WorkAreaGuiTask(EGuiAction.SET_WORK_AREA,playerId,nearestStone,stoneCutterPosition));
        }
      }
 else {
        ShortPoint2D nearestStone=aiStatistics.getStonesForPlayer(playerId).getNearestPoint(stoneCutterPosition,STONECUTTER.getWorkRadius() * MAXIMUM_STONECUTTER_WORK_RADIUS_FACTOR,null);
        if (nearestStone != null && numberOfStoneCutters < economyMinister.getMidGameNumberOfStoneCutters()) {
          taskScheduler.scheduleTask(new WorkAreaGuiTask(EGuiAction.SET_WORK_AREA,playerId,nearestStone,stoneCutterPosition));
        }
 else {
          taskScheduler.scheduleTask(new DestroyBuildingGuiTask(playerId,stoneCutterPosition));
          break;
        }
      }
    }
  }
  if (economyMinister.automaticLivingHousesEnabled()) {
    int numberOfFreeBeds=aiStatistics.getNumberOfBuildingTypeForPlayer(EBuildingType.SMALL_LIVINGHOUSE,playerId) * NUMBER_OF_SMALL_LIVINGHOUSE_BEDS + aiStatistics.getNumberOfBuildingTypeForPlayer(EBuildingType.MEDIUM_LIVINGHOUSE,playerId) * NUMBER_OF_MEDIUM_LIVINGHOUSE_BEDS + aiStatistics.getNumberOfBuildingTypeForPlayer(EBuildingType.BIG_LIVINGHOUSE,playerId) * NUMBER_OF_BIG_LIVINGHOUSE_BEDS - aiStatistics.getMovablePositionsByTypeForPlayer(EMovableType.BEARER,playerId).size();
    if (numberOfFreeBeds >= NUMBER_OF_SMALL_LIVINGHOUSE_BEDS + 1 && !destroyLivingHouse(SMALL_LIVINGHOUSE)) {
      if (numberOfFreeBeds >= NUMBER_OF_MEDIUM_LIVINGHOUSE_BEDS + 1 && !destroyLivingHouse(MEDIUM_LIVINGHOUSE)) {
        if (numberOfFreeBeds >= NUMBER_OF_BIG_LIVINGHOUSE_BEDS + 1) {
          destroyLivingHouse(BIG_LIVINGHOUSE);
        }
      }
    }
  }
  if (isEndGame && isWoodJam()) {
    List<ShortPoint2D> forresters=aiStatistics.getBuildingPositionsOfTypeForPlayer(FORESTER,playerId);
    if (forresters.size() > 1) {
      for (int i=1; i < forresters.size(); i++) {
        taskScheduler.scheduleTask(new DestroyBuildingGuiTask(playerId,forresters.get(i)));
      }
    }
    for (    ShortPoint2D lumberJackPosition : aiStatistics.getBuildingPositionsOfTypeForPlayer(LUMBERJACK,playerId)) {
      if (aiStatistics.getBuildingAt(lumberJackPosition).cannotWork()) {
        taskScheduler.scheduleTask(new DestroyBuildingGuiTask(playerId,lumberJackPosition));
      }
    }
    if ((aiStatistics.getNumberOfBuildingTypeForPlayer(SAWMILL,playerId) * 3 - 2) > aiStatistics.getNumberOfBuildingTypeForPlayer(LUMBERJACK,playerId)) {
      taskScheduler.scheduleTask(new DestroyBuildingGuiTask(playerId,aiStatistics.getBuildingPositionsOfTypeForPlayer(SAWMILL,playerId).get(0)));
    }
    for (    ShortPoint2D bigTemple : aiStatistics.getBuildingPositionsOfTypeForPlayer(BIG_TEMPLE,playerId)) {
      taskScheduler.scheduleTask(new DestroyBuildingGuiTask(playerId,bigTemple));
    }
  }
}

Fixed version (ground truth):
private void destroyBuildings(){
  for (  ShortPoint2D stoneCutterPosition : aiStatistics.getBuildingPositionsOfTypeForPlayer(STONECUTTER,playerId)) {
    if (aiStatistics.getBuildingAt(stoneCutterPosition).cannotWork()) {
      int numberOfStoneCutters=aiStatistics.getNumberOfBuildingTypeForPlayer(STONECUTTER,playerId);
      ShortPoint2D nearestStone=aiStatistics.getStonesForPlayer(playerId).getNearestPoint(stoneCutterPosition,STONECUTTER.getWorkRadius() * MAXIMUM_STONECUTTER_WORK_RADIUS_FACTOR,null);
      if (nearestStone != null && numberOfStoneCutters < economyMinister.getMidGameNumberOfStoneCutters()) {
        taskScheduler.scheduleTask(new WorkAreaGuiTask(EGuiAction.SET_WORK_AREA,playerId,nearestStone,stoneCutterPosition));
      }
 else {
        taskScheduler.scheduleTask(new DestroyBuildingGuiTask(playerId,stoneCutterPosition));
        break;
      }
    }
  }
  if (economyMinister.automaticLivingHousesEnabled()) {
    int numberOfFreeBeds=aiStatistics.getNumberOfBuildingTypeForPlayer(EBuildingType.SMALL_LIVINGHOUSE,playerId) * NUMBER_OF_SMALL_LIVINGHOUSE_BEDS + aiStatistics.getNumberOfBuildingTypeForPlayer(EBuildingType.MEDIUM_LIVINGHOUSE,playerId) * NUMBER_OF_MEDIUM_LIVINGHOUSE_BEDS + aiStatistics.getNumberOfBuildingTypeForPlayer(EBuildingType.BIG_LIVINGHOUSE,playerId) * NUMBER_OF_BIG_LIVINGHOUSE_BEDS - aiStatistics.getMovablePositionsByTypeForPlayer(EMovableType.BEARER,playerId).size();
    if (numberOfFreeBeds >= NUMBER_OF_SMALL_LIVINGHOUSE_BEDS + 1 && !destroyLivingHouse(SMALL_LIVINGHOUSE)) {
      if (numberOfFreeBeds >= NUMBER_OF_MEDIUM_LIVINGHOUSE_BEDS + 1 && !destroyLivingHouse(MEDIUM_LIVINGHOUSE)) {
        if (numberOfFreeBeds >= NUMBER_OF_BIG_LIVINGHOUSE_BEDS + 1) {
          destroyLivingHouse(BIG_LIVINGHOUSE);
        }
      }
    }
  }
  if (isEndGame && isWoodJam()) {
    List<ShortPoint2D> forresters=aiStatistics.getBuildingPositionsOfTypeForPlayer(FORESTER,playerId);
    if (forresters.size() > 1) {
      for (int i=1; i < forresters.size(); i++) {
        taskScheduler.scheduleTask(new DestroyBuildingGuiTask(playerId,forresters.get(i)));
      }
    }
    for (    ShortPoint2D lumberJackPosition : aiStatistics.getBuildingPositionsOfTypeForPlayer(LUMBERJACK,playerId)) {
      if (aiStatistics.getBuildingAt(lumberJackPosition).cannotWork()) {
        taskScheduler.scheduleTask(new DestroyBuildingGuiTask(playerId,lumberJackPosition));
      }
    }
    if ((aiStatistics.getNumberOfBuildingTypeForPlayer(SAWMILL,playerId) * 3 - 2) > aiStatistics.getNumberOfBuildingTypeForPlayer(LUMBERJACK,playerId)) {
      taskScheduler.scheduleTask(new DestroyBuildingGuiTask(playerId,aiStatistics.getBuildingPositionsOfTypeForPlayer(SAWMILL,playerId).get(0)));
    }
    for (    ShortPoint2D bigTemple : aiStatistics.getBuildingPositionsOfTypeForPlayer(BIG_TEMPLE,playerId)) {
      taskScheduler.scheduleTask(new DestroyBuildingGuiTask(playerId,bigTemple));
    }
  }
}