nus-yam/ex-repair huggingface dataset:
Program: 158228
Project: 158228
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Card card=game.getCard(source.getFirstTarget());
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null && card != null) {
    if (controller.moveCards(card,Zone.EXILED,source,game)) {
      PutTokenOntoBattlefieldCopyTargetEffect effect=new PutTokenOntoBattlefieldCopyTargetEffect(source.getControllerId(),null,false);
      effect.setTargetPointer(new FixedTarget(card.getId(),card.getZoneChangeCounter(game)));
      effect.setAdditionalSubType("String_Node_Str");
      effect.apply(game,source);
      ExileTargetEffect exileEffect=new ExileTargetEffect();
      exileEffect.setTargetPointer(new FixedTargets(effect.getAddedPermanent(),game));
      DelayedTriggeredAbility delayedAbility=new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
      game.addDelayedTriggeredAbility(delayedAbility,source);
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Card card=game.getCard(source.getFirstTarget());
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null && card != null) {
    controller.moveCards(card,Zone.EXILED,source,game);
    PutTokenOntoBattlefieldCopyTargetEffect effect=new PutTokenOntoBattlefieldCopyTargetEffect(source.getControllerId(),null,false);
    effect.setTargetPointer(new FixedTarget(card.getId(),card.getZoneChangeCounter(game)));
    effect.setAdditionalSubType("String_Node_Str");
    effect.apply(game,source);
    ExileTargetEffect exileEffect=new ExileTargetEffect();
    exileEffect.setTargetPointer(new FixedTargets(effect.getAddedPermanent(),game));
    DelayedTriggeredAbility delayedAbility=new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
    game.addDelayedTriggeredAbility(delayedAbility,source);
    return true;
  }
  return false;
}
Program: 158229
Project: 158229
Buggy source:
@Override public boolean apply(Game game,Ability source){
  int cmc=0;
  for (  Cost cost : source.getCosts()) {
    if (cost instanceof SacrificeTargetCost && ((SacrificeTargetCost)cost).getPermanents().size() > 0) {
      cmc=((SacrificeTargetCost)cost).getPermanents().get(0).getConvertedManaCost();
      break;
    }
  }
  for (  Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(),game)) {
    if (permanent.getConvertedManaCost() == cmc) {
      permanent.destroy(source.getSourceId(),game,false);
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  int cmc=0;
  for (  Cost cost : source.getCosts()) {
    if (cost instanceof SacrificeTargetCost && ((SacrificeTargetCost)cost).getPermanents().size() > 0) {
      cmc=((SacrificeTargetCost)cost).getPermanents().get(0).getConvertedManaCost();
      break;
    }
  }
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(),source.getControllerId(),game)) {
    if (permanent.getConvertedManaCost() == cmc) {
      permanent.destroy(source.getSourceId(),game,false);
    }
  }
  return true;
}
Program: 158230
Project: 158230
Buggy source:
@Override public boolean resolve(Game game){
  if (isOptional()) {
    MageObject object=game.getObject(getSourceId());
    Player player=game.getPlayer(this.getControllerId());
    if (player != null && object != null) {
      if (!player.chooseUse(getEffects().get(0).getOutcome(),this.getRule(object.getLogName()),this,game)) {
        return false;
      }
    }
 else {
      return false;
    }
  }
  if (checkInterveningIfClause(game)) {
    return super.resolve(game);
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean resolve(Game game){
  if (isOptional()) {
    MageObject object=game.getObject(getSourceId());
    Player player=game.getPlayer(this.getControllerId());
    if (player != null && object != null) {
      if (!player.chooseUse(getEffects().isEmpty() ? Outcome.Detriment : getEffects().get(0).getOutcome(),this.getRule(object.getLogName()),this,game)) {
        return false;
      }
    }
 else {
      return false;
    }
  }
  if (checkInterveningIfClause(game)) {
    return super.resolve(game);
  }
  return false;
}
Program: 158231
Project: 158231
Buggy source:
@Override public StackObject createCopyOnStack(Game game,Ability source,UUID newControllerId,boolean chooseNewTargets){
  Ability newAbility=this.copy();
  newAbility.newId();
  StackAbility newStackAbility=new StackAbility(newAbility,newControllerId);
  game.getStack().push(newStackAbility);
  if (chooseNewTargets && newAbility.getTargets().size() > 0) {
    Player controller=game.getPlayer(newControllerId);
    if (controller.chooseUse(newAbility.getEffects().get(0).getOutcome(),"String_Node_Str",source,game)) {
      newAbility.getTargets().clearChosen();
      newAbility.getTargets().chooseTargets(newAbility.getEffects().get(0).getOutcome(),newControllerId,newAbility,false,game);
    }
  }
  game.fireEvent(new GameEvent(GameEvent.EventType.COPIED_STACKOBJECT,newStackAbility.getId(),this.getId(),newControllerId));
  return newStackAbility;
}

Fixed version (ground truth):
@Override public StackObject createCopyOnStack(Game game,Ability source,UUID newControllerId,boolean chooseNewTargets){
  Ability newAbility=this.copy();
  newAbility.newId();
  StackAbility newStackAbility=new StackAbility(newAbility,newControllerId);
  game.getStack().push(newStackAbility);
  if (chooseNewTargets && newAbility.getTargets().size() > 0) {
    Player controller=game.getPlayer(newControllerId);
    Outcome outcome=newAbility.getEffects().isEmpty() ? Outcome.Detriment : newAbility.getEffects().get(0).getOutcome();
    if (controller.chooseUse(outcome,"String_Node_Str",source,game)) {
      newAbility.getTargets().clearChosen();
      newAbility.getTargets().chooseTargets(outcome,newControllerId,newAbility,false,game);
    }
  }
  game.fireEvent(new GameEvent(GameEvent.EventType.COPIED_STACKOBJECT,newStackAbility.getId(),this.getId(),newControllerId));
  return newStackAbility;
}
Program: 158233
Project: 158233
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,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;
}

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)) {
      UUID defenderId=response.getUUID();
      for (      Player player : game.getPlayers().values()) {
        if (player.getId().equals(response.getUUID())) {
          defenderId=player.getId();
          break;
        }
      }
      declareAttacker(attackerId,defenderId,game,true);
      return true;
    }
  }
  return false;
}
Program: 158235
Project: 158235
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Permanent controlledCreature=game.getPermanent(source.getFirstTarget());
  if (controlledCreature != null) {
    DelayedTriggeredAbility delayedAbility=new MeriekeRiBeritDelayedTriggeredAbility();
    delayedAbility.getEffects().get(0).setTargetPointer(new FixedTarget(controlledCreature.getId()));
    delayedAbility.setSourceId(source.getSourceId());
    delayedAbility.setControllerId(source.getControllerId());
    delayedAbility.setSourceObject(source.getSourceObject(game),game);
    delayedAbility.init(game);
    game.addDelayedTriggeredAbility(delayedAbility);
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Permanent controlledCreature=game.getPermanent(source.getFirstTarget());
  if (controlledCreature != null) {
    DelayedTriggeredAbility delayedAbility=new MeriekeRiBeritDelayedTriggeredAbility();
    delayedAbility.getEffects().get(0).setTargetPointer(new FixedTarget(controlledCreature,game));
    game.addDelayedTriggeredAbility(delayedAbility,source);
    return true;
  }
  return false;
}
Program: 158236
Project: 158236
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event.getSourceId() != null) {
    if (GameEvent.EventType.ZONE_CHANGE.equals(event.getType()) && event.getTargetId().equals(getSourceId())) {
      ZoneChangeEvent zEvent=(ZoneChangeEvent)event;
      return zEvent.getFromZone().equals(Zone.BATTLEFIELD);
    }
  }
  return GameEvent.EventType.UNTAPPED.equals(event.getType()) && event.getTargetId() != null && event.getTargetId().equals(getSourceId());
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event.getTargetId() != null) {
    if (GameEvent.EventType.ZONE_CHANGE.equals(event.getType()) && event.getTargetId().equals(getSourceId())) {
      ZoneChangeEvent zEvent=(ZoneChangeEvent)event;
      return zEvent.getFromZone().equals(Zone.BATTLEFIELD);
    }
  }
  return GameEvent.EventType.UNTAPPED.equals(event.getType()) && event.getTargetId() != null && event.getTargetId().equals(getSourceId());
}
Program: 158237
Project: 158237
Buggy source:
/** 
 * Reflecting Pool does not count Crumbling Vestige as a source of all mana colors
 */
@Test public void testTriggeredManaAbility(){
  addCard(Zone.HAND,playerA,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  addCard(Zone.HAND,playerA,"String_Node_Str",1);
  playLand(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str",playerB);
  setStopAt(1,PhaseStep.BEGIN_COMBAT);
  execute();
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertGraveyardCount(playerA,"String_Node_Str",1);
  assertLife(playerA,20);
  assertLife(playerB,17);
}

Fixed version (ground truth):
/** 
 * Reflecting Pool does not count Crumbling Vestige as a source of all mana colors
 */
@Test public void testTriggeredManaAbility(){
  addCard(Zone.HAND,playerA,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  addCard(Zone.HAND,playerA,"String_Node_Str",1);
  playLand(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  setChoice(playerA,"String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str",playerB);
  setStopAt(1,PhaseStep.BEGIN_COMBAT);
  execute();
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertGraveyardCount(playerA,"String_Node_Str",1);
  assertLife(playerA,20);
  assertLife(playerB,17);
}
Program: 158238
Project: 158238
Buggy source:
public void applyEffects(Game game){
  game.resetShortLivingLKI();
  for (  Player player : players.values()) {
    player.reset();
  }
  battlefield.reset(game);
  combat.reset(game);
  this.reset();
  effects.apply(game);
  combat.checkForRemoveFromCombat(game);
}

Fixed version (ground truth):
public void applyEffects(Game game){
  for (  Player player : players.values()) {
    player.reset();
  }
  battlefield.reset(game);
  combat.reset(game);
  this.reset();
  effects.apply(game);
  combat.checkForRemoveFromCombat(game);
}
Program: 158239
Project: 158239
Buggy source:
public void processAction(Game game){
  game.getState().handleSimultaneousEvent(game);
  applyEffects(game);
}

Fixed version (ground truth):
public void processAction(Game game){
  game.getState().handleSimultaneousEvent(game);
  game.applyEffects();
}
Program: 158240
Project: 158240
Buggy source:
public void removeEocEffects(Game game){
  effects.removeEndOfCombatEffects();
  delayed.removeEndOfCombatAbilities();
  applyEffects(game);
}

Fixed version (ground truth):
public void removeEocEffects(Game game){
  effects.removeEndOfCombatEffects();
  delayed.removeEndOfCombatAbilities();
  game.applyEffects();
}
Program: 158241
Project: 158241
Buggy source:
public void removeEotEffects(Game game){
  effects.removeEndOfTurnEffects();
  delayed.removeEndOfTurnAbilities();
  applyEffects(game);
}

Fixed version (ground truth):
public void removeEotEffects(Game game){
  effects.removeEndOfTurnEffects();
  delayed.removeEndOfTurnAbilities();
  game.applyEffects();
}
Program: 158243
Project: 158243
Buggy source:
@Override public synchronized void applyEffects(){
  state.applyEffects(this);
}

Fixed version (ground truth):
@Override public synchronized void applyEffects(){
  resetShortLivingLKI();
  state.applyEffects(this);
}
Program: 158245
Project: 158245
Buggy source:
@Override public boolean apply(Permanent input,Game game){
  Player owner=game.getPlayer(input.getOwnerId());
  return input.getCardType().contains(CardType.CREATURE) && owner != null && input.getId().equals(owner.getCommandersIds());
}

Fixed version (ground truth):
@Override public boolean apply(Permanent input,Game game){
  Player owner=game.getPlayer(input.getOwnerId());
  return input.getCardType().contains(CardType.CREATURE) && owner != null && owner.getCommandersIds().contains(input.getId());
}
Program: 158246
Project: 158246
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player player=game.getPlayer(targetPointer.getFirst(game,source));
  if (player != null) {
    Token lightningRagerToken=new LightningRagerToken();
    lightningRagerToken.putOntoBattlefield(1,game,this.getId(),player.getId());
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player player=game.getPlayer(targetPointer.getFirst(game,source));
  if (player != null) {
    return new LightningRagerToken().putOntoBattlefield(1,game,source.getSourceId(),player.getId());
  }
  return false;
}
Program: 158247
Project: 158247
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    ArrayList<UUID> players=new ArrayList<>();
    ArrayList<UUID> creatures=new ArrayList<>();
    for (    UUID playerId : game.getState().getPlayersInRange(controller.getId(),game)) {
      Player player=game.getPlayer(playerId);
      if (player != null) {
        if (player.chooseUse(outcome,"String_Node_Str",source,game)) {
          Target target=new TargetControlledCreaturePermanent(new FilterControlledCreaturePermanent("String_Node_Str"));
          if (player.choose(outcome,target,playerId,game)) {
            creatures.add(target.getFirstTarget());
            players.add(player.getId());
          }
        }
      }
    }
    for (    UUID creatureId : creatures) {
      Permanent creature=game.getPermanent(creatureId);
      if (creature != null) {
        creature.addCounters(CounterType.P1P1.createInstance(2),game);
      }
    }
    for (    UUID playerId : players) {
      FilterCreaturePermanent filter=new FilterCreaturePermanent();
      filter.add(new PlayerIdPredicate(playerId));
      game.addEffect(new CantAttackYouAllEffect(Duration.UntilYourNextTurn,filter,true),source);
    }
    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) {
    ArrayList<UUID> players=new ArrayList<>();
    ArrayList<UUID> creatures=new ArrayList<>();
    for (    UUID playerId : game.getState().getPlayersInRange(controller.getId(),game)) {
      Player player=game.getPlayer(playerId);
      if (player != null) {
        if (player.chooseUse(outcome,"String_Node_Str",source,game)) {
          Target target=new TargetControlledCreaturePermanent(new FilterControlledCreaturePermanent("String_Node_Str"));
          if (player.choose(outcome,target,playerId,game)) {
            creatures.add(target.getFirstTarget());
            players.add(player.getId());
          }
        }
      }
    }
    for (    UUID creatureId : creatures) {
      Permanent creature=game.getPermanent(creatureId);
      if (creature != null) {
        creature.addCounters(CounterType.P1P1.createInstance(2),game);
      }
    }
    for (    UUID playerId : players) {
      FilterCreaturePermanent filter=new FilterCreaturePermanent();
      filter.add(new ControllerIdPredicate(playerId));
      game.addEffect(new CantAttackYouAllEffect(Duration.UntilYourNextTurn,filter,true),source);
    }
    return true;
  }
  return false;
}
Program: 158248
Project: 158248
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Player opponent=game.getPlayer(this.getTargetPointer().getFirst(game,source));
  if (controller != null && opponent != null) {
    Cards cards=new CardsImpl();
    int numLooked=Math.min(2,opponent.getLibrary().size());
    if (numLooked > 0) {
      for (int i=0; i < numLooked; i++) {
        cards.add(opponent.getLibrary().removeFromTop(game));
      }
      TargetCard target=new TargetCardInLibrary(new FilterCard("String_Node_Str"));
      controller.choose(Outcome.Exile,cards,target,game);
      Card card=cards.get(target.getFirstTarget(),game);
      cards.remove(card);
      opponent.moveCardToExileWithInfo(card,null,"String_Node_Str",source.getSourceId(),game,Zone.LIBRARY,true);
      if (cards.size() == 1) {
        card=cards.get(cards.iterator().next(),game);
        opponent.moveCardToLibraryWithInfo(card,source.getSourceId(),game,Zone.LIBRARY,true,false);
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Player opponent=game.getPlayer(this.getTargetPointer().getFirst(game,source));
  if (controller != null && opponent != null) {
    Cards cards=new CardsImpl();
    cards.addAll(opponent.getLibrary().getTopCards(game,2));
    if (cards.size() > 0) {
      TargetCard target=new TargetCardInLibrary(new FilterCard("String_Node_Str"));
      if (controller.choose(Outcome.Exile,cards,target,game)) {
        Card card=cards.get(target.getFirstTarget(),game);
        if (card != null) {
          cards.remove(card);
          opponent.moveCards(card,Zone.EXILED,source,game);
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158249
Project: 158249
Buggy source:
public void setExpansionSetCodeForImage(String code){
  if (availableImageSetCodes.size() > 0) {
    if (availableImageSetCodes.contains(code)) {
      setOriginalExpansionSetCode(code);
    }
 else     if (getOriginalExpansionSetCode() == null || getOriginalExpansionSetCode().isEmpty() || !availableImageSetCodes.contains(getOriginalExpansionSetCode())) {
      setOriginalExpansionSetCode(availableImageSetCodes.get(RandomUtil.nextInt(availableImageSetCodes.size())));
    }
  }
 else   if (getOriginalExpansionSetCode() == null || getOriginalExpansionSetCode().isEmpty()) {
    setOriginalExpansionSetCode(code);
  }
  setTokenDescriptor();
}

Fixed version (ground truth):
public void setExpansionSetCodeForImage(String code){
  if (availableImageSetCodes.size() > 0) {
    if (availableImageSetCodes.contains(code)) {
      setOriginalExpansionSetCode(code);
    }
 else {
      if (getOriginalExpansionSetCode() == null || getOriginalExpansionSetCode().isEmpty() || !availableImageSetCodes.contains(getOriginalExpansionSetCode())) {
        setOriginalExpansionSetCode(availableImageSetCodes.get(RandomUtil.nextInt(availableImageSetCodes.size())));
      }
    }
  }
 else   if (getOriginalExpansionSetCode() == null || getOriginalExpansionSetCode().isEmpty()) {
    setOriginalExpansionSetCode(code);
  }
  setTokenDescriptor();
}
Program: 158250
Project: 158250
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    UUID playerId=(UUID)game.getState().getValue(source.getSourceId() + "String_Node_Str");
    Player player=game.getPlayer(playerId);
    if (player != null && player.canRespond()) {
      player.damage((Integer)this.getValue("String_Node_Str"),source.getSourceId(),game,false,true);
    }
    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) {
    UUID playerId=(UUID)game.getState().getValue(source.getSourceId() + "String_Node_Str");
    Player player=game.getPlayer(playerId);
    if (player != null && player.canRespond()) {
      Integer damage=(Integer)this.getValue("String_Node_Str");
      if (damage > 0) {
        player.damage(damage,source.getSourceId(),game,false,true);
      }
    }
    return true;
  }
  return false;
}
Program: 158251
Project: 158251
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 && sourceObject != null) {
    Cards cards=new CardsImpl();
    cards.addAll(controller.getLibrary().getTopCards(game,4));
    boolean properCardFound=cards.count(filterPutInHand,source.getControllerId(),source.getSourceId(),game) > 0;
    if (!cards.isEmpty()) {
      controller.revealCards(sourceObject.getName(),cards,game);
      TargetCard target=new TargetCard(Zone.LIBRARY,filterPutInHand);
      if (properCardFound && controller.chooseUse(outcome,"String_Node_Str",source,game) && controller.choose(Outcome.DrawCard,cards,target,game)) {
        Card card=game.getCard(target.getFirstTarget());
        if (card != null) {
          cards.remove(card);
          controller.moveCards(card,Zone.HAND,source,game);
        }
      }
      controller.moveCards(cards,Zone.GRAVEYARD,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 && sourceObject != null) {
    Cards cards=new CardsImpl();
    cards.addAll(controller.getLibrary().getTopCards(game,4));
    boolean properCardFound=cards.count(filterPutInHand,source.getControllerId(),source.getSourceId(),game) > 0;
    if (!cards.isEmpty()) {
      controller.revealCards(sourceObject.getIdName(),cards,game);
      TargetCard target=new TargetCard(Zone.LIBRARY,filterPutInHand);
      if (properCardFound && controller.chooseUse(outcome,"String_Node_Str",source,game) && controller.choose(Outcome.DrawCard,cards,target,game)) {
        Card card=game.getCard(target.getFirstTarget());
        if (card != null) {
          cards.remove(card);
          controller.moveCards(card,Zone.HAND,source,game);
        }
      }
      controller.moveCards(cards,Zone.GRAVEYARD,source,game);
    }
    return true;
  }
  return false;
}
Program: 158252
Project: 158252
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (!onlyCombat || ((DamagedPlayerEvent)event).isCombatDamage()) {
    Permanent permanent=game.getPermanent(event.getSourceId());
    if (permanent != null) {
      if (filter.match(permanent,getSourceId(),getControllerId(),game)) {
        if (!setTargetPointer.equals(SetTargetPointer.NONE)) {
          for (          Effect effect : this.getEffects()) {
            effect.setValue("String_Node_Str",event.getAmount());
switch (setTargetPointer) {
case PLAYER:
              effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
            break;
case PERMANENT:
          effect.setTargetPointer(new FixedTarget(permanent.getId(),permanent.getZoneChangeCounter(game)));
        break;
    }
  }
}
return true;
}
}
}
return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (!onlyCombat || ((DamagedPlayerEvent)event).isCombatDamage()) {
    Permanent permanent=game.getPermanent(event.getSourceId());
    if (permanent != null) {
      if (filter.match(permanent,getSourceId(),getControllerId(),game)) {
        for (        Effect effect : this.getEffects()) {
          effect.setValue("String_Node_Str",event.getAmount());
switch (setTargetPointer) {
case PLAYER:
            effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
          break;
case PERMANENT:
        effect.setTargetPointer(new FixedTarget(permanent.getId(),permanent.getZoneChangeCounter(game)));
      break;
  }
}
return true;
}
}
}
return false;
}
Program: 158253
Project: 158253
Buggy source:
@Override public CardsDrawnThisTurnWatcher copy(){
  return new CardsDrawnThisTurnWatcher(this);
}

Fixed version (ground truth):
@Override public KydeleCardsDrawnThisTurnWatcher copy(){
  return new KydeleCardsDrawnThisTurnWatcher(this);
}
Program: 158254
Project: 158254
Buggy source:
@Override public int calculate(Game game,Ability sourceAbility,Effect effect){
  CardsDrawnThisTurnWatcher watcher=(CardsDrawnThisTurnWatcher)game.getState().getWatchers().get("String_Node_Str");
  return watcher.getNumCardsDrawnThisTurn(sourceAbility.getControllerId());
}

Fixed version (ground truth):
@Override public int calculate(Game game,Ability sourceAbility,Effect effect){
  KydeleCardsDrawnThisTurnWatcher watcher=(KydeleCardsDrawnThisTurnWatcher)game.getState().getWatchers().get(KydeleCardsDrawnThisTurnWatcher.class.getName());
  return watcher.getNumCardsDrawnThisTurn(sourceAbility.getControllerId());
}
Program: 158255
Project: 158255
Buggy source:
@Override public CardsDrawnThisTurnWatcher copy(){
  return new CardsDrawnThisTurnWatcher(this);
}

Fixed version (ground truth):
@Override public SylvanLibraryCardsDrawnThisTurnWatcher copy(){
  return new SylvanLibraryCardsDrawnThisTurnWatcher(this);
}
Program: 158256
Project: 158256
Buggy source:
/** 
 * Determines if permanent can damage in current (First Strike or not) combat damage step
 * @param perm Permanent to check
 * @param first First strike or common combat damage step
 * @return
 */
private boolean canDamage(Permanent perm,boolean first){
  if (first) {
    return hasFirstOrDoubleStrike(perm);
  }
 else {
    if (hasFirstStrike(perm)) {
      return hasDoubleStrike(perm);
    }
    return true;
  }
}

Fixed version (ground truth):
/** 
 * Determines if permanent can damage in current (First Strike or not) combat damage step
 * @param perm Permanent to check
 * @param first First strike or common combat damage step
 * @return
 */
private boolean canDamage(Permanent perm,boolean first){
  if (perm == null) {
    return false;
  }
  if (first) {
    return hasFirstOrDoubleStrike(perm);
  }
 else {
    if (hasFirstStrike(perm)) {
      return hasDoubleStrike(perm);
    }
    return true;
  }
}
Program: 158258
Project: 158258
Buggy source:
protected void playALand(Set<Card> lands,Game game){
  log.debug("String_Node_Str");
  for (  Mana mana : unplayable.keySet()) {
    for (    Card card : lands) {
      for (      ManaAbility ability : card.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
        for (        Mana netMana : ability.getNetMana(game)) {
          if (netMana.enough(mana)) {
            this.playLand(card,game,false);
            lands.remove(card);
            return;
          }
        }
      }
    }
  }
  for (  Mana mana : unplayable.keySet()) {
    for (    Card card : lands) {
      for (      ManaAbility ability : card.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
        for (        Mana netMana : ability.getNetMana(game)) {
          if (mana.contains(netMana)) {
            this.playLand(card,game,false);
            lands.remove(card);
            return;
          }
        }
      }
    }
  }
  this.playLand(lands.iterator().next(),game,false);
  lands.remove(lands.iterator().next());
}

Fixed version (ground truth):
protected void playALand(Set<Card> lands,Game game){
  log.debug("String_Node_Str");
  for (  Mana mana : unplayable.keySet()) {
    for (    Card card : lands) {
      for (      ActivatedManaAbilityImpl ability : card.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD)) {
        for (        Mana netMana : ability.getNetMana(game)) {
          if (netMana.enough(mana)) {
            this.playLand(card,game,false);
            lands.remove(card);
            return;
          }
        }
      }
    }
  }
  for (  Mana mana : unplayable.keySet()) {
    for (    Card card : lands) {
      for (      ActivatedManaAbilityImpl ability : card.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD)) {
        for (        Mana netMana : ability.getNetMana(game)) {
          if (mana.contains(netMana)) {
            this.playLand(card,game,false);
            lands.remove(card);
            return;
          }
        }
      }
    }
  }
  this.playLand(lands.iterator().next(),game,false);
  lands.remove(lands.iterator().next());
}
Program: 158261
Project: 158261
Buggy source:
public int evaluate(Permanent permanent,Game game){
  if (!values.containsKey(permanent.getId())) {
    int value=0;
    if (permanent.getCardType().contains(CardType.CREATURE)) {
      value+=combat.evaluate(permanent,game);
    }
    value+=permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD).size();
    value+=permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD).size();
    values.put(permanent.getId(),value);
  }
  return values.get(permanent.getId());
}

Fixed version (ground truth):
public int evaluate(Permanent permanent,Game game){
  if (!values.containsKey(permanent.getId())) {
    int value=0;
    if (permanent.getCardType().contains(CardType.CREATURE)) {
      value+=combat.evaluate(permanent,game);
    }
    value+=permanent.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD).size();
    value+=permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD).size();
    values.put(permanent.getId(),value);
  }
  return values.get(permanent.getId());
}
Program: 158262
Project: 158262
Buggy source:
public static int evaluatePermanent(Permanent permanent,Game game,boolean ignoreTapped){
  int value=0;
  if (ignoreTapped)   value=5;
 else   value=permanent.isTapped() ? 4 : 5;
  if (permanent.getCardType().contains(CardType.CREATURE)) {
    value+=evaluateCreature(permanent,game) * CREATURE_FACTOR;
  }
  value+=permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD).size();
  for (  ActivatedAbility ability : permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
    if (!(ability instanceof ManaAbility) && ability.canActivate(ability.getControllerId(),game))     value+=ability.getEffects().size();
  }
  for (  Counter counter : permanent.getCounters(game).values()) {
    if (!(counter instanceof BoostCounter)) {
      value+=counter.getCount();
    }
  }
  value+=permanent.getAbilities().getStaticAbilities(Zone.BATTLEFIELD).size();
  value+=permanent.getAbilities().getTriggeredAbilities(Zone.BATTLEFIELD).size();
  value+=permanent.getManaCost().convertedManaCost();
  return value;
}

Fixed version (ground truth):
public static int evaluatePermanent(Permanent permanent,Game game,boolean ignoreTapped){
  int value=0;
  if (ignoreTapped)   value=5;
 else   value=permanent.isTapped() ? 4 : 5;
  if (permanent.getCardType().contains(CardType.CREATURE)) {
    value+=evaluateCreature(permanent,game) * CREATURE_FACTOR;
  }
  value+=permanent.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD).size();
  for (  ActivatedAbility ability : permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
    if (!(ability instanceof ActivatedManaAbilityImpl) && ability.canActivate(ability.getControllerId(),game))     value+=ability.getEffects().size();
  }
  for (  Counter counter : permanent.getCounters(game).values()) {
    if (!(counter instanceof BoostCounter)) {
      value+=counter.getCount();
    }
  }
  value+=permanent.getAbilities().getStaticAbilities(Zone.BATTLEFIELD).size();
  value+=permanent.getAbilities().getTriggeredAbilities(Zone.BATTLEFIELD).size();
  value+=permanent.getManaCost().convertedManaCost();
  return value;
}
Program: 158263
Project: 158263
Buggy source:
protected void playManaAbilities(ManaCost unpaid,Game game){
  updateGameStatePriority("String_Node_Str",game);
  MageObject object=game.getObject(response.getUUID());
  if (object == null) {
    return;
  }
  Zone zone=game.getState().getZone(object.getId());
  if (zone != null) {
    LinkedHashMap<UUID,ManaAbility> useableAbilities=getUseableManaAbilities(object,zone,game);
    if (useableAbilities != null && useableAbilities.size() > 0) {
      useableAbilities=ManaUtil.tryToAutoPay(unpaid,useableAbilities);
      currentlyUnpaidMana=unpaid;
      activateAbility(useableAbilities,object,game);
      currentlyUnpaidMana=null;
    }
  }
}

Fixed version (ground truth):
protected void playManaAbilities(ManaCost unpaid,Game game){
  updateGameStatePriority("String_Node_Str",game);
  MageObject object=game.getObject(response.getUUID());
  if (object == null) {
    return;
  }
  Zone zone=game.getState().getZone(object.getId());
  if (zone != null) {
    LinkedHashMap<UUID,ActivatedManaAbilityImpl> useableAbilities=getUseableManaAbilities(object,zone,game);
    if (useableAbilities != null && useableAbilities.size() > 0) {
      useableAbilities=ManaUtil.tryToAutoPay(unpaid,useableAbilities);
      currentlyUnpaidMana=unpaid;
      activateAbility(useableAbilities,object,game);
      currentlyUnpaidMana=null;
    }
  }
}
Program: 158264
Project: 158264
Buggy source:
private boolean suppressAbilityPicker(ActivatedAbility ability){
  if (this.getUserData().isShowAbilityPickerForced()) {
    if (ability instanceof PlayLandAbility) {
      return true;
    }
    if (!ability.getSourceId().equals(getCastSourceIdWithAlternateMana()) && ability.getManaCostsToPay().convertedManaCost() > 0) {
      return true;
    }
    return ability instanceof ManaAbility;
  }
  return true;
}

Fixed version (ground truth):
private boolean suppressAbilityPicker(ActivatedAbility ability){
  if (this.getUserData().isShowAbilityPickerForced()) {
    if (ability instanceof PlayLandAbility) {
      return true;
    }
    if (!ability.getSourceId().equals(getCastSourceIdWithAlternateMana()) && ability.getManaCostsToPay().convertedManaCost() > 0) {
      return true;
    }
    return ability instanceof ActivatedManaAbilityImpl;
  }
  return true;
}
Program: 158265
Project: 158265
Buggy source:
protected void activateAbility(LinkedHashMap<UUID,? extends ActivatedAbility> abilities,MageObject object,Game game){
  updateGameStatePriority("String_Node_Str",game);
  if (abilities.size() == 1 && suppressAbilityPicker(abilities.values().iterator().next())) {
    ActivatedAbility ability=abilities.values().iterator().next();
    if (!ability.getTargets().isEmpty() || !(ability.getCosts().size() == 1 && ability.getCosts().get(0) instanceof SacrificeSourceCost) || !(ability.getCosts().size() == 2 && ability.getCosts().get(0) instanceof TapSourceCost && ability.getCosts().get(0) instanceof SacrificeSourceCost)) {
      activateAbility(ability,game);
      return;
    }
  }
  if (userData.isUseFirstManaAbility() && object instanceof Permanent && object.getCardType().contains(CardType.LAND)) {
    ActivatedAbility ability=abilities.values().iterator().next();
    if (ability instanceof ManaAbility) {
      activateAbility(ability,game);
      return;
    }
  }
  game.fireGetChoiceEvent(playerId,name,object,new ArrayList<>(abilities.values()));
  waitForResponse(game);
  if (response.getUUID() != null && isInGame()) {
    if (abilities.containsKey(response.getUUID())) {
      activateAbility(abilities.get(response.getUUID()),game);
    }
  }
}

Fixed version (ground truth):
protected void activateAbility(LinkedHashMap<UUID,? extends ActivatedAbility> abilities,MageObject object,Game game){
  updateGameStatePriority("String_Node_Str",game);
  if (abilities.size() == 1 && suppressAbilityPicker(abilities.values().iterator().next())) {
    ActivatedAbility ability=abilities.values().iterator().next();
    if (!ability.getTargets().isEmpty() || !(ability.getCosts().size() == 1 && ability.getCosts().get(0) instanceof SacrificeSourceCost) || !(ability.getCosts().size() == 2 && ability.getCosts().get(0) instanceof TapSourceCost && ability.getCosts().get(0) instanceof SacrificeSourceCost)) {
      activateAbility(ability,game);
      return;
    }
  }
  if (userData.isUseFirstManaAbility() && object instanceof Permanent && object.getCardType().contains(CardType.LAND)) {
    ActivatedAbility ability=abilities.values().iterator().next();
    if (ability instanceof ActivatedManaAbilityImpl) {
      activateAbility(ability,game);
      return;
    }
  }
  game.fireGetChoiceEvent(playerId,name,object,new ArrayList<>(abilities.values()));
  waitForResponse(game);
  if (response.getUUID() != null && isInGame()) {
    if (abilities.containsKey(response.getUUID())) {
      activateAbility(abilities.get(response.getUUID()),game);
    }
  }
}
Program: 158266
Project: 158266
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getPlayerId().equals(source.getFirstTarget())) {
    MageObject object=game.getObject(event.getSourceId());
    if (event.getType() == GameEvent.EventType.CAST_SPELL) {
      if (object.getCardType().contains(CardType.INSTANT) || object.getCardType().contains(CardType.SORCERY)) {
        return true;
      }
    }
    if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
      Ability ability=game.getAbility(event.getTargetId(),event.getSourceId());
      if (ability != null && !(ability instanceof ManaAbility)) {
        return true;
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getPlayerId().equals(source.getFirstTarget())) {
    MageObject object=game.getObject(event.getSourceId());
    if (event.getType() == GameEvent.EventType.CAST_SPELL) {
      if (object.getCardType().contains(CardType.INSTANT) || object.getCardType().contains(CardType.SORCERY)) {
        return true;
      }
    }
    if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
      Ability ability=game.getAbility(event.getTargetId(),event.getSourceId());
      if (ability != null && !(ability instanceof ActivatedManaAbilityImpl)) {
        return true;
      }
    }
  }
  return false;
}
Program: 158267
Project: 158267
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  Player targetingPlayer=game.getPlayer(event.getPlayerId());
  if (controller != null && targetingPlayer.isHuman() && controller.hasOpponent(event.getPlayerId(),game)) {
    StackObject stackObject=game.getStack().getStackObject(event.getSourceId());
    if (stackObject.isCopy()) {
      return false;
    }
    Ability ability=(Ability)getValue("String_Node_Str");
    if (ability != null) {
      List<Permanent> allowedPermanents=game.getBattlefield().getActivePermanents(filter,event.getPlayerId(),event.getSourceId(),game);
      if (!allowedPermanents.isEmpty()) {
        boolean canTargetAllowedPermanent=false;
        for (        UUID modeId : ability.getModes().getSelectedModes()) {
          ability.getModes().setActiveMode(modeId);
          for (          Target target : ability.getTargets()) {
            for (            Permanent allowedPermanent : allowedPermanents) {
              if (target.getTargets().contains(allowedPermanent.getId())) {
                return false;
              }
              if (target.canTarget(allowedPermanent.getId(),source,game)) {
                canTargetAllowedPermanent=true;
              }
            }
          }
        }
        return canTargetAllowedPermanent;
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  Player targetingPlayer=game.getPlayer(event.getPlayerId());
  if (controller != null && targetingPlayer.isHuman() && controller.hasOpponent(event.getPlayerId(),game)) {
    StackObject stackObject=game.getStack().getStackObject(event.getSourceId());
    if (stackObject.isCopy()) {
      return false;
    }
    Ability ability=(Ability)getValue("String_Node_Str");
    if (ability != null) {
      List<Permanent> allowedPermanents=game.getBattlefield().getActivePermanents(filter,event.getPlayerId(),event.getSourceId(),game);
      if (!allowedPermanents.isEmpty()) {
        boolean canTargetAllowedPermanent=false;
        for (        UUID modeId : ability.getModes().getSelectedModes()) {
          ability.getModes().setActiveMode(modeId);
          for (          Target target : ability.getTargets()) {
            for (            Permanent allowedPermanent : allowedPermanents) {
              if (target.getTargets().contains(allowedPermanent.getId())) {
                return false;
              }
              if (target.canTarget(stackObject.getControllerId(),allowedPermanent.getId(),source,game)) {
                canTargetAllowedPermanent=true;
              }
            }
          }
        }
        return canTargetAllowedPermanent;
      }
    }
  }
  return false;
}
Program: 158268
Project: 158268
Buggy source:
@Override public String getText(Mode mode){
  StringBuilder sb=new StringBuilder();
  if (!"String_Node_Str".equals(duration.toString())) {
    sb.append(duration.toString()).append("String_Node_Str");
  }
  sb.append(filter.getMessage());
  sb.append("String_Node_Str").append(token.getDescription());
  if (type != null && type.length() > 0) {
    sb.append("String_Node_Str").append(type);
  }
  return sb.toString();
}

Fixed version (ground truth):
@Override public String getText(Mode mode){
  StringBuilder sb=new StringBuilder();
  if (!"String_Node_Str".equals(duration.toString())) {
    sb.append(duration.toString()).append("String_Node_Str");
  }
  sb.append("String_Node_Str");
  sb.append(filter.getMessage());
  if ("String_Node_Str".equals(duration.toString())) {
    sb.append("String_Node_Str");
  }
 else {
    sb.append("String_Node_Str");
  }
  sb.append(token.getDescription());
  if (type != null && type.length() > 0) {
    sb.append("String_Node_Str").append(type);
  }
  return sb.toString();
}
Program: 158269
Project: 158269
Buggy source:
protected List<MageObject> getAvailableManaProducers(Game game){
  List<MageObject> result=new ArrayList<>();
  for (  Permanent permanent : game.getBattlefield().getAllActivePermanents(playerId)) {
    boolean canAdd=false;
    for (    ManaAbility ability : permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
      if (!ability.getManaCosts().isEmpty()) {
        canAdd=false;
        break;
      }
      if (ability.canActivate(playerId,game)) {
        canAdd=true;
      }
    }
    if (canAdd) {
      result.add(permanent);
    }
  }
  for (  Card card : getHand().getCards(game)) {
    boolean canAdd=false;
    for (    ManaAbility ability : card.getAbilities(game).getManaAbilities(Zone.HAND)) {
      if (!ability.getManaCosts().isEmpty()) {
        canAdd=false;
        break;
      }
      if (ability.canActivate(playerId,game)) {
        canAdd=true;
      }
    }
    if (canAdd) {
      result.add(card);
    }
  }
  return result;
}

Fixed version (ground truth):
protected List<MageObject> getAvailableManaProducers(Game game){
  List<MageObject> result=new ArrayList<>();
  for (  Permanent permanent : game.getBattlefield().getAllActivePermanents(playerId)) {
    Boolean canUse=null;
    boolean canAdd=false;
    for (    ManaAbility ability : permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
      if (!ability.getManaCosts().isEmpty()) {
        canAdd=false;
        break;
      }
      if (canUse == null) {
        canUse=permanent.canUseActivatedAbilities(game);
      }
      if (canUse && ability.canActivate(playerId,game)) {
        canAdd=true;
      }
    }
    if (canAdd) {
      result.add(permanent);
    }
  }
  for (  Card card : getHand().getCards(game)) {
    boolean canAdd=false;
    for (    ManaAbility ability : card.getAbilities(game).getManaAbilities(Zone.HAND)) {
      if (!ability.getManaCosts().isEmpty()) {
        canAdd=false;
        break;
      }
      if (ability.canActivate(playerId,game)) {
        canAdd=true;
      }
    }
    if (canAdd) {
      result.add(card);
    }
  }
  return result;
}
Program: 158270
Project: 158270
Buggy source:
public List<Permanent> getAvailableManaProducersWithCost(Game game){
  List<Permanent> result=new ArrayList<>();
  for (  Permanent permanent : game.getBattlefield().getAllActivePermanents(playerId)) {
    for (    ManaAbility ability : permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
      if (ability.canActivate(playerId,game) && !ability.getManaCosts().isEmpty()) {
        result.add(permanent);
        break;
      }
    }
  }
  return result;
}

Fixed version (ground truth):
public List<Permanent> getAvailableManaProducersWithCost(Game game){
  List<Permanent> result=new ArrayList<>();
  for (  Permanent permanent : game.getBattlefield().getAllActivePermanents(playerId)) {
    Boolean canUse=null;
    for (    ManaAbility ability : permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
      if (canUse == null) {
        canUse=permanent.canUseActivatedAbilities(game);
      }
      if (canUse && ability.canActivate(playerId,game) && !ability.getManaCosts().isEmpty()) {
        result.add(permanent);
        break;
      }
    }
  }
  return result;
}