Program: 37963
Project: 37963
Buggy source:
/** 
 * Splits the sublevel recursively until it builds rooms, then connects the rooms together In the end, curr is populated with the current hallways and rooms
 */
private void splitAndBuild(SubLevel curr){
  boolean makeRoom=false;
  int splitAttempts=0;
  if (curr.depth == depthMax) {
    makeRoom=true;
  }
  if (makeRoom) {
    makeRoom(curr);
  }
 else {
    Split s=(rand.getRandom(2) == 0) ? Split.VER : Split.HOR;
    if (s == Split.HOR) {
      float height=(curr.max.y - curr.min.y);
      if (height < 4 * minWallThickness + 2 * minRoomDim) {
        s=Split.VER;
      }
    }
 else {
      float width=(curr.max.x - curr.min.x);
      if (width < 4 * minWallThickness + 2 * minRoomDim) {
        s=Split.HOR;
      }
    }
    SubLevel s1, s2;
    if (s == Split.HOR) {
      float height=(curr.max.y - curr.min.y);
      if (height < 4 * minWallThickness + 2 * minRoomDim) {
        makeRoom(curr);
        return;
      }
      int splitVal=Math.round(curr.min.y + height * splitMin + rand.getRandom(Math.round((height * (splitMax - splitMin)))));
      while (splitVal - curr.min.y < 2 * minWallThickness + minRoomDim || curr.max.y - splitVal - 1 < 2 * minWallThickness + minRoomDim) {
        if (splitAttempts >= splitTries) {
          makeRoom(curr);
          return;
        }
        splitAttempts++;
        splitVal=Math.round(curr.min.y + height * splitMin + rand.getRandom(Math.round((height * (splitMax - splitMin)))));
      }
      s1=new SubLevel(new Vec2i(curr.min.x,curr.min.y),new Vec2i(curr.max.x,splitVal),curr.depth + 1);
      s2=new SubLevel(new Vec2i(curr.min.x,splitVal + 1),new Vec2i(curr.max.x,curr.max.y),curr.depth + 1);
    }
 else {
      float width=(curr.max.x - curr.min.x);
      if (width < 4 * minWallThickness + 2 * minRoomDim) {
        makeRoom(curr);
        return;
      }
      int maxVal=Math.round((width * (splitMax - splitMin)));
      int splitVal=Math.round(curr.min.x + width * splitMin + rand.getRandom(maxVal));
      while (splitVal - curr.min.x < 2 * minWallThickness + minRoomDim || curr.max.x - splitVal - 1 < 2 * minWallThickness + minRoomDim) {
        if (splitAttempts >= splitTries) {
          makeRoom(curr);
          return;
        }
        splitAttempts++;
        maxVal=Math.round((width * (splitMax - splitMin)));
        splitVal=Math.round(curr.min.x + width * splitMin + rand.getRandom(maxVal));
      }
      s1=new SubLevel(new Vec2i(curr.min.x,curr.min.y),new Vec2i(splitVal,curr.max.y),curr.depth + 1);
      s2=new SubLevel(new Vec2i(splitVal + 1,curr.min.y),new Vec2i(curr.max.x,curr.max.y),curr.depth + 1);
    }
    splitAndBuild(s1);
    splitAndBuild(s2);
    Range range=s1.overLap(s2,s);
    if (range != null) {
      int hpt;
      HallwayPoint hp1;
      HallwayPoint hp2;
      do {
        hpt=rand.getRandom(range.min,range.max);
        hp1=s1.getHallwayPoint(s,true,hpt);
        hp2=s2.getHallwayPoint(s,false,hpt);
      }
 while (!testHallway(hp1.point,hp2.point));
      Hallway new_hallway=new Hallway(hp1.point,hp2.point);
      paintHallway(hp1.point,hp2.point,true,TileType.FLOOR);
      hp1.space.connectToHallway(new_hallway);
      hp2.space.connectToHallway(new_hallway);
      if (hp1.space.needDoor())       makeDoor(hp1.point,s,true);
      if (hp2.space.needDoor())       makeDoor(hp2.point,s,false);
      curr.hallways.add(new_hallway);
    }
 else {
      if (s == Split.HOR) {
        HallwayPoint hp1;
        HallwayPoint hp2;
        Vec2i corner;
        do {
          int cx=rand.getRandom(s1.intersectMin.x,s1.intersectMax.x);
          int cy=rand.getRandom(s2.intersectMin.y,s2.intersectMax.y);
          corner=new Vec2i(cx,cy);
          hp1=s1.getHallwayPoint(Split.HOR,true,cx);
          hp2=s2.getHallwayPoint(Split.VER,(s2.intersectMin.x < s1.intersectMax.x),cy);
        }
 while (!testHallway(hp1.point,corner) && !testHallway(hp2.point,corner));
        Hallway new_hallway1=new Hallway(hp1.point,corner);
        hp1.space.connectToHallway(new_hallway1);
        Hallway new_hallway2;
        if (s2.intersectMin.x > s1.intersectMax.x)         new_hallway2=new Hallway(hp2.point,corner);
 else         new_hallway2=new Hallway(corner,hp2.point);
        hp2.space.connectToHallway(new_hallway2);
        new_hallway1.connectToHallway(new_hallway2);
        paintHallway(hp1.point,corner,true,TileType.FLOOR);
        paintHallway(hp2.point,corner,true,TileType.FLOOR);
        if (hp1.space.needDoor())         makeDoor(hp1.point,s,true);
        if (hp2.space.needDoor())         makeDoor(hp2.point,s,false);
        curr.hallways.add(new_hallway1);
        curr.hallways.add(new_hallway2);
      }
 else {
        HallwayPoint hp1;
        HallwayPoint hp2;
        Vec2i corner;
        do {
          int cx=s1.intersectMin.x + rand.getRandom(s1.intersectMax.x - s1.intersectMin.x);
          int cy=s2.intersectMin.y + rand.getRandom(s2.intersectMax.y - s2.intersectMin.y);
          corner=new Vec2i(cx,cy);
          hp1=s1.getHallwayPoint(Split.HOR,(s1.intersectMin.y < s2.intersectMax.y),cx);
          hp2=s2.getHallwayPoint(Split.VER,false,cy);
        }
 while (!testHallway(hp1.point,corner) && !testHallway(hp2.point,corner));
        Hallway new_hallway1;
        if (s1.intersectMin.y < s2.intersectMax.y)         new_hallway1=new Hallway(hp1.point,corner);
 else         new_hallway1=new Hallway(corner,hp1.point);
        hp1.space.connectToHallway(new_hallway1);
        Hallway new_hallway2=new Hallway(corner,hp2.point);
        hp2.space.connectToHallway(new_hallway2);
        new_hallway1.connectToHallway(new_hallway2);
        paintHallway(hp1.point,corner,true,TileType.FLOOR);
        paintHallway(hp2.point,corner,true,TileType.FLOOR);
        curr.hallways.add(new_hallway1);
        curr.hallways.add(new_hallway2);
      }
    }
    curr.rooms.addAll(s1.rooms);
    curr.rooms.addAll(s2.rooms);
    curr.hallways.addAll(s1.hallways);
    curr.hallways.addAll(s2.hallways);
    int maxIX=Math.max(s1.intersectMax.x,s2.intersectMax.x);
    int maxIY=Math.max(s1.intersectMax.y,s2.intersectMax.y);
    int minIX=Math.min(s1.intersectMin.x,s2.intersectMin.x);
    int minIY=Math.min(s1.intersectMin.y,s2.intersectMin.y);
    curr.intersectMax=new Vec2i(maxIX,maxIY);
    curr.intersectMin=new Vec2i(minIX,minIY);
  }
}

Fixed version (ground truth):
/** 
 * Splits the sublevel recursively until it builds rooms, then connects the rooms together In the end, curr is populated with the current hallways and rooms
 */
private void splitAndBuild(SubLevel curr){
  boolean makeRoom=false;
  int splitAttempts=0;
  if (curr.depth == depthMax) {
    makeRoom=true;
  }
  if (makeRoom) {
    makeRoom(curr);
  }
 else {
    Split s=(rand.getRandom(2) == 0) ? Split.VER : Split.HOR;
    if (s == Split.HOR) {
      float height=(curr.max.y - curr.min.y);
      if (height < 4 * minWallThickness + 2 * minRoomDim) {
        s=Split.VER;
      }
    }
 else {
      float width=(curr.max.x - curr.min.x);
      if (width < 4 * minWallThickness + 2 * minRoomDim) {
        s=Split.HOR;
      }
    }
    SubLevel s1, s2;
    if (s == Split.HOR) {
      float height=(curr.max.y - curr.min.y);
      if (height < 4 * minWallThickness + 2 * minRoomDim) {
        makeRoom(curr);
        return;
      }
      int splitVal=Math.round(curr.min.y + height * splitMin + rand.getRandom(Math.round((height * (splitMax - splitMin)))));
      while (splitVal - curr.min.y < 2 * minWallThickness + minRoomDim || curr.max.y - splitVal - 1 < 2 * minWallThickness + minRoomDim) {
        if (splitAttempts >= splitTries) {
          makeRoom(curr);
          return;
        }
        splitAttempts++;
        splitVal=Math.round(curr.min.y + height * splitMin + rand.getRandom(Math.round((height * (splitMax - splitMin)))));
      }
      s1=new SubLevel(new Vec2i(curr.min.x,curr.min.y),new Vec2i(curr.max.x,splitVal),curr.depth + 1);
      s2=new SubLevel(new Vec2i(curr.min.x,splitVal + 1),new Vec2i(curr.max.x,curr.max.y),curr.depth + 1);
    }
 else {
      float width=(curr.max.x - curr.min.x);
      if (width < 4 * minWallThickness + 2 * minRoomDim) {
        makeRoom(curr);
        return;
      }
      int maxVal=Math.round((width * (splitMax - splitMin)));
      int splitVal=Math.round(curr.min.x + width * splitMin + rand.getRandom(maxVal));
      while (splitVal - curr.min.x < 2 * minWallThickness + minRoomDim || curr.max.x - splitVal - 1 < 2 * minWallThickness + minRoomDim) {
        if (splitAttempts >= splitTries) {
          makeRoom(curr);
          return;
        }
        splitAttempts++;
        maxVal=Math.round((width * (splitMax - splitMin)));
        splitVal=Math.round(curr.min.x + width * splitMin + rand.getRandom(maxVal));
      }
      s1=new SubLevel(new Vec2i(curr.min.x,curr.min.y),new Vec2i(splitVal,curr.max.y),curr.depth + 1);
      s2=new SubLevel(new Vec2i(splitVal + 1,curr.min.y),new Vec2i(curr.max.x,curr.max.y),curr.depth + 1);
    }
    splitAndBuild(s1);
    splitAndBuild(s2);
    Range range=s1.overLap(s2,s);
    if (range != null) {
      int hpt;
      HallwayPoint hp1;
      HallwayPoint hp2;
      do {
        hpt=rand.getRandom(range.min,range.max);
        hp1=s1.getHallwayPoint(s,true,hpt);
        hp2=s2.getHallwayPoint(s,false,hpt);
      }
 while (!testHallway(hp1.point,hp2.point));
      Hallway new_hallway=new Hallway(hp1.point,hp2.point);
      paintHallway(hp1.point,hp2.point,true,TileType.FLOOR);
      hp1.space.connectToHallway(new_hallway);
      hp2.space.connectToHallway(new_hallway);
      if (hp1.space.needDoor())       makeDoor(hp1.point,s,true);
      if (hp2.space.needDoor())       makeDoor(hp2.point,s,false);
      curr.hallways.add(new_hallway);
    }
 else {
      if (s == Split.HOR) {
        HallwayPoint hp1;
        HallwayPoint hp2;
        Vec2i corner;
        do {
          int cx=rand.getRandom(s1.intersectMin.x,s1.intersectMax.x);
          int cy=rand.getRandom(s2.intersectMin.y,s2.intersectMax.y);
          corner=new Vec2i(cx,cy);
          hp1=s1.getHallwayPoint(Split.HOR,true,cx);
          hp2=s2.getHallwayPoint(Split.VER,(s2.intersectMin.x < s1.intersectMax.x),cy);
        }
 while (!testHallway(hp1.point,corner) && !testHallway(hp2.point,corner));
        Hallway new_hallway1=new Hallway(hp1.point,corner);
        hp1.space.connectToHallway(new_hallway1);
        Hallway new_hallway2;
        if (s2.intersectMin.x > s1.intersectMax.x)         new_hallway2=new Hallway(hp2.point,corner);
 else         new_hallway2=new Hallway(corner,hp2.point);
        hp2.space.connectToHallway(new_hallway2);
        new_hallway1.connectToHallway(new_hallway2);
        paintHallway(hp1.point,corner,true,TileType.FLOOR);
        paintHallway(hp2.point,corner,true,TileType.FLOOR);
        if (hp1.space.needDoor())         makeDoor(hp1.point,s,true);
        if (hp2.space.needDoor())         makeDoor(hp2.point,s,false);
        curr.hallways.add(new_hallway1);
        curr.hallways.add(new_hallway2);
      }
 else {
        HallwayPoint hp1;
        HallwayPoint hp2;
        Vec2i corner;
        do {
          int cx=s1.intersectMin.x + rand.getRandom(s1.intersectMax.x - s1.intersectMin.x);
          int cy=s2.intersectMin.y + rand.getRandom(s2.intersectMax.y - s2.intersectMin.y);
          corner=new Vec2i(cx,cy);
          hp1=s1.getHallwayPoint(Split.HOR,(s1.intersectMin.y < s2.intersectMax.y),cx);
          hp2=s2.getHallwayPoint(Split.VER,false,cy);
        }
 while (!testHallway(hp1.point,corner) && !testHallway(hp2.point,corner));
        Hallway new_hallway1;
        if (s1.intersectMin.y < s2.intersectMax.y)         new_hallway1=new Hallway(hp1.point,corner);
 else         new_hallway1=new Hallway(corner,hp1.point);
        hp1.space.connectToHallway(new_hallway1);
        Hallway new_hallway2=new Hallway(corner,hp2.point);
        hp2.space.connectToHallway(new_hallway2);
        new_hallway1.connectToHallway(new_hallway2);
        paintHallway(hp1.point,corner,true,TileType.FLOOR);
        paintHallway(hp2.point,corner,true,TileType.FLOOR);
        if (hp1.space.needDoor())         makeDoor(hp1.point,s,true);
        if (hp2.space.needDoor())         makeDoor(hp2.point,s,false);
        curr.hallways.add(new_hallway1);
        curr.hallways.add(new_hallway2);
      }
    }
    curr.rooms.addAll(s1.rooms);
    curr.rooms.addAll(s2.rooms);
    curr.hallways.addAll(s1.hallways);
    curr.hallways.addAll(s2.hallways);
    int maxIX=Math.max(s1.intersectMax.x,s2.intersectMax.x);
    int maxIY=Math.max(s1.intersectMax.y,s2.intersectMax.y);
    int minIX=Math.min(s1.intersectMin.x,s2.intersectMin.x);
    int minIY=Math.min(s1.intersectMin.y,s2.intersectMin.y);
    curr.intersectMax=new Vec2i(maxIX,maxIY);
    curr.intersectMin=new Vec2i(minIX,minIY);
  }
}