nus-yam/ex-repair huggingface dataset:
Program: 163946
Project: 163946
Buggy source:
@Override public boolean interact(){
  updateRose();
  if (rose != null && !rose.talkedTo) {
    rose.talkedTo=true;
    GameScene.show(new WndQuest(this,Messages.get(this,"String_Node_Str")));
    return false;
  }
 else {
    int curPos=pos;
    moveSprite(pos,Dungeon.hero.pos);
    move(Dungeon.hero.pos);
    Dungeon.hero.sprite.move(Dungeon.hero.pos,curPos);
    Dungeon.hero.move(curPos);
    Dungeon.hero.spend(1 / Dungeon.hero.speed());
    Dungeon.hero.busy();
    return true;
  }
}

Fixed version (ground truth):
@Override public boolean interact(){
  updateRose();
  if (rose != null && !rose.talkedTo) {
    rose.talkedTo=true;
    GameScene.show(new WndQuest(this,Messages.get(this,"String_Node_Str")));
    return false;
  }
 else   if (Level.passable[pos] || Dungeon.hero.flying) {
    int curPos=pos;
    moveSprite(pos,Dungeon.hero.pos);
    move(Dungeon.hero.pos);
    Dungeon.hero.sprite.move(Dungeon.hero.pos,curPos);
    Dungeon.hero.move(curPos);
    Dungeon.hero.spend(1 / Dungeon.hero.speed());
    Dungeon.hero.busy();
    return true;
  }
 else {
    return false;
  }
}
Program: 163947
Project: 163947
Buggy source:
@Override protected void onZap(Ballistica bolt){
  Char ch=Actor.findChar(bolt.collisionPos);
  if (ch != null) {
    if (ch.buff(Corruption.class) != null) {
      GLog.w(Messages.get(this,"String_Node_Str"));
      return;
    }
    if (ch.properties().contains(Char.Property.BOSS) || ch.properties().contains(Char.Property.MINIBOSS)) {
      GLog.w(Messages.get(this,"String_Node_Str"));
      return;
    }
    int basePower=10 + 2 * level();
    int mobPower=Random.IntRange(0,ch.HT) + ch.HP * 2;
    for (    Buff buff : ch.buffs()) {
      if (buff.type == Buff.buffType.NEGATIVE) {
        mobPower*=0.67;
        break;
      }
    }
    int extraCharges=0;
    while (basePower <= mobPower) {
      extraCharges++;
      basePower+=5 + level();
    }
    if (extraCharges >= curCharges) {
      curCharges=1;
      GLog.w(Messages.get(this,"String_Node_Str"));
      return;
    }
    Buff.append(ch,Corruption.class);
    ch.HP=ch.HT;
    curCharges-=extraCharges;
    usagesToKnow-=extraCharges;
    processSoulMark(ch,extraCharges + chargesPerCast());
  }
}

Fixed version (ground truth):
@Override protected void onZap(Ballistica bolt){
  Char ch=Actor.findChar(bolt.collisionPos);
  if (ch != null && !(ch instanceof NPC)) {
    if (ch.buff(Corruption.class) != null) {
      GLog.w(Messages.get(this,"String_Node_Str"));
      return;
    }
    if (ch.properties().contains(Char.Property.BOSS) || ch.properties().contains(Char.Property.MINIBOSS)) {
      GLog.w(Messages.get(this,"String_Node_Str"));
      return;
    }
    int basePower=10 + 2 * level();
    int mobPower=Random.IntRange(0,ch.HT) + ch.HP * 2;
    for (    Buff buff : ch.buffs()) {
      if (buff.type == Buff.buffType.NEGATIVE) {
        mobPower*=0.67;
        break;
      }
    }
    int extraCharges=0;
    while (basePower <= mobPower) {
      extraCharges++;
      basePower+=5 + level();
    }
    if (extraCharges >= curCharges) {
      curCharges=1;
      GLog.w(Messages.get(this,"String_Node_Str"));
      return;
    }
    Buff.append(ch,Corruption.class);
    ch.HP=ch.HT;
    curCharges-=extraCharges;
    usagesToKnow-=extraCharges;
    processSoulMark(ch,extraCharges + chargesPerCast());
  }
}
Program: 163948
Project: 163948
Buggy source:
private void recreateLines(){
  for (  Entry entry : entries) {
    lastEntry=PixelScene.renderMultiline(entry.text,6);
    lastEntry.hardlight(lastColor=entry.color);
    add(lastEntry);
  }
}

Fixed version (ground truth):
private synchronized void recreateLines(){
  for (  Entry entry : entries) {
    lastEntry=PixelScene.renderMultiline(entry.text,6);
    lastEntry.hardlight(lastColor=entry.color);
    add(lastEntry);
  }
}
Program: 163949
Project: 163949
Buggy source:
public void newLine(){
  lastEntry=null;
}

Fixed version (ground truth):
public synchronized void newLine(){
  lastEntry=null;
}
Program: 163952
Project: 163952
Buggy source:
protected void setupRooms(ArrayList<Room> rooms){
  entrance=exit=shop=null;
  singleConnections.clear();
  multiConnections.clear();
  for (  Room r : rooms) {
    if (r instanceof EntranceRoom) {
      entrance=r;
    }
 else     if (r instanceof ExitRoom) {
      exit=r;
    }
 else     if (r instanceof ShopRoom && r.maxConnections(Room.ALL) == 1) {
      shop=r;
    }
 else     if (r.maxConnections(Room.ALL) > 1) {
      multiConnections.add(r);
    }
 else     if (r.maxConnections(Room.ALL) == 1) {
      singleConnections.add(r);
    }
  }
  weightRooms(multiConnections);
  Random.shuffle(multiConnections);
  multiConnections=new ArrayList<>(new LinkedHashSet<>(multiConnections));
}

Fixed version (ground truth):
protected void setupRooms(ArrayList<Room> rooms){
  for (  Room r : rooms) {
    r.setEmpty();
  }
  entrance=exit=shop=null;
  singleConnections.clear();
  multiConnections.clear();
  for (  Room r : rooms) {
    if (r instanceof EntranceRoom) {
      entrance=r;
    }
 else     if (r instanceof ExitRoom) {
      exit=r;
    }
 else     if (r instanceof ShopRoom && r.maxConnections(Room.ALL) == 1) {
      shop=r;
    }
 else     if (r.maxConnections(Room.ALL) > 1) {
      multiConnections.add(r);
    }
 else     if (r.maxConnections(Room.ALL) == 1) {
      singleConnections.add(r);
    }
  }
  weightRooms(multiConnections);
  Random.shuffle(multiConnections);
  multiConnections=new ArrayList<>(new LinkedHashSet<>(multiConnections));
}
Program: 163953
Project: 163953
Buggy source:
private void fillBetweenPoints(Level level,Point from,Point to,int floor){
  if (from.y == to.y || from.x == to.x) {
    Painter.fill(level,Math.min(from.x,to.x),Math.min(from.y,to.y),spaceBetween(from.x,to.x) + 2,spaceBetween(from.y,to.y) + 2,floor);
    return;
  }
  if (corners == null) {
    corners=new Point[4];
    corners[0]=new Point(left + 2,top + 2);
    corners[1]=new Point(right - 2,top + 2);
    corners[2]=new Point(right - 2,bottom - 2);
    corners[3]=new Point(left + 2,bottom - 2);
  }
  for (  Point c : corners) {
    if ((c.x == from.x || c.y == from.y) && (c.x == to.x || c.y == to.y)) {
      Painter.drawLine(level,from,c,floor);
      Painter.drawLine(level,c,to,floor);
      return;
    }
  }
  Point side;
  if (from.y == top + 1 || from.y == bottom - 1) {
    if (spaceBetween(left,from.x) + spaceBetween(left,to.x) <= spaceBetween(right,from.x) + spaceBetween(right,to.x)) {
      side=new Point(left + 1,top + height() / 2);
    }
 else {
      side=new Point(right - 1,top + height() / 2);
    }
  }
 else {
    if (spaceBetween(top,from.y) + spaceBetween(top,to.y) <= spaceBetween(bottom,from.y) + spaceBetween(bottom,to.y)) {
      side=new Point(left + width() / 2,top + 1);
    }
 else {
      side=new Point(left + width() / 2,bottom - 1);
    }
  }
  fillBetweenPoints(level,from,side,floor);
  fillBetweenPoints(level,side,to,floor);
}

Fixed version (ground truth):
private void fillBetweenPoints(Level level,Point from,Point to,int floor){
  if (from.y == to.y || from.x == to.x) {
    Painter.fill(level,Math.min(from.x,to.x),Math.min(from.y,to.y),spaceBetween(from.x,to.x) + 2,spaceBetween(from.y,to.y) + 2,floor);
    return;
  }
  if (corners == null) {
    corners=new Point[4];
    corners[0]=new Point(left + 2,top + 2);
    corners[1]=new Point(right - 2,top + 2);
    corners[2]=new Point(right - 2,bottom - 2);
    corners[3]=new Point(left + 2,bottom - 2);
  }
  for (  Point c : corners) {
    if ((c.x == from.x || c.y == from.y) && (c.x == to.x || c.y == to.y)) {
      Painter.drawLine(level,from,c,floor);
      Painter.drawLine(level,c,to,floor);
      return;
    }
  }
  Point side;
  if (from.y == top + 2 || from.y == bottom - 2) {
    if (spaceBetween(left,from.x) + spaceBetween(left,to.x) <= spaceBetween(right,from.x) + spaceBetween(right,to.x)) {
      side=new Point(left + 2,top + height() / 2);
    }
 else {
      side=new Point(right - 2,top + height() / 2);
    }
  }
 else {
    if (spaceBetween(top,from.y) + spaceBetween(top,to.y) <= spaceBetween(bottom,from.y) + spaceBetween(bottom,to.y)) {
      side=new Point(left + width() / 2,top + 2);
    }
 else {
      side=new Point(left + width() / 2,bottom - 2);
    }
  }
  fillBetweenPoints(level,from,side,floor);
  fillBetweenPoints(level,side,to,floor);
}
Program: 163955
Project: 163955
Buggy source:
public static void process(){
  if (spawned && given && !processed&& (depth == Dungeon.depth)) {
    GLog.n(Messages.get(Ghost.class,"String_Node_Str"));
    Sample.INSTANCE.play(Assets.SND_GHOST);
    processed=true;
    Generator.Category.ARTIFACT.probs[10]=1;
  }
}

Fixed version (ground truth):
public static void process(){
  if (spawned && given && !processed&& (depth == Dungeon.depth)) {
    GLog.n(Messages.get(Ghost.class,"String_Node_Str"));
    Sample.INSTANCE.play(Assets.SND_GHOST);
    processed=true;
  }
}
Program: 163956
Project: 163956
Buggy source:
public static boolean completed(){
  return spawned && processed;
}

Fixed version (ground truth):
public static boolean completed(){
  return processed() && weapon == null && armor == null;
}
Program: 163957
Project: 163957
Buggy source:
@Override public float speed(){
  return Quest.completed() ? 2f : 0.5f;
}

Fixed version (ground truth):
@Override public float speed(){
  return Quest.processed() ? 2f : 0.5f;
}
Program: 163958
Project: 163958
Buggy source:
@Override protected boolean act(){
  if (Quest.completed())   target=Dungeon.hero.pos;
  return super.act();
}

Fixed version (ground truth):
@Override protected boolean act(){
  if (Quest.processed())   target=Dungeon.hero.pos;
  return super.act();
}
Program: 163959
Project: 163959
Buggy source:
public static void initArtifacts(){
  Category.ARTIFACT.probs=Category.INITIAL_ARTIFACT_PROBS.clone();
  if (Ghost.Quest.completed())   Category.ARTIFACT.probs[10]=1;
  spawnedArtifacts=new ArrayList<>();
}

Fixed version (ground truth):
public static void initArtifacts(){
  Category.ARTIFACT.probs=Category.INITIAL_ARTIFACT_PROBS.clone();
  spawnedArtifacts=new ArrayList<>();
}
Program: 163960
Project: 163960
Buggy source:
@Override public String status(){
  if (cooldown != 0)   return Messages.format("String_Node_Str",cooldown);
  if (chargeCap == 100)   return Messages.format("String_Node_Str",charge);
  if (chargeCap > 0)   return Messages.format("String_Node_Str",charge,chargeCap);
  if (charge != 0)   return Messages.format("String_Node_Str",charge);
  return null;
}

Fixed version (ground truth):
@Override public String status(){
  if (!isIdentified() || cursed) {
    return null;
  }
  if (cooldown != 0)   return Messages.format("String_Node_Str",cooldown);
  if (chargeCap == 100)   return Messages.format("String_Node_Str",charge);
  if (chargeCap > 0)   return Messages.format("String_Node_Str",charge,chargeCap);
  if (charge != 0)   return Messages.format("String_Node_Str",charge);
  return null;
}
Program: 163961
Project: 163961
Buggy source:
public static void restoreGhostHero(Level level,int pos){
  if (heldGhost != null) {
    level.mobs.add(heldGhost);
    int ghostPos;
    do {
      ghostPos=pos + PathFinder.NEIGHBOURS8[Random.Int(8)];
    }
 while (Level.solid[ghostPos] || level.findMob(ghostPos) != null);
    heldGhost.pos=pos;
    heldGhost=null;
  }
}

Fixed version (ground truth):
public static void restoreGhostHero(Level level,int pos){
  if (heldGhost != null) {
    level.mobs.add(heldGhost);
    int ghostPos;
    do {
      ghostPos=pos + PathFinder.NEIGHBOURS8[Random.Int(8)];
    }
 while (Level.solid[ghostPos] || level.findMob(ghostPos) != null);
    heldGhost.pos=ghostPos;
    heldGhost=null;
  }
}
Program: 163962
Project: 163962
Buggy source:
@Override public ArrayList<String> actions(Hero hero){
  ArrayList<String> actions=super.actions(hero);
  if (isEquipped(hero) && charge == chargeCap && !cursed) {
    actions.add(AC_SUMMON);
  }
  if (isIdentified() && !cursed) {
    actions.add(AC_OUTFIT);
  }
  return actions;
}

Fixed version (ground truth):
@Override public ArrayList<String> actions(Hero hero){
  ArrayList<String> actions=super.actions(hero);
  if (!Ghost.Quest.completed()) {
    actions.remove(AC_EQUIP);
    return actions;
  }
  if (isEquipped(hero) && charge == chargeCap && !cursed) {
    actions.add(AC_SUMMON);
  }
  if (isIdentified() && !cursed) {
    actions.add(AC_OUTFIT);
  }
  return actions;
}
Program: 163963
Project: 163963
Buggy source:
@Override public String desc(){
  String desc=super.desc();
  if (isEquipped(Dungeon.hero)) {
    if (!cursed) {
      if (level() < levelCap)       desc+="String_Node_Str" + Messages.get(this,"String_Node_Str");
    }
 else     desc+="String_Node_Str" + Messages.get(this,"String_Node_Str");
  }
  return desc;
}

Fixed version (ground truth):
@Override public String desc(){
  if (!Ghost.Quest.completed() && !isIdentified()) {
    return Messages.get(this,"String_Node_Str");
  }
  String desc=super.desc();
  if (isEquipped(Dungeon.hero)) {
    if (!cursed) {
      if (level() < levelCap)       desc+="String_Node_Str" + Messages.get(this,"String_Node_Str");
    }
 else     desc+="String_Node_Str" + Messages.get(this,"String_Node_Str");
  }
  return desc;
}
Program: 163965
Project: 163965
Buggy source:
@Override protected void onClick(){
  if (rose.armor != null) {
    if (rose.armor.doPickUp(Dungeon.hero)) {
      item(new WndBag.Placeholder(ItemSpriteSheet.ARMOR_HOLDER));
    }
 else {
      Dungeon.level.drop(rose.armor,Dungeon.hero.pos);
    }
    rose.armor=null;
  }
 else {
    GameScene.selectItem(new WndBag.Listener(){
      @Override public void onSelect(      Item item){
        if (!(item instanceof Armor)) {
        }
 else         if (item.unique || ((Armor)item).checkSeal() != null) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (!item.isIdentified()) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (item.cursed) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (((Armor)item).STRReq() > rose.ghostStrength()) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else {
          if (item.isEquipped(Dungeon.hero)) {
            ((Armor)item).doUnequip(Dungeon.hero,false,false);
          }
 else {
            item.detach(Dungeon.hero.belongings.backpack);
          }
          rose.armor=(Armor)item;
          item(rose.armor);
        }
      }
    }
,WndBag.Mode.ARMOR,Messages.get(WndGhostHero.class,"String_Node_Str"));
  }
}

Fixed version (ground truth):
@Override protected void onClick(){
  if (rose.armor != null) {
    item(new WndBag.Placeholder(ItemSpriteSheet.ARMOR_HOLDER));
    if (!rose.armor.doPickUp(Dungeon.hero)) {
      Dungeon.level.drop(rose.armor,Dungeon.hero.pos);
    }
    rose.armor=null;
  }
 else {
    GameScene.selectItem(new WndBag.Listener(){
      @Override public void onSelect(      Item item){
        if (!(item instanceof Armor)) {
        }
 else         if (item.unique || ((Armor)item).checkSeal() != null) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (!item.isIdentified()) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (item.cursed) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (((Armor)item).STRReq() > rose.ghostStrength()) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else {
          if (item.isEquipped(Dungeon.hero)) {
            ((Armor)item).doUnequip(Dungeon.hero,false,false);
          }
 else {
            item.detach(Dungeon.hero.belongings.backpack);
          }
          rose.armor=(Armor)item;
          item(rose.armor);
        }
      }
    }
,WndBag.Mode.ARMOR,Messages.get(WndGhostHero.class,"String_Node_Str"));
  }
}
Program: 163967
Project: 163967
Buggy source:
public void updateArmor(){
  TextureFilm film=new TextureFilm(tiers(),((Hero)ch).tier(),FRAME_WIDTH,FRAME_HEIGHT);
  idle=new Animation(1,true);
  idle.frames(film,0,0,0,1,0,0,1,1);
  run=new Animation(RUN_FRAMERATE,true);
  run.frames(film,2,3,4,5,6,7);
  die=new Animation(20,false);
  die.frames(film,8,9,10,11,12,11);
  attack=new Animation(15,false);
  attack.frames(film,13,14,15,0);
  zap=attack.clone();
  operate=new Animation(8,false);
  operate.frames(film,16,17,16,17);
  fly=new Animation(1,true);
  fly.frames(film,18);
  read=new Animation(20,false);
  read.frames(film,19,20,20,20,20,20,20,20,20,19);
}

Fixed version (ground truth):
public void updateArmor(){
  TextureFilm film=new TextureFilm(tiers(),((Hero)ch).tier(),FRAME_WIDTH,FRAME_HEIGHT);
  idle=new Animation(1,true);
  idle.frames(film,0,0,0,1,0,0,1,1);
  run=new Animation(RUN_FRAMERATE,true);
  run.frames(film,2,3,4,5,6,7);
  die=new Animation(20,false);
  die.frames(film,8,9,10,11,12,11);
  attack=new Animation(15,false);
  attack.frames(film,13,14,15,0);
  zap=attack.clone();
  operate=new Animation(8,false);
  operate.frames(film,16,17,16,17);
  fly=new Animation(1,true);
  fly.frames(film,18);
  read=new Animation(20,false);
  read.frames(film,19,20,20,20,20,20,20,20,20,19);
  idle();
}
Program: 163968
Project: 163968
Buggy source:
public void restoreFromBundle(Bundle bundle){
  if (bundle.contains("String_Node_Str")) {
    int[] ironKeys=bundle.getIntArray("String_Node_Str");
    for (int i=0; i < ironKeys.length; i++) {
      if (ironKeys[i] > 0) {
        Notes.add((Key)new IronKey(i).quantity(ironKeys[i]));
      }
    }
  }
  if (bundle.contains("String_Node_Str")) {
    int[] specialKeys=bundle.getIntArray("String_Node_Str");
    for (int i=0; i < specialKeys.length; i++) {
      if (specialKeys[i] > 0) {
        if (i % 5 == 0) {
          Notes.add((Key)new GoldenKey(i).quantity(specialKeys[i]));
        }
 else {
          Notes.add((Key)new SkeletonKey(i).quantity(specialKeys[i]));
        }
      }
    }
  }
  backpack.clear();
  backpack.restoreFromBundle(bundle);
  weapon=(KindOfWeapon)bundle.get(WEAPON);
  if (weapon != null) {
    weapon.activate(owner);
  }
  armor=(Armor)bundle.get(ARMOR);
  if (armor != null) {
    armor.activate(owner);
  }
  misc1=(KindofMisc)bundle.get(MISC1);
  if (misc1 != null) {
    misc1.activate(owner);
  }
  misc2=(KindofMisc)bundle.get(MISC2);
  if (misc2 != null) {
    misc2.activate(owner);
  }
}

Fixed version (ground truth):
public void restoreFromBundle(Bundle bundle){
  if (bundle.contains("String_Node_Str")) {
    int[] ironKeys=bundle.getIntArray("String_Node_Str");
    for (int i=0; i < ironKeys.length; i++) {
      if (ironKeys[i] > 0) {
        Notes.add((Key)new IronKey(i).quantity(ironKeys[i]));
      }
    }
  }
  if (bundle.contains("String_Node_Str")) {
    int[] specialKeys=bundle.getIntArray("String_Node_Str");
    for (int i=0; i < specialKeys.length; i++) {
      if (specialKeys[i] > 0) {
        if (i % 5 == 0) {
          Notes.add((Key)new SkeletonKey(i).quantity(specialKeys[i]));
        }
 else {
          Notes.add((Key)new GoldenKey(i).quantity(specialKeys[i]));
        }
      }
    }
  }
  backpack.clear();
  backpack.restoreFromBundle(bundle);
  weapon=(KindOfWeapon)bundle.get(WEAPON);
  if (weapon != null) {
    weapon.activate(owner);
  }
  armor=(Armor)bundle.get(ARMOR);
  if (armor != null) {
    armor.activate(owner);
  }
  misc1=(KindofMisc)bundle.get(MISC1);
  if (misc1 != null) {
    misc1.activate(owner);
  }
  misc2=(KindofMisc)bundle.get(MISC2);
  if (misc2 != null) {
    misc2.activate(owner);
  }
}
Program: 163969
Project: 163969
Buggy source:
private boolean actUnlock(HeroAction.Unlock action){
  int doorCell=action.dst;
  if (Dungeon.level.adjacent(pos,doorCell)) {
    boolean hasKey=false;
    int door=Dungeon.level.map[doorCell];
    if (door == Terrain.LOCKED_DOOR && Notes.keyCount(new IronKey(Dungeon.depth)) > 0) {
      hasKey=true;
    }
 else     if (door == Terrain.LOCKED_EXIT && Notes.keyCount(new GoldenKey(Dungeon.depth)) > 0) {
      hasKey=true;
    }
    if (hasKey) {
      spend(Key.TIME_TO_UNLOCK);
      sprite.operate(doorCell);
      Sample.INSTANCE.play(Assets.SND_UNLOCK);
    }
 else {
      GLog.w(Messages.get(this,"String_Node_Str"));
      ready();
    }
    return false;
  }
 else   if (getCloser(doorCell)) {
    return true;
  }
 else {
    ready();
    return false;
  }
}

Fixed version (ground truth):
private boolean actUnlock(HeroAction.Unlock action){
  int doorCell=action.dst;
  if (Dungeon.level.adjacent(pos,doorCell)) {
    boolean hasKey=false;
    int door=Dungeon.level.map[doorCell];
    if (door == Terrain.LOCKED_DOOR && Notes.keyCount(new IronKey(Dungeon.depth)) > 0) {
      hasKey=true;
    }
 else     if (door == Terrain.LOCKED_EXIT && Notes.keyCount(new SkeletonKey(Dungeon.depth)) > 0) {
      hasKey=true;
    }
    if (hasKey) {
      spend(Key.TIME_TO_UNLOCK);
      sprite.operate(doorCell);
      Sample.INSTANCE.play(Assets.SND_UNLOCK);
    }
 else {
      GLog.w(Messages.get(this,"String_Node_Str"));
      ready();
    }
    return false;
  }
 else   if (getCloser(doorCell)) {
    return true;
  }
 else {
    ready();
    return false;
  }
}
Program: 163970
Project: 163970
Buggy source:
public static void load(){
  if (loaded) {
    return;
  }
  Badges.loadGlobal();
  if (Badges.global.contains(Badges.Badge.ALL_ITEMS_IDENTIFIED)) {
    for (    LinkedHashMap<Class<? extends Item>,Boolean> cat : allCatalogs) {
      for (      Class<? extends Item> item : cat.keySet()) {
        cat.put(item,true);
      }
    }
    loaded=true;
    return;
  }
  for (  LinkedHashMap<Class<? extends Item>,Boolean> cat : allCatalogs) {
    if (Badges.global.contains(catalogBadges.get(cat))) {
      for (      Class<? extends Item> item : cat.keySet()) {
        cat.put(item,true);
      }
    }
  }
  try {
    InputStream input=Game.instance.openFileInput("String_Node_Str");
    Bundle bundle=Bundle.read(input);
    input.close();
    List<String> seen=Arrays.asList(bundle.getStringArray("String_Node_Str"));
    for (    LinkedHashMap<Class<? extends Item>,Boolean> cat : allCatalogs) {
      for (      Class<? extends Item> item : cat.keySet()) {
        cat.put(item,seen.contains(item.getSimpleName()));
      }
    }
    loaded=true;
  }
 catch (  IOException e) {
  }
}

Fixed version (ground truth):
public static void load(){
  if (loaded) {
    return;
  }
  Badges.loadGlobal();
  if (Badges.global.contains(Badges.Badge.ALL_ITEMS_IDENTIFIED)) {
    for (    LinkedHashMap<Class<? extends Item>,Boolean> cat : allCatalogs) {
      for (      Class<? extends Item> item : cat.keySet()) {
        cat.put(item,true);
      }
    }
    loaded=true;
    return;
  }
  for (  LinkedHashMap<Class<? extends Item>,Boolean> cat : allCatalogs) {
    if (Badges.global.contains(catalogBadges.get(cat))) {
      for (      Class<? extends Item> item : cat.keySet()) {
        cat.put(item,true);
      }
    }
  }
  try {
    InputStream input=Game.instance.openFileInput("String_Node_Str");
    Bundle bundle=Bundle.read(input);
    input.close();
    List<String> seen=Arrays.asList(bundle.getStringArray("String_Node_Str"));
    for (    LinkedHashMap<Class<? extends Item>,Boolean> cat : allCatalogs) {
      for (      Class<? extends Item> item : cat.keySet()) {
        if (seen.contains(item.getSimpleName())) {
          cat.put(item,true);
        }
      }
    }
    loaded=true;
  }
 catch (  IOException e) {
  }
}
Program: 163971
Project: 163971
Buggy source:
public static void restoreGhostHero(Level level,int pos){
  if (heldGhost != null) {
    level.mobs.add(heldGhost);
    int ghostPos;
    do {
      ghostPos=pos + PathFinder.NEIGHBOURS8[Random.Int(8)];
    }
 while (!Level.solid[ghostPos] || level.findMob(ghostPos) != null);
    heldGhost.pos=pos;
    heldGhost=null;
  }
}

Fixed version (ground truth):
public static void restoreGhostHero(Level level,int pos){
  if (heldGhost != null) {
    level.mobs.add(heldGhost);
    int ghostPos;
    do {
      ghostPos=pos + PathFinder.NEIGHBOURS8[Random.Int(8)];
    }
 while (Level.solid[ghostPos] || level.findMob(ghostPos) != null);
    heldGhost.pos=pos;
    heldGhost=null;
  }
}
Program: 163972
Project: 163972
Buggy source:
@Override public int randomRespawnCell(){
  int count=0;
  int cell=-1;
  while (true) {
    if (++count > 30) {
      return -1;
    }
    Room room=randomRoom(StandardRoom.class);
    if (room == null || room == roomEntrance) {
      continue;
    }
    cell=pointToCell(room.random());
    if (!Dungeon.visible[cell] && Actor.findChar(cell) == null && Level.passable[cell] && cell != exit) {
      return cell;
    }
  }
}

Fixed version (ground truth):
@Override public int randomRespawnCell(){
  int count=0;
  int cell=-1;
  while (true) {
    if (++count > 30) {
      return -1;
    }
    Room room=randomRoom(StandardRoom.class);
    if (room == null || room == roomEntrance) {
      continue;
    }
    if (room.width() >= 6 && room.height() >= 6) {
      cell=pointToCell(room.random(2));
    }
 else {
      cell=pointToCell(room.random(1));
    }
    if (!Dungeon.visible[cell] && Actor.findChar(cell) == null && Level.passable[cell] && cell != exit) {
      return cell;
    }
  }
}
Program: 163973
Project: 163973
Buggy source:
@Override public int minHeight(){
  return Math.max(super.minHeight(),5);
}

Fixed version (ground truth):
@Override public int minHeight(){
  return Math.max(super.minHeight(),6);
}
Program: 163974
Project: 163974
Buggy source:
@Override public int minWidth(){
  return Math.max(super.minWidth(),5);
}

Fixed version (ground truth):
@Override public int minWidth(){
  return Math.max(super.minWidth(),6);
}
Program: 163975
Project: 163975
Buggy source:
@Override public void restoreFromBundle(Bundle bundle){
  super.restoreFromBundle(bundle);
  if ((ticksToKnow=bundle.getInt(UNFAMILIRIARITY)) == 0) {
    ticksToKnow=TICKS_TO_KNOW;
  }
}

Fixed version (ground truth):
@Override public void restoreFromBundle(Bundle bundle){
  super.restoreFromBundle(bundle);
  if ((ticksToKnow=bundle.getInt(UNFAMILIRIARITY)) == 0) {
    ticksToKnow=TICKS_TO_KNOW;
  }
  if (level() < 0) {
    upgrade(-level());
  }
}
Program: 163976
Project: 163976
Buggy source:
public static boolean uncurse(Hero hero,Item... items){
  boolean procced=false;
  for (  Item item : items) {
    if (item != null && item.cursed) {
      item.cursed=false;
      procced=true;
    }
    if (item instanceof Weapon) {
      Weapon w=(Weapon)item;
      if (w.hasCurseEnchant()) {
        w.enchant(null);
        w.cursed=false;
        procced=true;
      }
    }
    if (item instanceof Armor) {
      Armor a=(Armor)item;
      if (a.hasCurseGlyph()) {
        a.inscribe(null);
        a.cursed=false;
        procced=true;
      }
    }
    if (item instanceof Ring && item.level() <= 0) {
      item.upgrade(1 - item.level());
    }
    if (item instanceof Bag) {
      for (      Item bagItem : ((Bag)item).items) {
        if (bagItem != null && bagItem.cursed) {
          bagItem.cursed=false;
          procced=true;
        }
      }
    }
  }
  if (procced) {
    hero.sprite.emitter().start(ShadowParticle.UP,0.05f,10);
  }
  return procced;
}

Fixed version (ground truth):
public static boolean uncurse(Hero hero,Item... items){
  boolean procced=false;
  for (  Item item : items) {
    if (item != null && item.cursed) {
      item.cursed=false;
      procced=true;
    }
    if (item instanceof Weapon) {
      Weapon w=(Weapon)item;
      if (w.hasCurseEnchant()) {
        w.enchant(null);
        w.cursed=false;
        procced=true;
      }
    }
    if (item instanceof Armor) {
      Armor a=(Armor)item;
      if (a.hasCurseGlyph()) {
        a.inscribe(null);
        a.cursed=false;
        procced=true;
      }
    }
    if (item instanceof Bag) {
      for (      Item bagItem : ((Bag)item).items) {
        if (bagItem != null && bagItem.cursed) {
          bagItem.cursed=false;
          procced=true;
        }
      }
    }
  }
  if (procced) {
    hero.sprite.emitter().start(ShadowParticle.UP,0.05f,10);
  }
  return procced;
}
Program: 163977
Project: 163977
Buggy source:
@SuppressWarnings("String_Node_Str") public static void switchLevel(final Level level,int pos){
  if (pos < 0 || pos >= level.length()) {
    pos=level.exit;
  }
  PathFinder.setMapSize(level.width(),level.height());
  Dungeon.level=level;
  DriedRose.restoreGhostHero(level,pos + PathFinder.NEIGHBOURS8[Random.Int(8)]);
  Actor.init();
  visible=new boolean[level.length()];
  Actor respawner=level.respawner();
  if (respawner != null) {
    Actor.add(level.respawner());
  }
  hero.pos=pos;
  Light light=hero.buff(Light.class);
  hero.viewDistance=light == null ? level.viewDistance : Math.max(Light.DISTANCE,level.viewDistance);
  hero.curAction=hero.lastAction=null;
  observe();
  try {
    saveAll();
  }
 catch (  IOException e) {
    ShatteredPixelDungeon.reportException(e);
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public static void switchLevel(final Level level,int pos){
  if (pos < 0 || pos >= level.length()) {
    pos=level.exit;
  }
  PathFinder.setMapSize(level.width(),level.height());
  Dungeon.level=level;
  DriedRose.restoreGhostHero(level,pos);
  Actor.init();
  visible=new boolean[level.length()];
  Actor respawner=level.respawner();
  if (respawner != null) {
    Actor.add(level.respawner());
  }
  hero.pos=pos;
  Light light=hero.buff(Light.class);
  hero.viewDistance=light == null ? level.viewDistance : Math.max(Light.DISTANCE,level.viewDistance);
  hero.curAction=hero.lastAction=null;
  observe();
  try {
    saveAll();
  }
 catch (  IOException e) {
    ShatteredPixelDungeon.reportException(e);
  }
}
Program: 163978
Project: 163978
Buggy source:
public static void restoreGhostHero(Level level,int pos){
  if (heldGhost != null) {
    level.mobs.add(heldGhost);
    heldGhost.pos=pos;
    heldGhost=null;
  }
}

Fixed version (ground truth):
public static void restoreGhostHero(Level level,int pos){
  if (heldGhost != null) {
    level.mobs.add(heldGhost);
    int ghostPos;
    do {
      ghostPos=pos + PathFinder.NEIGHBOURS8[Random.Int(8)];
    }
 while (!Level.solid[ghostPos] || level.findMob(ghostPos) != null);
    heldGhost.pos=pos;
    heldGhost=null;
  }
}
Program: 163979
Project: 163979
Buggy source:
@Override protected void onClick(){
  if (rose.armor != null) {
    if (rose.armor.doPickUp(Dungeon.hero)) {
      item(new WndBag.Placeholder(ItemSpriteSheet.ARMOR_HOLDER));
    }
 else {
      Dungeon.level.drop(rose.armor,Dungeon.hero.pos);
    }
    rose.armor=null;
  }
 else {
    GameScene.selectItem(new WndBag.Listener(){
      @Override public void onSelect(      Item item){
        if (!(item instanceof Armor)) {
          hide();
        }
 else         if (item.unique || ((Armor)item).checkSeal() != null) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (!item.isIdentified()) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (item.cursed) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (((Armor)item).STRReq() > rose.ghostStrength()) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else {
          if (item.isEquipped(Dungeon.hero)) {
            ((Armor)item).doUnequip(Dungeon.hero,false,false);
          }
 else {
            item.detach(Dungeon.hero.belongings.backpack);
          }
          rose.armor=(Armor)item;
          item(rose.armor);
        }
      }
    }
,WndBag.Mode.ARMOR,Messages.get(WndGhostHero.class,"String_Node_Str"));
  }
}

Fixed version (ground truth):
@Override protected void onClick(){
  if (rose.armor != null) {
    if (rose.armor.doPickUp(Dungeon.hero)) {
      item(new WndBag.Placeholder(ItemSpriteSheet.ARMOR_HOLDER));
    }
 else {
      Dungeon.level.drop(rose.armor,Dungeon.hero.pos);
    }
    rose.armor=null;
  }
 else {
    GameScene.selectItem(new WndBag.Listener(){
      @Override public void onSelect(      Item item){
        if (!(item instanceof Armor)) {
        }
 else         if (item.unique || ((Armor)item).checkSeal() != null) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (!item.isIdentified()) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (item.cursed) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else         if (((Armor)item).STRReq() > rose.ghostStrength()) {
          GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
          hide();
        }
 else {
          if (item.isEquipped(Dungeon.hero)) {
            ((Armor)item).doUnequip(Dungeon.hero,false,false);
          }
 else {
            item.detach(Dungeon.hero.belongings.backpack);
          }
          rose.armor=(Armor)item;
          item(rose.armor);
        }
      }
    }
,WndBag.Mode.ARMOR,Messages.get(WndGhostHero.class,"String_Node_Str"));
  }
}
Program: 163981
Project: 163981
Buggy source:
@Override public void onSelect(Item item){
  if (!(item instanceof Armor)) {
    hide();
  }
 else   if (item.unique || ((Armor)item).checkSeal() != null) {
    GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
    hide();
  }
 else   if (!item.isIdentified()) {
    GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
    hide();
  }
 else   if (item.cursed) {
    GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
    hide();
  }
 else   if (((Armor)item).STRReq() > rose.ghostStrength()) {
    GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
    hide();
  }
 else {
    if (item.isEquipped(Dungeon.hero)) {
      ((Armor)item).doUnequip(Dungeon.hero,false,false);
    }
 else {
      item.detach(Dungeon.hero.belongings.backpack);
    }
    rose.armor=(Armor)item;
    item(rose.armor);
  }
}

Fixed version (ground truth):
@Override public void onSelect(Item item){
  if (!(item instanceof Armor)) {
  }
 else   if (item.unique || ((Armor)item).checkSeal() != null) {
    GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
    hide();
  }
 else   if (!item.isIdentified()) {
    GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
    hide();
  }
 else   if (item.cursed) {
    GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
    hide();
  }
 else   if (((Armor)item).STRReq() > rose.ghostStrength()) {
    GLog.w(Messages.get(WndGhostHero.class,"String_Node_Str"));
    hide();
  }
 else {
    if (item.isEquipped(Dungeon.hero)) {
      ((Armor)item).doUnequip(Dungeon.hero,false,false);
    }
 else {
      item.detach(Dungeon.hero.belongings.backpack);
    }
    rose.armor=(Armor)item;
    item(rose.armor);
  }
}
Program: 163982
Project: 163982
Buggy source:
@Override protected void createMobs(){
  int mobsToSpawn=Dungeon.depth == 1 ? 10 : nMobs();
  ArrayList<Room> stdRooms=new ArrayList<>();
  for (  Room room : rooms) {
    if ((room instanceof StandardRoom || room.legacyType.equals("String_Node_Str")) && room != roomEntrance) {
      for (int i=0; i < ((StandardRoom)room).sizeCat.roomValue; i++) {
        stdRooms.add(room);
      }
    }
  }
  Random.shuffle(stdRooms);
  Iterator<Room> stdRoomIter=stdRooms.iterator();
  while (mobsToSpawn > 0) {
    if (!stdRoomIter.hasNext())     stdRoomIter=stdRooms.iterator();
    Room roomToSpawn=stdRoomIter.next();
    Mob mob=Bestiary.mob(Dungeon.depth);
    mob.pos=pointToCell(roomToSpawn.random());
    if (findMob(mob.pos) == null && Level.passable[mob.pos]) {
      mobsToSpawn--;
      mobs.add(mob);
      if (mobsToSpawn > 0 && Random.Int(4) == 0) {
        mob=Bestiary.mob(Dungeon.depth);
        mob.pos=pointToCell(roomToSpawn.random());
        if (findMob(mob.pos) == null && Level.passable[mob.pos]) {
          mobsToSpawn--;
          mobs.add(mob);
        }
      }
    }
  }
  for (  Mob m : mobs) {
    if (map[m.pos] == Terrain.HIGH_GRASS) {
      map[m.pos]=Terrain.GRASS;
      losBlocking[m.pos]=false;
    }
  }
}

Fixed version (ground truth):
@Override protected void createMobs(){
  int mobsToSpawn=Dungeon.depth == 1 ? 10 : nMobs();
  ArrayList<Room> stdRooms=new ArrayList<>();
  for (  Room room : rooms) {
    if (room instanceof StandardRoom && room != roomEntrance) {
      for (int i=0; i < ((StandardRoom)room).sizeCat.roomValue; i++) {
        stdRooms.add(room);
      }
    }
 else     if (room.legacyType.equals("String_Node_Str")) {
      stdRooms.add(room);
    }
  }
  Random.shuffle(stdRooms);
  Iterator<Room> stdRoomIter=stdRooms.iterator();
  while (mobsToSpawn > 0) {
    if (!stdRoomIter.hasNext())     stdRoomIter=stdRooms.iterator();
    Room roomToSpawn=stdRoomIter.next();
    Mob mob=Bestiary.mob(Dungeon.depth);
    mob.pos=pointToCell(roomToSpawn.random());
    if (findMob(mob.pos) == null && Level.passable[mob.pos]) {
      mobsToSpawn--;
      mobs.add(mob);
      if (mobsToSpawn > 0 && Random.Int(4) == 0) {
        mob=Bestiary.mob(Dungeon.depth);
        mob.pos=pointToCell(roomToSpawn.random());
        if (findMob(mob.pos) == null && Level.passable[mob.pos]) {
          mobsToSpawn--;
          mobs.add(mob);
        }
      }
    }
  }
  for (  Mob m : mobs) {
    if (map[m.pos] == Terrain.HIGH_GRASS) {
      map[m.pos]=Terrain.GRASS;
      losBlocking[m.pos]=false;
    }
  }
}
Program: 163983
Project: 163983
Buggy source:
@SuppressWarnings("String_Node_Str") public static <K>K chances(HashMap<K,Float> chances){
  int size=chances.size();
  Object[] values=chances.keySet().toArray();
  float[] probs=new float[size];
  float sum=0;
  for (int i=0; i < size; i++) {
    probs[i]=chances.get(values[i]);
    sum+=probs[i];
  }
  float value=Float(sum);
  sum=probs[0];
  for (int i=0; i < size; i++) {
    if (value < sum) {
      return (K)values[i];
    }
    sum+=probs[i + 1];
  }
  return null;
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public static <K>K chances(HashMap<K,Float> chances){
  int size=chances.size();
  Object[] values=chances.keySet().toArray();
  float[] probs=new float[size];
  float sum=0;
  for (int i=0; i < size; i++) {
    probs[i]=chances.get(values[i]);
    sum+=probs[i];
  }
  if (sum <= 0) {
    return null;
  }
  float value=Float(sum);
  sum=probs[0];
  for (int i=0; i < size; i++) {
    if (value < sum) {
      return (K)values[i];
    }
    sum+=probs[i + 1];
  }
  return null;
}
Program: 163984
Project: 163984
Buggy source:
@Override protected void createMobs(){
  int mobsToSpawn=Dungeon.depth == 1 ? 10 : nMobs();
  ArrayList<Room> stdRooms=new ArrayList<>();
  for (  Room room : rooms) {
    if (room instanceof StandardRoom && room != roomEntrance) {
      for (int i=0; i < ((StandardRoom)room).sizeCat.roomValue; i++) {
        stdRooms.add(room);
      }
    }
  }
  Random.shuffle(rooms);
  Iterator<Room> stdRoomIter=stdRooms.iterator();
  while (mobsToSpawn > 0) {
    if (!stdRoomIter.hasNext())     stdRoomIter=stdRooms.iterator();
    Room roomToSpawn=stdRoomIter.next();
    Mob mob=Bestiary.mob(Dungeon.depth);
    mob.pos=pointToCell(roomToSpawn.random());
    if (findMob(mob.pos) == null && Level.passable[mob.pos]) {
      mobsToSpawn--;
      mobs.add(mob);
      if (mobsToSpawn > 0 && Random.Int(4) == 0) {
        mob=Bestiary.mob(Dungeon.depth);
        mob.pos=pointToCell(roomToSpawn.random());
        if (findMob(mob.pos) == null && Level.passable[mob.pos]) {
          mobsToSpawn--;
          mobs.add(mob);
        }
      }
    }
  }
  for (  Mob m : mobs) {
    if (map[m.pos] == Terrain.HIGH_GRASS) {
      map[m.pos]=Terrain.GRASS;
      losBlocking[m.pos]=false;
    }
  }
}

Fixed version (ground truth):
@Override protected void createMobs(){
  int mobsToSpawn=Dungeon.depth == 1 ? 10 : nMobs();
  ArrayList<Room> stdRooms=new ArrayList<>();
  for (  Room room : rooms) {
    if ((room instanceof StandardRoom || room.legacyType.equals("String_Node_Str")) && room != roomEntrance) {
      for (int i=0; i < ((StandardRoom)room).sizeCat.roomValue; i++) {
        stdRooms.add(room);
      }
    }
  }
  Random.shuffle(stdRooms);
  Iterator<Room> stdRoomIter=stdRooms.iterator();
  while (mobsToSpawn > 0) {
    if (!stdRoomIter.hasNext())     stdRoomIter=stdRooms.iterator();
    Room roomToSpawn=stdRoomIter.next();
    Mob mob=Bestiary.mob(Dungeon.depth);
    mob.pos=pointToCell(roomToSpawn.random());
    if (findMob(mob.pos) == null && Level.passable[mob.pos]) {
      mobsToSpawn--;
      mobs.add(mob);
      if (mobsToSpawn > 0 && Random.Int(4) == 0) {
        mob=Bestiary.mob(Dungeon.depth);
        mob.pos=pointToCell(roomToSpawn.random());
        if (findMob(mob.pos) == null && Level.passable[mob.pos]) {
          mobsToSpawn--;
          mobs.add(mob);
        }
      }
    }
  }
  for (  Mob m : mobs) {
    if (map[m.pos] == Terrain.HIGH_GRASS) {
      map[m.pos]=Terrain.GRASS;
      losBlocking[m.pos]=false;
    }
  }
}
Program: 163985
Project: 163985
Buggy source:
public synchronized void updateFogCell(int cell){
  updateFogArea(cell % mapWidth,cell / mapHeight,1,1);
}

Fixed version (ground truth):
public synchronized void updateFogCell(int cell){
  updateFogArea(cell % mapWidth,cell / mapWidth,1,1);
}
Program: 163987
Project: 163987
Buggy source:
protected static float angleBetweenRooms(Room from,Room to){
  PointF fromCenter=new PointF((from.left + from.right) / 2f,(from.top + from.bottom) / 2f);
  PointF toCenter=new PointF((to.left + to.right) / 2f,(to.top + to.bottom) / 2f);
  double m=(toCenter.y - fromCenter.y) / (toCenter.x - fromCenter.x);
  return (float)(A * (Math.atan(m) + Math.PI / 2f));
}

Fixed version (ground truth):
protected static float angleBetweenRooms(Room from,Room to){
  PointF fromCenter=new PointF((from.left + from.right) / 2f,(from.top + from.bottom) / 2f);
  PointF toCenter=new PointF((to.left + to.right) / 2f,(to.top + to.bottom) / 2f);
  double m=(toCenter.y - fromCenter.y) / (toCenter.x - fromCenter.x);
  float angle=(float)(A * (Math.atan(m) + Math.PI / 2.0));
  if (fromCenter.x > toCenter.x)   angle-=180f;
  return angle;
}
Program: 163990
Project: 163990
Buggy source:
@SuppressWarnings("String_Node_Str") private static void buildDistanceMap(int to,boolean[] passable){
  System.arraycopy(maxVal,0,distance,0,maxVal.length);
  int head=0;
  int tail=0;
  queue[tail++]=to;
  distance[to]=0;
  while (head < tail) {
    int step=queue[head++];
    int nextDistance=distance[step] + 1;
    for (int i=0; i < dir.length; i++) {
      int n=step + dir[i];
      if (n >= 0 && n < size && passable[n] && (distance[n] > nextDistance)) {
        queue[tail++]=n;
        distance[n]=nextDistance;
      }
    }
  }
}

Fixed version (ground truth):
public static void buildDistanceMap(int to,boolean[] passable){
  System.arraycopy(maxVal,0,distance,0,maxVal.length);
  int head=0;
  int tail=0;
  queue[tail++]=to;
  distance[to]=0;
  while (head < tail) {
    int step=queue[head++];
    int nextDistance=distance[step] + 1;
    int start=(step % width == 0 ? 3 : 0);
    int end=((step + 1) % width == 0 ? 3 : 0);
    for (int i=start; i < dirLR.length - end; i++) {
      int n=step + dirLR[i];
      if (n >= 0 && n < size && passable[n] && (distance[n] > nextDistance)) {
        queue[tail++]=n;
        distance[n]=nextDistance;
      }
    }
  }
}
Program: 163991
Project: 163991
Buggy source:
private static int buildEscapeDistanceMap(int cur,int from,float factor,boolean[] passable){
  System.arraycopy(maxVal,0,distance,0,maxVal.length);
  int destDist=Integer.MAX_VALUE;
  int head=0;
  int tail=0;
  queue[tail++]=from;
  distance[from]=0;
  int dist=0;
  while (head < tail) {
    int step=queue[head++];
    dist=distance[step];
    if (dist > destDist) {
      return destDist;
    }
    if (step == cur) {
      destDist=(int)(dist * factor) + 1;
    }
    int nextDistance=dist + 1;
    for (int i=0; i < dir.length; i++) {
      int n=step + dir[i];
      if (n >= 0 && n < size && passable[n] && distance[n] > nextDistance) {
        queue[tail++]=n;
        distance[n]=nextDistance;
      }
    }
  }
  return dist;
}

Fixed version (ground truth):
private static int buildEscapeDistanceMap(int cur,int from,float factor,boolean[] passable){
  System.arraycopy(maxVal,0,distance,0,maxVal.length);
  int destDist=Integer.MAX_VALUE;
  int head=0;
  int tail=0;
  queue[tail++]=from;
  distance[from]=0;
  int dist=0;
  while (head < tail) {
    int step=queue[head++];
    dist=distance[step];
    if (dist > destDist) {
      return destDist;
    }
    if (step == cur) {
      destDist=(int)(dist * factor) + 1;
    }
    int nextDistance=dist + 1;
    int start=(step % width == 0 ? 3 : 0);
    int end=((step + 1) % width == 0 ? 3 : 0);
    for (int i=start; i < dirLR.length - end; i++) {
      int n=step + dirLR[i];
      if (n >= 0 && n < size && passable[n] && distance[n] > nextDistance) {
        queue[tail++]=n;
        distance[n]=nextDistance;
      }
    }
  }
  return dist;
}
Program: 163992
Project: 163992
Buggy source:
public static void setMapSize(int width,int height){
  int size=width * height;
  PathFinder.size=size;
  distance=new int[size];
  goals=new boolean[size];
  queue=new int[size];
  maxVal=new int[size];
  Arrays.fill(maxVal,Integer.MAX_VALUE);
  dir=new int[]{-1,+1,-width,+width,-width - 1,-width + 1,+width - 1,+width + 1};
  NEIGHBOURS4=new int[]{-width,-1,+1,+width};
  NEIGHBOURS8=new int[]{-width - 1,-width,-width + 1,-1,+1,+width - 1,+width,+width + 1};
  NEIGHBOURS9=new int[]{-width - 1,-width,-width + 1,-1,0,+1,+width - 1,+width,+width + 1};
  CIRCLE4=new int[]{-width,+1,+width,-1};
  CIRCLE8=new int[]{-width - 1,-width,-width + 1,+1,+width + 1,+width,+width - 1,-1};
}

Fixed version (ground truth):
public static void setMapSize(int width,int height){
  PathFinder.width=width;
  PathFinder.size=width * height;
  distance=new int[size];
  goals=new boolean[size];
  queue=new int[size];
  maxVal=new int[size];
  Arrays.fill(maxVal,Integer.MAX_VALUE);
  dir=new int[]{-1,+1,-width,+width,-width - 1,-width + 1,+width - 1,+width + 1};
  dirLR=new int[]{-1 - width,-1,-1 + width,-width,+width,+1 - width,+1,+1 + width};
  NEIGHBOURS4=new int[]{-width,-1,+1,+width};
  NEIGHBOURS8=new int[]{-width - 1,-width,-width + 1,-1,+1,+width - 1,+width,+width + 1};
  NEIGHBOURS9=new int[]{-width - 1,-width,-width + 1,-1,0,+1,+width - 1,+width,+width + 1};
  CIRCLE4=new int[]{-width,+1,+width,-1};
  CIRCLE8=new int[]{-width - 1,-width,-width + 1,+1,+width + 1,+width,+width - 1,-1};
}
Program: 163994
Project: 163994
Buggy source:
public void paint(Level level){
  Painter.fill(level,this,Terrain.WALL);
  Painter.fill(level,this,1,Terrain.EMPTY_SP);
  Door entrance=entrance();
  Painter.fill(level,left + 1,top + 1,width() - 2,1,Terrain.BOOKSHELF);
  if (entrance.y == top) {
    Painter.set(level,entrance.x,entrance.y + 1,Terrain.EMPTY_SP);
  }
 else   if (entrance.y == top + 1) {
    if (entrance.x == left) {
      Painter.set(level,entrance.x + 1,entrance.y,Terrain.EMPTY_SP);
    }
 else {
      Painter.set(level,entrance.x + 1,entrance.y,Terrain.EMPTY_SP);
    }
  }
  int n=Random.IntRange(2,3);
  for (int i=0; i < n; i++) {
    int pos;
    do {
      pos=level.pointToCell(random());
    }
 while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get(pos) != null);
    Item item;
    if (i == 0)     item=Random.Int(2) == 0 ? new ScrollOfIdentify() : new ScrollOfRemoveCurse();
 else     item=prize(level);
    level.drop(item,pos);
  }
  entrance.set(Door.Type.LOCKED);
  level.addItemToSpawn(new IronKey(Dungeon.depth));
}

Fixed version (ground truth):
public void paint(Level level){
  Painter.fill(level,this,Terrain.WALL);
  Painter.fill(level,this,1,Terrain.EMPTY_SP);
  Door entrance=entrance();
  Painter.fill(level,left + 1,top + 1,width() - 2,1,Terrain.BOOKSHELF);
  Painter.drawInside(level,this,entrance,1,Terrain.EMPTY_SP);
  int n=Random.IntRange(2,3);
  for (int i=0; i < n; i++) {
    int pos;
    do {
      pos=level.pointToCell(random());
    }
 while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get(pos) != null);
    Item item;
    if (i == 0)     item=Random.Int(2) == 0 ? new ScrollOfIdentify() : new ScrollOfRemoveCurse();
 else     item=prize(level);
    level.drop(item,pos);
  }
  entrance.set(Door.Type.LOCKED);
  level.addItemToSpawn(new IronKey(Dungeon.depth));
}