nus-yam/ex-repair huggingface dataset:
Program: 158740
Project: 158740
Buggy source:
/** 
 * Resolving a Silence cast from exile via Isochron Scepter during my opponent's upkeep does  not prevent that opponent from casting spells that turn.
 */
@Test public void testSilence(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",4);
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",2);
  addCard(Zone.HAND,playerB,"String_Node_Str",1);
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  addTarget(playerA,"String_Node_Str");
  activateAbility(2,PhaseStep.UPKEEP,playerA,"String_Node_Str");
  setChoice(playerA,"String_Node_Str");
  setChoice(playerA,"String_Node_Str");
  castSpell(2,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  setStopAt(2,PhaseStep.BEGIN_COMBAT);
  execute();
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertExileCount("String_Node_Str",1);
  assertHandCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
}

Fixed version (ground truth):
/** 
 * Resolving a Silence cast from exile via Isochron Scepter during my opponent's upkeep does not prevent that opponent from casting spells that turn.
 */
@Test public void testSilence(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",4);
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",2);
  addCard(Zone.HAND,playerB,"String_Node_Str",1);
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  addTarget(playerA,"String_Node_Str");
  activateAbility(2,PhaseStep.UPKEEP,playerA,"String_Node_Str");
  setChoice(playerA,"String_Node_Str");
  setChoice(playerA,"String_Node_Str");
  castSpell(2,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  setStopAt(2,PhaseStep.BEGIN_COMBAT);
  execute();
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertExileCount("String_Node_Str",1);
  assertHandCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
}
Program: 158742
Project: 158742
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Spell spell=game.getStack().getSpell(source.getSourceId());
    if (spell != null) {
      Card spellCard=spell.getCard();
      if (spellCard != null) {
        Player owner=game.getPlayer(spellCard.getOwnerId());
        if (owner != null) {
          controller.moveCardToLibraryWithInfo(spellCard,source.getSourceId(),game,Zone.STACK,true,true);
          owner.shuffleLibrary(game);
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Spell spell=game.getStack().getSpell(source.getId());
    if (spell != null) {
      if (controller.moveCards(spell,Zone.LIBRARY,source,game) && !spell.isCopy()) {
        Player owner=game.getPlayer(spell.getCard().getOwnerId());
        if (owner != null) {
          owner.shuffleLibrary(game);
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158743
Project: 158743
Buggy source:
public Spell copySpell(){
  return new Spell(this.card.copy(),this.ability.copySpell(),this.controllerId,this.fromZone);
}

Fixed version (ground truth):
public Spell copySpell(){
  return new Spell(this.card,this.ability.copySpell(),this.controllerId,this.fromZone);
}
Program: 158745
Project: 158745
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Spell spell=game.getStack().getSpell(source.getSourceId());
  if (spell != null) {
    SacrificeTargetCost cost=new SacrificeTargetCost(new TargetControlledCreaturePermanent());
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      cost.clearPaid();
      Player player=game.getPlayer(playerId);
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + spell.getIdName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),player.getId(),false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + spell.getIdName()+ "String_Node_Str");
          game.getStack().counter(spell.getId(),source.getSourceId(),game);
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject != null) {
    SacrificeTargetCost cost=new SacrificeTargetCost(new TargetControlledCreaturePermanent());
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      cost.clearPaid();
      Player player=game.getPlayer(playerId);
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + sourceObject.getIdName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),player.getId(),false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + sourceObject.getIdName()+ "String_Node_Str");
          Spell spell=game.getStack().getSpell(source.getSourceId());
          if (spell != null) {
            game.getStack().counter(spell.getId(),source.getSourceId(),game);
          }
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158746
Project: 158746
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Spell spell=game.getStack().getSpell(source.getSourceId());
  if (spell != null) {
    PayLifeCost cost=new PayLifeCost(5);
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      Player player=game.getPlayer(playerId);
      cost.clearPaid();
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + spell.getIdName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),player.getId(),false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + spell.getIdName()+ "String_Node_Str");
          game.getStack().counter(spell.getId(),source.getSourceId(),game);
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject != null) {
    PayLifeCost cost=new PayLifeCost(5);
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      Player player=game.getPlayer(playerId);
      cost.clearPaid();
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + sourceObject.getIdName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),player.getId(),false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + sourceObject.getIdName()+ "String_Node_Str");
          Spell spell=game.getStack().getSpell(source.getSourceId());
          if (spell != null) {
            game.getStack().counter(spell.getId(),source.getSourceId(),game);
          }
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158747
Project: 158747
Buggy source:
@Override public boolean apply(Game game,Ability source){
  StackObject spell=null;
  for (  StackObject objet : game.getStack()) {
    if (objet instanceof Spell && objet.getSourceId().equals(source.getSourceId())) {
      spell=objet;
    }
  }
  if (spell != null) {
    DiscardTargetCost cost=new DiscardTargetCost(new TargetCardInHand(3,3,new FilterCard()));
    for (    UUID uuid : game.getPlayerList()) {
      Player player=game.getPlayer(uuid);
      cost.clearPaid();
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(Outcome.Detriment,"String_Node_Str" + spell.getName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),uuid,false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + spell.getName()+ "String_Node_Str");
          game.getStack().counter(spell.getId(),source.getSourceId(),game);
          return true;
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject != null) {
    DiscardTargetCost cost=new DiscardTargetCost(new TargetCardInHand(3,3,new FilterCard()));
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      Player player=game.getPlayer(playerId);
      cost.clearPaid();
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + sourceObject.getIdName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),playerId,false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + sourceObject.getIdName()+ "String_Node_Str");
          Spell spell=game.getStack().getSpell(source.getSourceId());
          if (spell != null) {
            game.getStack().counter(spell.getId(),source.getSourceId(),game);
          }
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158748
Project: 158748
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Spell spell=game.getStack().getSpell(source.getSourceId());
  if (spell != null) {
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      Player player=game.getPlayer(playerId);
      if (player.chooseUse(outcome,"String_Node_Str" + spell.getIdName() + "String_Node_Str",source,game)) {
        Integer amount=(int)Math.ceil(player.getLife() / 2f);
        player.loseLife(amount,game);
        game.informPlayers(player.getLogName() + "String_Node_Str" + spell.getIdName()+ "String_Node_Str");
        game.getStack().counter(spell.getId(),source.getSourceId(),game);
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject != null) {
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      Player player=game.getPlayer(playerId);
      if (player.chooseUse(outcome,"String_Node_Str" + sourceObject.getIdName() + "String_Node_Str",source,game)) {
        Integer amount=(int)Math.ceil(player.getLife() / 2f);
        player.loseLife(amount,game);
        game.informPlayers(player.getLogName() + "String_Node_Str" + sourceObject.getIdName()+ "String_Node_Str");
        Spell spell=game.getStack().getSpell(source.getSourceId());
        if (spell != null) {
          game.getStack().counter(spell.getId(),source.getSourceId(),game);
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158749
Project: 158749
Buggy source:
@Override public void clearPaid(){
  super.clearPaid();
  cards.clear();
}

Fixed version (ground truth):
@Override public void clearPaid(){
  super.clearPaid();
  this.cards.clear();
  this.targets.clear();
}
Program: 158750
Project: 158750
Buggy source:
@Override public boolean pay(Ability ability,Game game,UUID sourceId,UUID controllerId,boolean noMana){
  this.cards.clear();
  Player player=game.getPlayer(controllerId);
  if (player == null) {
    return false;
  }
  int amount=this.getTargets().get(0).getNumberOfTargets();
  if (randomDiscard) {
    this.cards.addAll(player.discard(amount,true,ability,game).getCards(game));
  }
 else {
    if (targets.choose(Outcome.Discard,controllerId,sourceId,game)) {
      for (      UUID targetId : targets.get(0).getTargets()) {
        Card card=player.getHand().get(targetId,game);
        if (card == null) {
          return false;
        }
        player.discard(card,ability,game);
        this.cards.add(card.copy());
      }
    }
  }
  paid=cards.size() >= amount;
  return paid;
}

Fixed version (ground truth):
@Override public boolean pay(Ability ability,Game game,UUID sourceId,UUID controllerId,boolean noMana){
  this.cards.clear();
  this.targets.clear();
  Player player=game.getPlayer(controllerId);
  if (player == null) {
    return false;
  }
  int amount=this.getTargets().get(0).getNumberOfTargets();
  if (randomDiscard) {
    this.cards.addAll(player.discard(amount,true,ability,game).getCards(game));
  }
 else {
    if (targets.choose(Outcome.Discard,controllerId,sourceId,game)) {
      for (      UUID targetId : targets.get(0).getTargets()) {
        Card card=player.getHand().get(targetId,game);
        if (card == null) {
          return false;
        }
        player.discard(card,ability,game);
        this.cards.add(card.copy());
      }
    }
  }
  paid=cards.size() >= amount;
  return paid;
}
Program: 158751
Project: 158751
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Spell spell=game.getStack().getSpell(source.getSourceId());
  if (spell != null) {
    SacrificeTargetCost cost=new SacrificeTargetCost(new TargetControlledCreaturePermanent());
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      cost.clearPaid();
      Player player=game.getPlayer(playerId);
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + spell.getIdName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),player.getId(),false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + spell.getIdName()+ "String_Node_Str");
          game.getStack().counter(spell.getId(),source.getSourceId(),game);
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject != null) {
    SacrificeTargetCost cost=new SacrificeTargetCost(new TargetControlledCreaturePermanent());
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      cost.clearPaid();
      Player player=game.getPlayer(playerId);
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + sourceObject.getIdName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),player.getId(),false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + sourceObject.getIdName()+ "String_Node_Str");
          Spell spell=game.getStack().getSpell(source.getSourceId());
          if (spell != null) {
            game.getStack().counter(spell.getId(),source.getSourceId(),game);
          }
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158752
Project: 158752
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Spell spell=game.getStack().getSpell(source.getSourceId());
  if (spell != null) {
    PayLifeCost cost=new PayLifeCost(5);
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      Player player=game.getPlayer(playerId);
      cost.clearPaid();
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + spell.getIdName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),player.getId(),false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + spell.getIdName()+ "String_Node_Str");
          game.getStack().counter(spell.getId(),source.getSourceId(),game);
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject != null) {
    PayLifeCost cost=new PayLifeCost(5);
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      Player player=game.getPlayer(playerId);
      cost.clearPaid();
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + sourceObject.getIdName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),player.getId(),false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + sourceObject.getIdName()+ "String_Node_Str");
          Spell spell=game.getStack().getSpell(source.getSourceId());
          if (spell != null) {
            game.getStack().counter(spell.getId(),source.getSourceId(),game);
          }
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158753
Project: 158753
Buggy source:
@Override public boolean apply(Game game,Ability source){
  StackObject spell=null;
  for (  StackObject objet : game.getStack()) {
    if (objet instanceof Spell && objet.getSourceId().equals(source.getSourceId())) {
      spell=objet;
    }
  }
  if (spell != null) {
    DiscardTargetCost cost=new DiscardTargetCost(new TargetCardInHand(3,3,new FilterCard()));
    for (    UUID uuid : game.getPlayerList()) {
      Player player=game.getPlayer(uuid);
      cost.clearPaid();
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(Outcome.Detriment,"String_Node_Str" + spell.getName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),uuid,false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + spell.getName()+ "String_Node_Str");
          game.getStack().counter(spell.getId(),source.getSourceId(),game);
          return true;
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject != null) {
    DiscardTargetCost cost=new DiscardTargetCost(new TargetCardInHand(3,3,new FilterCard()));
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      Player player=game.getPlayer(playerId);
      cost.clearPaid();
      if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + sourceObject.getIdName() + "String_Node_Str",source,game)) {
        if (cost.pay(source,game,source.getSourceId(),playerId,false)) {
          game.informPlayers(player.getLogName() + "String_Node_Str" + sourceObject.getIdName()+ "String_Node_Str");
          Spell spell=game.getStack().getSpell(source.getSourceId());
          if (spell != null) {
            game.getStack().counter(spell.getId(),source.getSourceId(),game);
          }
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158754
Project: 158754
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Spell spell=game.getStack().getSpell(source.getSourceId());
  if (spell != null) {
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      Player player=game.getPlayer(playerId);
      if (player.chooseUse(outcome,"String_Node_Str" + spell.getIdName() + "String_Node_Str",source,game)) {
        Integer amount=(int)Math.ceil(player.getLife() / 2f);
        player.loseLife(amount,game);
        game.informPlayers(player.getLogName() + "String_Node_Str" + spell.getIdName()+ "String_Node_Str");
        game.getStack().counter(spell.getId(),source.getSourceId(),game);
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject != null) {
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      Player player=game.getPlayer(playerId);
      if (player.chooseUse(outcome,"String_Node_Str" + sourceObject.getIdName() + "String_Node_Str",source,game)) {
        Integer amount=(int)Math.ceil(player.getLife() / 2f);
        player.loseLife(amount,game);
        game.informPlayers(player.getLogName() + "String_Node_Str" + sourceObject.getIdName()+ "String_Node_Str");
        Spell spell=game.getStack().getSpell(source.getSourceId());
        if (spell != null) {
          game.getStack().counter(spell.getId(),source.getSourceId(),game);
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158755
Project: 158755
Buggy source:
@Override public void clearPaid(){
  super.clearPaid();
  cards.clear();
}

Fixed version (ground truth):
@Override public void clearPaid(){
  super.clearPaid();
  this.cards.clear();
  this.targets.clear();
}
Program: 158756
Project: 158756
Buggy source:
@Override public boolean pay(Ability ability,Game game,UUID sourceId,UUID controllerId,boolean noMana){
  this.cards.clear();
  Player player=game.getPlayer(controllerId);
  if (player == null) {
    return false;
  }
  int amount=this.getTargets().get(0).getNumberOfTargets();
  if (randomDiscard) {
    this.cards.addAll(player.discard(amount,true,ability,game).getCards(game));
  }
 else {
    if (targets.choose(Outcome.Discard,controllerId,sourceId,game)) {
      for (      UUID targetId : targets.get(0).getTargets()) {
        Card card=player.getHand().get(targetId,game);
        if (card == null) {
          return false;
        }
        player.discard(card,ability,game);
        this.cards.add(card.copy());
      }
    }
  }
  paid=cards.size() >= amount;
  return paid;
}

Fixed version (ground truth):
@Override public boolean pay(Ability ability,Game game,UUID sourceId,UUID controllerId,boolean noMana){
  this.cards.clear();
  this.targets.clear();
  Player player=game.getPlayer(controllerId);
  if (player == null) {
    return false;
  }
  int amount=this.getTargets().get(0).getNumberOfTargets();
  if (randomDiscard) {
    this.cards.addAll(player.discard(amount,true,ability,game).getCards(game));
  }
 else {
    if (targets.choose(Outcome.Discard,controllerId,sourceId,game)) {
      for (      UUID targetId : targets.get(0).getTargets()) {
        Card card=player.getHand().get(targetId,game);
        if (card == null) {
          return false;
        }
        player.discard(card,ability,game);
        this.cards.add(card.copy());
      }
    }
  }
  paid=cards.size() >= amount;
  return paid;
}
Program: 158758
Project: 158758
Buggy source:
public ManaType asThoughMana(ManaType manaType,ManaPoolItem mana,UUID objectId,Ability affectedAbility,UUID controllerId,Game game){
  List<AsThoughEffect> asThoughEffectsList=getApplicableAsThoughEffects(AsThoughEffectType.SPEND_ONLY_MANA,game);
  for (  AsThoughEffect effect : asThoughEffectsList) {
    HashSet<Ability> abilities=asThoughEffectsMap.get(AsThoughEffectType.SPEND_ONLY_MANA).getAbility(effect.getId());
    for (    Ability ability : abilities) {
      if ((affectedAbility == null && effect.applies(objectId,ability,controllerId,game)) || effect.applies(objectId,affectedAbility,ability,game)) {
        if (((AsThoughManaEffect)effect).getAsThoughtManaType(manaType,mana,controllerId,ability,game) == null) {
          return null;
        }
      }
    }
  }
  asThoughEffectsList=getApplicableAsThoughEffects(AsThoughEffectType.SPEND_OTHER_MANA,game);
  for (  AsThoughEffect effect : asThoughEffectsList) {
    HashSet<Ability> abilities=asThoughEffectsMap.get(AsThoughEffectType.SPEND_OTHER_MANA).getAbility(effect.getId());
    for (    Ability ability : abilities) {
      if ((affectedAbility == null && effect.applies(objectId,ability,controllerId,game)) || effect.applies(objectId,affectedAbility,ability,game)) {
        ManaType usableManaType=((AsThoughManaEffect)effect).getAsThoughtManaType(manaType,mana,controllerId,ability,game);
        if (usableManaType != null) {
          return usableManaType;
        }
      }
    }
  }
  return manaType;
}

Fixed version (ground truth):
public ManaType asThoughMana(ManaType manaType,ManaPoolItem mana,UUID objectId,Ability affectedAbility,UUID controllerId,Game game){
  List<AsThoughEffect> asThoughEffectsList=getApplicableAsThoughEffects(AsThoughEffectType.SPEND_ONLY_MANA,game);
  for (  AsThoughEffect effect : asThoughEffectsList) {
    HashSet<Ability> abilities=asThoughEffectsMap.get(AsThoughEffectType.SPEND_ONLY_MANA).getAbility(effect.getId());
    for (    Ability ability : abilities) {
      if ((affectedAbility == null && effect.applies(objectId,ability,controllerId,game)) || effect.applies(objectId,affectedAbility,ability,game)) {
        if (((AsThoughManaEffect)effect).getAsThoughManaType(manaType,mana,controllerId,ability,game) == null) {
          return null;
        }
      }
    }
  }
  asThoughEffectsList=getApplicableAsThoughEffects(AsThoughEffectType.SPEND_OTHER_MANA,game);
  for (  AsThoughEffect effect : asThoughEffectsList) {
    HashSet<Ability> abilities=asThoughEffectsMap.get(AsThoughEffectType.SPEND_OTHER_MANA).getAbility(effect.getId());
    for (    Ability ability : abilities) {
      if ((affectedAbility == null && effect.applies(objectId,ability,controllerId,game)) || effect.applies(objectId,affectedAbility,ability,game)) {
        ManaType usableManaType=((AsThoughManaEffect)effect).getAsThoughManaType(manaType,mana,controllerId,ability,game);
        if (usableManaType != null) {
          return usableManaType;
        }
      }
    }
  }
  return manaType;
}
Program: 158759
Project: 158759
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
switch (((ZoneChangeEvent)event).getToZone()) {
case HAND:
    if (!alsoHand && ((ZoneChangeEvent)event).getToZone() == Zone.HAND) {
      return false;
    }
case LIBRARY:
  if (!alsoLibrary && ((ZoneChangeEvent)event).getToZone() == Zone.LIBRARY) {
    return false;
  }
case GRAVEYARD:
case EXILED:
if (commanderId.equals(event.getTargetId())) {
  return true;
}
break;
case STACK:
Spell spell=game.getStack().getSpell(event.getTargetId());
if (spell != null) {
if (commanderId.equals(spell.getSourceId())) {
return true;
}
}
break;
}
return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
switch (((ZoneChangeEvent)event).getToZone()) {
case HAND:
    if (!alsoHand && ((ZoneChangeEvent)event).getToZone() == Zone.HAND) {
      return false;
    }
case LIBRARY:
  if (!alsoLibrary && ((ZoneChangeEvent)event).getToZone() == Zone.LIBRARY) {
    return false;
  }
case GRAVEYARD:
case EXILED:
if (((ZoneChangeEvent)event).getFromZone().equals(Zone.STACK)) {
  Spell spell=game.getStack().getSpell(event.getTargetId());
  if (spell != null && commanderId.equals(spell.getSourceId())) {
    return true;
  }
}
if (commanderId.equals(event.getTargetId())) {
return true;
}
break;
case STACK:
Spell spell=game.getStack().getSpell(event.getTargetId());
if (spell != null) {
if (commanderId.equals(spell.getSourceId())) {
return true;
}
}
break;
}
return false;
}
Program: 158761
Project: 158761
Buggy source:
/** 
 * Selects a defender for an attacker and adds the attacker to combat
 * @param defenders - list of possible defender
 * @param attackerId - UUID of attacker
 * @param game
 * @return
 */
protected boolean selectDefender(Set<UUID> defenders,UUID attackerId,Game game){
  boolean forcedToAttack=false;
  Set<UUID> possibleDefender=game.getCombat().getCreaturesForcedToAttack().get(attackerId);
  if (possibleDefender != null) {
    forcedToAttack=true;
  }
  if (possibleDefender == null || possibleDefender.isEmpty()) {
    possibleDefender=defenders;
  }
  if (possibleDefender.size() == 1) {
    declareAttacker(attackerId,defenders.iterator().next(),game,true);
    return true;
  }
 else {
    TargetDefender target=new TargetDefender(possibleDefender,attackerId);
    target.setNotTarget(true);
    if (forcedToAttack) {
      StringBuilder sb=new StringBuilder(target.getTargetName());
      Permanent attacker=game.getPermanent(attackerId);
      if (attacker != null) {
        sb.append("String_Node_Str").append(attacker.getName()).append("String_Node_Str");
        target.setTargetName(sb.toString());
      }
    }
    if (chooseTarget(Outcome.Damage,target,null,game)) {
      declareAttacker(attackerId,response.getUUID(),game,true);
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Selects a defender for an attacker and adds the attacker to combat
 * @param defenders - list of possible defender
 * @param attackerId - UUID of attacker
 * @param game
 * @return
 */
protected boolean selectDefender(Set<UUID> defenders,UUID attackerId,Game game){
  boolean forcedToAttack=false;
  Set<UUID> possibleDefender=game.getCombat().getCreaturesForcedToAttack().get(attackerId);
  if (possibleDefender != null) {
    forcedToAttack=true;
  }
  if (possibleDefender == null || possibleDefender.isEmpty()) {
    possibleDefender=defenders;
  }
  if (possibleDefender.size() == 1) {
    declareAttacker(attackerId,possibleDefender.iterator().next(),game,true);
    return true;
  }
 else {
    TargetDefender target=new TargetDefender(possibleDefender,attackerId);
    target.setNotTarget(true);
    if (forcedToAttack) {
      StringBuilder sb=new StringBuilder(target.getTargetName());
      Permanent attacker=game.getPermanent(attackerId);
      if (attacker != null) {
        sb.append("String_Node_Str").append(attacker.getName()).append("String_Node_Str");
        target.setTargetName(sb.toString());
      }
    }
    if (chooseTarget(Outcome.Damage,target,null,game)) {
      declareAttacker(attackerId,response.getUUID(),game,true);
      return true;
    }
  }
  return false;
}
Program: 158762
Project: 158762
Buggy source:
@Override public boolean isInactive(Ability source,Game game){
  if (targetPermanentReference == null) {
    return true;
  }
  Permanent targetPermanent=targetPermanentReference.getPermanent(game);
  if (targetPermanent == null) {
    return true;
  }
  if (nextTurnTargetController == 0 && startingTurn != game.getTurnNum() && game.getActivePlayerId().equals(targetPermanent.getControllerId())) {
    nextTurnTargetController=game.getTurnNum();
  }
  if (game.getPhase().getType() == TurnPhase.END && nextTurnTargetController > 0 && game.getTurnNum() > nextTurnTargetController) {
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean isInactive(Ability source,Game game){
  if (targetPermanentReference == null) {
    return true;
  }
  Permanent targetPermanent=targetPermanentReference.getPermanent(game);
  if (targetPermanent == null) {
    return true;
  }
  if (nextTurnTargetController == 0 && startingTurn != game.getTurnNum() && game.getActivePlayerId().equals(targetPermanent.getControllerId())) {
    nextTurnTargetController=game.getTurnNum();
  }
  return game.getPhase().getType() == TurnPhase.END && nextTurnTargetController > 0 && game.getTurnNum() > nextTurnTargetController;
}
Program: 158765
Project: 158765
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  MageObject sourceObject=game.getObject(source.getSourceId());
  if (controller != null) {
    Player targetPlayer=game.getPlayer(getTargetPointer().getFirst(game,source));
    if (targetPlayer != null) {
      if (targetPlayer.getHand().size() > 0) {
        Cards cards=new CardsImpl();
        Card card=targetPlayer.getHand().getRandom(game);
        cards.add(card);
        if (targetPlayer.getHand().size() > 1) {
          do {
            card=targetPlayer.getHand().getRandom(game);
          }
 while (cards.contains(card.getId()));
          cards.add(card);
        }
        targetPlayer.revealCards(sourceObject.getName(),cards,game);
        for (        Card cardToDiscard : cards.getCards(game)) {
          if (!cardToDiscard.getCardType().contains(CardType.LAND)) {
            targetPlayer.discard(cardToDiscard,source,game);
          }
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  MageObject sourceObject=game.getObject(source.getSourceId());
  if (controller != null) {
    Player targetPlayer=game.getPlayer(getTargetPointer().getFirst(game,source));
    if (targetPlayer != null) {
      if (targetPlayer.getHand().size() > 0) {
        Cards cards=new CardsImpl();
        Card card=targetPlayer.getHand().getRandom(game);
        cards.add(card);
        if (targetPlayer.getHand().size() > 1) {
          do {
            card=targetPlayer.getHand().getRandom(game);
          }
 while (cards.contains(card.getId()));
          cards.add(card);
        }
        targetPlayer.revealCards(sourceObject.getIdName(),cards,game);
        for (        Card cardToDiscard : cards.getCards(game)) {
          if (!cardToDiscard.getCardType().contains(CardType.LAND)) {
            targetPlayer.discard(cardToDiscard,source,game);
          }
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158766
Project: 158766
Buggy source:
@Override public boolean isLegal(Ability source,Game game){
  Set<UUID> illegalTargets=new HashSet<>();
  for (  UUID targetId : targets.keySet()) {
    Card card=game.getCard(targetId);
    if (card != null) {
      if (zoneChangeCounters.containsKey(targetId) && zoneChangeCounters.get(targetId) != card.getZoneChangeCounter(game)) {
        illegalTargets.add(targetId);
        continue;
      }
    }
    if (!notTarget && game.replaceEvent(GameEvent.getEvent(EventType.TARGET,targetId,source.getSourceId(),source.getControllerId()))) {
      illegalTargets.add(targetId);
      continue;
    }
    if (!canTarget(targetId,source,game)) {
      illegalTargets.add(targetId);
    }
  }
  for (  UUID targetId : illegalTargets) {
    targets.remove(targetId);
  }
  if (getNumberOfTargets() == 0 && targets.isEmpty()) {
    return true;
  }
  return targets.size() > 0;
}

Fixed version (ground truth):
@Override public boolean isLegal(Ability source,Game game){
  Set<UUID> illegalTargets=new HashSet<>();
  for (  UUID targetId : targets.keySet()) {
    Card card=game.getCard(targetId);
    if (card != null) {
      if (zoneChangeCounters.containsKey(targetId) && zoneChangeCounters.get(targetId) != card.getZoneChangeCounter(game)) {
        illegalTargets.add(targetId);
        continue;
      }
    }
    if (!notTarget && game.replaceEvent(GameEvent.getEvent(EventType.TARGET,targetId,source.getSourceId(),source.getControllerId()))) {
      illegalTargets.add(targetId);
      continue;
    }
    if (!canTarget(targetId,source,game)) {
      illegalTargets.add(targetId);
    }
  }
  for (  UUID targetId : illegalTargets) {
    targets.remove(targetId);
  }
  if (targets.isEmpty()) {
    if (!illegalTargets.isEmpty()) {
      return false;
    }
    if (getNumberOfTargets() == 0) {
      return true;
    }
  }
  return targets.size() > 0;
}
Program: 158768
Project: 158768
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event.getPlayerId().equals(this.getControllerId())) {
    Spell spell=game.getStack().getSpell(event.getTargetId());
    if (isControlledInstantOrSorcery(spell)) {
      boolean targetsSource=false;
      for (      Target target : spell.getSpellAbility().getTargets()) {
        for (        UUID targetId : target.getTargets()) {
          if (targetId.equals(getSourceId())) {
            targetsSource=true;
          }
 else {
            return false;
          }
        }
      }
      if (targetsSource) {
        this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getId()));
        return true;
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event.getPlayerId().equals(this.getControllerId())) {
    Spell spell=game.getStack().getSpell(event.getTargetId());
    if (isControlledInstantOrSorcery(spell)) {
      boolean targetsSource=false;
      for (      UUID modeId : spell.getSpellAbility().getModes().getSelectedModes()) {
        spell.getSpellAbility().getModes().setActiveMode(modeId);
        for (        Target target : spell.getSpellAbility().getTargets()) {
          for (          UUID targetId : target.getTargets()) {
            if (targetId.equals(getSourceId())) {
              targetsSource=true;
            }
 else {
              return false;
            }
          }
        }
      }
      if (targetsSource) {
        this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getId()));
        return true;
      }
    }
  }
  return false;
}
Program: 158771
Project: 158771
Buggy source:
public UUID getDefendingPlayerId(UUID attackerId,Game game){
  UUID defenderId=null;
  for (  CombatGroup group : groups) {
    if (group.getAttackers().contains(attackerId)) {
      defenderId=group.getDefenderId();
      if (group.defenderIsPlaneswalker) {
        Permanent permanent=game.getPermanent(defenderId);
        if (permanent != null) {
          defenderId=permanent.getControllerId();
        }
 else {
          defenderId=null;
        }
      }
      break;
    }
  }
  return defenderId;
}

Fixed version (ground truth):
public UUID getDefendingPlayerId(UUID attackingCreatureId,Game game){
  UUID defenderId=null;
  for (  CombatGroup group : groups) {
    if (group.getAttackers().contains(attackingCreatureId)) {
      defenderId=group.getDefenderId();
      if (group.defenderIsPlaneswalker) {
        Permanent permanent=game.getPermanent(defenderId);
        if (permanent != null) {
          defenderId=permanent.getControllerId();
        }
 else {
          defenderId=null;
        }
      }
      break;
    }
  }
  return defenderId;
}
Program: 158774
Project: 158774
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller == null) {
    return false;
  }
  int value=amount.calculate(game,source,this);
  boolean result=false;
  ChoiceColor choice=new ChoiceColor();
  for (int i=0; i < value; i++) {
    if (!choice.isChosen()) {
      if (!controller.choose(outcome,choice,game)) {
        return false;
      }
    }
    Mana mana=null;
    if (choice.getColor().isBlack()) {
      mana=manaBuilder.setMana(Mana.BlackMana(1),source,game).build();
    }
 else     if (choice.getColor().isBlue()) {
      mana=manaBuilder.setMana(Mana.BlueMana(1),source,game).build();
    }
 else     if (choice.getColor().isRed()) {
      mana=manaBuilder.setMana(Mana.RedMana(1),source,game).build();
    }
 else     if (choice.getColor().isGreen()) {
      mana=manaBuilder.setMana(Mana.GreenMana(1),source,game).build();
    }
 else     if (choice.getColor().isWhite()) {
      mana=manaBuilder.setMana(Mana.WhiteMana(1),source,game).build();
    }
    if (mana != null) {
      checkToFirePossibleEvents(mana,game,source);
      controller.getManaPool().addMana(mana,game,source);
      result=true;
    }
    if (!oneChoice) {
      choice.clearChoice();
    }
  }
  return result;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller == null) {
    return false;
  }
  int value=amount.calculate(game,source,this);
  boolean result=false;
  ChoiceColor choice=new ChoiceColor(false);
  for (int i=0; i < value; i++) {
    if (!choice.isChosen()) {
      if (!controller.choose(outcome,choice,game)) {
        return false;
      }
    }
    Mana mana=null;
    if (choice.getColor().isBlack()) {
      mana=manaBuilder.setMana(Mana.BlackMana(1),source,game).build();
    }
 else     if (choice.getColor().isBlue()) {
      mana=manaBuilder.setMana(Mana.BlueMana(1),source,game).build();
    }
 else     if (choice.getColor().isRed()) {
      mana=manaBuilder.setMana(Mana.RedMana(1),source,game).build();
    }
 else     if (choice.getColor().isGreen()) {
      mana=manaBuilder.setMana(Mana.GreenMana(1),source,game).build();
    }
 else     if (choice.getColor().isWhite()) {
      mana=manaBuilder.setMana(Mana.WhiteMana(1),source,game).build();
    }
    if (mana != null) {
      checkToFirePossibleEvents(mana,game,source);
      controller.getManaPool().addMana(mana,game,source);
      result=true;
    }
    if (!oneChoice) {
      choice.clearChoice();
    }
  }
  return result;
}
Program: 158775
Project: 158775
Buggy source:
/** 
 * Execute action.
 * @param game Game context.
 */
public abstract int doAction(final Game game);

Fixed version (ground truth):
/** 
 * Execute action.
 * @param game Game context.
 * @return
 */
public abstract int doAction(final Game game);
Program: 158776
Project: 158776
Buggy source:
/** 
 * Set or change action score.
 * @param scorePlayer Set player.
 * @param score       Set score value.
 */
protected void setScore(Player scorePlayer,int score){
  this.scorePlayer=scorePlayer;
  this.score=score;
}

Fixed version (ground truth):
/** 
 * Set or change action score.
 * @param scorePlayer Set player.
 * @param score Set score value.
 */
protected void setScore(Player scorePlayer,int score){
  this.scorePlayer=scorePlayer;
  this.score=score;
}
Program: 158777
Project: 158777
Buggy source:
@Override public synchronized void concede(UUID playerId){
  Player player=state.getPlayer(playerId);
  if (player != null) {
    logger.debug(new StringBuilder("String_Node_Str").append(player.getName()).append("String_Node_Str").append(this.getId()));
    fireInformEvent(player.getLogName() + "String_Node_Str");
    player.concede(this);
  }
}

Fixed version (ground truth):
@Override public synchronized void concede(UUID playerId){
  Player player=state.getPlayer(playerId);
  if (player != null) {
    logger.debug("String_Node_Str" + player.getName() + "String_Node_Str"+ this.getId());
    fireInformEvent(player.getLogName() + "String_Node_Str");
    player.concede(this);
  }
}
Program: 158778
Project: 158778
Buggy source:
protected boolean specialAction(SpecialAction action,Game game){
  if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY,action.getSourceId(),action.getId(),playerId))) {
    int bookmark=game.bookmarkState();
    if (action.activate(game,false)) {
      game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY,action.getSourceId(),action.getId(),playerId));
      if (!game.isSimulation()) {
        game.informPlayers(getLogName() + action.getGameLogMessage(game));
      }
      if (action.resolve(game)) {
        game.removeBookmark(bookmark);
        resetStoredBookmark(game);
        return true;
      }
    }
    game.restoreState(bookmark,action.getRule());
  }
  return false;
}

Fixed version (ground truth):
protected boolean specialAction(SpecialAction action,Game game){
  if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY,action.getSourceId(),action.getId(),playerId))) {
    int bookmark=game.bookmarkState();
    if (action.activate(game,false)) {
      game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY,action.getSourceId(),action.getId(),playerId));
      if (!game.isSimulation()) {
        game.informPlayers(getLogName() + action.getGameLogMessage(game));
      }
      if (action.resolve(game)) {
        game.removeBookmark(bookmark);
        resetStoredBookmark(game);
        return true;
      }
    }
    restoreState(bookmark,action.getRule(),game);
  }
  return false;
}
Program: 158780
Project: 158780
Buggy source:
protected boolean playManaAbility(ManaAbility ability,Game game){
  if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY,ability.getId(),ability.getSourceId(),playerId))) {
    int bookmark=game.bookmarkState();
    if (ability.activate(game,false)) {
      if (ability.resolve(game)) {
        if (ability.isUndoPossible() && (storedBookmark == -1 || storedBookmark > bookmark)) {
          setStoredBookmark(bookmark);
        }
 else {
          resetStoredBookmark(game);
        }
        return true;
      }
    }
    game.restoreState(bookmark,ability.getRule());
  }
  return false;
}

Fixed version (ground truth):
protected boolean playManaAbility(ManaAbility ability,Game game){
  if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY,ability.getId(),ability.getSourceId(),playerId))) {
    int bookmark=game.bookmarkState();
    if (ability.activate(game,false)) {
      if (ability.resolve(game)) {
        if (ability.isUndoPossible()) {
          if (storedBookmark == -1 || storedBookmark > bookmark) {
            setStoredBookmark(bookmark);
          }
        }
 else {
          resetStoredBookmark(game);
        }
        return true;
      }
    }
    restoreState(bookmark,ability.getRule(),game);
  }
  return false;
}
Program: 158781
Project: 158781
Buggy source:
protected boolean playAbility(ActivatedAbility ability,Game game){
  if (ability.isUsesStack()) {
    if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY,ability.getId(),ability.getSourceId(),playerId))) {
      int bookmark=game.bookmarkState();
      ability.newId();
      game.getStack().push(new StackAbility(ability,playerId));
      if (ability.activate(game,false)) {
        game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY,ability.getId(),ability.getSourceId(),playerId));
        if (!game.isSimulation()) {
          game.informPlayers(getLogName() + ability.getGameLogMessage(game));
        }
        game.removeBookmark(bookmark);
        resetStoredBookmark(game);
        return true;
      }
      game.restoreState(bookmark,ability.getRule());
    }
  }
 else {
    int bookmark=game.bookmarkState();
    if (ability.activate(game,false)) {
      ability.resolve(game);
      game.removeBookmark(bookmark);
      resetStoredBookmark(game);
      return true;
    }
    game.restoreState(bookmark,ability.getRule());
  }
  return false;
}

Fixed version (ground truth):
protected boolean playAbility(ActivatedAbility ability,Game game){
  if (ability.isUsesStack()) {
    if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY,ability.getId(),ability.getSourceId(),playerId))) {
      int bookmark=game.bookmarkState();
      ability.newId();
      game.getStack().push(new StackAbility(ability,playerId));
      if (ability.activate(game,false)) {
        game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY,ability.getId(),ability.getSourceId(),playerId));
        if (!game.isSimulation()) {
          game.informPlayers(getLogName() + ability.getGameLogMessage(game));
        }
        game.removeBookmark(bookmark);
        resetStoredBookmark(game);
        return true;
      }
      restoreState(bookmark,ability.getRule(),game);
    }
  }
 else {
    int bookmark=game.bookmarkState();
    if (ability.activate(game,false)) {
      ability.resolve(game);
      game.removeBookmark(bookmark);
      resetStoredBookmark(game);
      return true;
    }
    restoreState(bookmark,ability.getRule(),game);
  }
  return false;
}