Program: 39144
Project: 39144
Buggy source:
/** 
 * puts the current unit into all substrates where it should go according to parameters.
 * @param u unit to be put into substrates
 * @param substrates array containing all substrates. this array is modified and then returned
 * @param substrateSize how big each substrate is
 * @param location index within an individual substrate
 * @return double[] input as substrates, but with the unit added at location for every appropriate substrate
 */
private double[] populateSubstratesWith(Unit u,boolean isTerrain,double[] substrates,int location){
  ArrayList<Integer> appropriateSubstrates=new ArrayList<>();
  ArrayList<Integer> subIDs=new ArrayList<>();
  int numCurrentSubs=0;
  if (u != null) {
    if (areSubsActive[mobile]) {
      if (u.getType().canMove) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(mobile);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[buildings]) {
      if (!u.getType().canMove && u.getPlayer() != -1) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(buildings);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[myMobile]) {
      if (u.getType().canMove && u.getPlayer() == 0) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(myMobile);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[myBuildings]) {
      if (!u.getType().canMove && u.getPlayer() != 1) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(myBuildings);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[oppsMobile]) {
      if (u.getType().canMove && u.getPlayer() == 1) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(oppsMobile);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[oppsBuildings]) {
      if (!u.getType().canMove && u.getPlayer() != 0) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(oppsBuildings);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[myAll]) {
      if (u.getPlayer() == 0) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(myAll);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[oppsAll]) {
      if (u.getPlayer() == 1) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(oppsAll);
      }
      numCurrentSubs++;
    }
  }
  if (areSubsActive[all]) {
    appropriateSubstrates.add(numCurrentSubs);
    subIDs.add(all);
    numCurrentSubs++;
  }
  if (areSubsActive[neutral]) {
    if (isTerrain || (u != null && u.getPlayer() == -1)) {
      appropriateSubstrates.add(numCurrentSubs);
      subIDs.add(neutral);
    }
    numCurrentSubs++;
  }
  if (areSubsActive[terrain]) {
    if (isTerrain) {
      appropriateSubstrates.add(numCurrentSubs);
      subIDs.add(terrain);
    }
    numCurrentSubs++;
  }
  double[] pathSub=new double[pgs.getWidth() * pgs.getHeight()];
  if (areSubsActive[path]) {
    appropriateSubstrates.add(numCurrentSubs);
    subIDs.add(path);
    if (u != null && u.getType().name.equals("String_Node_Str")) {
      activate(location,1,pathSub,pgs.getWidth());
    }
 else     if (isTerrain) {
      activate(location,-1,pathSub,pgs.getWidth());
    }
  }
  for (int i=0; i < appropriateSubstrates.size(); i++) {
    int indexWithinAll=(substrateSize * appropriateSubstrates.get(i)) + location;
    int subID=subIDs.get(i);
    if (subID == path) {
      int subStart=indexWithinAll - location;
      for (int j=subStart; j < subStart + substrateSize; j++) {
        substrates[j]=pathSub[j - subStart];
      }
    }
 else {
      substrates[indexWithinAll]=getWeightedValue(subID,u,isTerrain);
    }
  }
  return substrates;
}

Fixed version (ground truth):
/** 
 * puts the current unit into all substrates where it should go according to parameters.
 * @param u unit to be put into substrates
 * @param substrates array containing all substrates. this array is modified and then returned
 * @param substrateSize how big each substrate is
 * @param location index within an individual substrate
 * @return double[] input as substrates, but with the unit added at location for every appropriate substrate
 */
private double[] populateSubstratesWith(Unit u,boolean isTerrain,double[] substrates,int location){
  ArrayList<Integer> appropriateSubstrates=new ArrayList<>();
  ArrayList<Integer> subIDs=new ArrayList<>();
  int numCurrentSubs=0;
  if (u != null) {
    if (areSubsActive[mobile]) {
      if (u.getType().canMove) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(mobile);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[buildings]) {
      if (!u.getType().canMove && u.getPlayer() != -1) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(buildings);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[myMobile]) {
      if (u.getType().canMove && u.getPlayer() == 0) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(myMobile);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[myBuildings]) {
      if (!u.getType().canMove && u.getPlayer() != 1) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(myBuildings);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[oppsMobile]) {
      if (u.getType().canMove && u.getPlayer() == 1) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(oppsMobile);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[oppsBuildings]) {
      if (!u.getType().canMove && u.getPlayer() != 0) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(oppsBuildings);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[myAll]) {
      if (u.getPlayer() == 0) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(myAll);
      }
      numCurrentSubs++;
    }
    if (areSubsActive[oppsAll]) {
      if (u.getPlayer() == 1) {
        appropriateSubstrates.add(numCurrentSubs);
        subIDs.add(oppsAll);
      }
      numCurrentSubs++;
    }
  }
  if (areSubsActive[all]) {
    appropriateSubstrates.add(numCurrentSubs);
    subIDs.add(all);
    numCurrentSubs++;
  }
  if (areSubsActive[neutral]) {
    if (isTerrain || (u != null && u.getPlayer() == -1)) {
      appropriateSubstrates.add(numCurrentSubs);
      subIDs.add(neutral);
    }
    numCurrentSubs++;
  }
  if (areSubsActive[terrain]) {
    if (isTerrain) {
      appropriateSubstrates.add(numCurrentSubs);
      subIDs.add(terrain);
    }
    numCurrentSubs++;
  }
  double[] pathSub=new double[pgs.getWidth() * pgs.getHeight()];
  if (areSubsActive[path]) {
    appropriateSubstrates.add(numCurrentSubs);
    subIDs.add(path);
    if (u != null && u.getType().name.equals("String_Node_Str")) {
      pathSub=activate(location,1,pathSub,pgs.getWidth());
    }
 else     if (isTerrain) {
      pathSub=activate(location,-1,pathSub,pgs.getWidth());
    }
    numCurrentSubs++;
  }
  for (int i=0; i < appropriateSubstrates.size(); i++) {
    int indexWithinAll=(substrateSize * appropriateSubstrates.get(i)) + location;
    int subID=subIDs.get(i);
    if (subID == path) {
      int subStart=indexWithinAll - location;
      for (int j=subStart; j < subStart + substrateSize; j++) {
        substrates[j]=pathSub[j - subStart];
      }
    }
 else {
      System.out.println(substrates.length);
      substrates[indexWithinAll]=getWeightedValue(subID,u,isTerrain);
    }
  }
  return substrates;
}