protected int combatPotential(Permanent creature, Game game) { log.debug("combatPotential"); if (!creature.canAttack(null, game)) { return 0; } int potential = creature.getPower().getValue(); potential += creature.getAbilities().getEvasionAbilities().size(); potential += creature.getAbilities().getProtectionAbilities().size(); potential += creature.getAbilities().containsKey(FirstStrikeAbility.getInstance().getId()) ? 1 : 0; potential += creature.getAbilities().containsKey(DoubleStrikeAbility.getInstance().getId()) ? 2 : 0; potential += creature.getAbilities().containsKey(TrampleAbility.getInstance().getId()) ? 1 : 0; return potential; }
@Override public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) { return attacker.getAbilities().contains(SpaceflightAbility.getInstance()); }
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()); }
@Override public boolean apply(MageObject input, Game game) { Abilities<Ability> abilities = input.getAbilities(); for (int i = 0; i < abilities.size(); i++) { if (abilities.get(i) instanceof EmbalmAbility) { return true; } if (abilities.get(i) instanceof EternalizeAbility) { return true; } } return false; }
private Abilities<ActivatedManaAbilityImpl> getManaAbilitiesSortedByManaCount(MageObject mageObject, final Game game) { Abilities<ActivatedManaAbilityImpl> manaAbilities = mageObject.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, game); if (manaAbilities.size() > 1) { // Sort mana abilities by number of produced manas, to use ability first that produces most mana (maybe also conditional if possible) Collections.sort(manaAbilities, new Comparator<ActivatedManaAbilityImpl>() { @Override public int compare(ActivatedManaAbilityImpl a1, ActivatedManaAbilityImpl a2) { int a1Max = 0; for (Mana netMana : a1.getNetMana(game)) { if (netMana.count() > a1Max) { a1Max = netMana.count(); } } int a2Max = 0; for (Mana netMana : a2.getNetMana(game)) { if (netMana.count() > a2Max) { a2Max = netMana.count(); } } return a2Max - a1Max; } }); } return manaAbilities; }
@Override public boolean hasAbility(UUID abilityId, Game game) { return abilites.containsKey(abilityId); }
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).canActivate()) { 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(); //TODO: add a difficulty to calculation to ManaCost - sort permanents by difficulty for casting when evaluating game states return value; }
for (ManaCost cost : unpaid) { Abilities: for (ActivatedManaAbilityImpl ability : mageObject.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, game)) { for (Mana netMana : ability.getNetMana(game)) { if (cost.testPay(netMana)) { score += mageObject.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, game).size(); score += mageObject.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD).size(); if (!mageObject.getCardType().contains(CardType.LAND)) { score += 2;
@Override public boolean apply(MageObject input, Game game) { Abilities<Ability> abilities; if (input instanceof Card){ abilities = ((Card)input).getAbilities(game); } else { abilities = input.getAbilities(); } return abilities.stream().anyMatch(ability -> ability.getClass().equals(abilityClass)); }
@Override public List<Mana> getMana() { List<Mana> mana = new ArrayList<>(); for (ActivatedManaAbilityImpl ability : this.abilities.getActivatedManaAbilities(Zone.BATTLEFIELD)) { mana.addAll(ability.getNetMana(null)); } return mana; }
@Override public SpellAbility getSpellAbility() { if (spellAbility == null) { for (Ability ability : abilities.getActivatedAbilities(Zone.HAND)) { if (ability instanceof SpellAbility && ((SpellAbility) ability).getSpellAbilityType() != SpellAbilityType.BASE_ALTERNATE) { return spellAbility = (SpellAbility) ability; } } } return spellAbility; }
@Override public boolean hasProtectionFrom(MageObject source, Game game) { for (ProtectionAbility ability : abilities.getProtectionAbilities()) { if (!ability.canTarget(source, game)) { return true; } } return false; }
perm.getAbilities().removeIf(entry -> entry.getId().equals(ability.getId())); for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { System.out.println(game.getTurn() + ", " + game.getPhase() + ": " + "remove from size " + perm.getAbilities().size()); for (Ability ability : ability) { perm.getAbilities().removeIf(entry -> entry.getId().equals(ability.getId())); if (filter.match(perm, source.getSourceId(), source.getControllerId(), game)) { for (Ability ability : ability) { perm.getAbilities().removeIf(entry -> entry.getId().equals(ability.getId()));
Mana mana = new Mana(); for (ActivatedManaAbilityImpl ability : permanent.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD)) { for (Mana netMana : ability.getNetMana(game)) { mana.add(netMana); Mana opponentLandMana = new Mana(); for (ActivatedManaAbilityImpl ability : opponentPermanent.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, game)) { for (Mana netMana : ability.getNetMana(game)) { opponentLandMana.add(netMana);
@Override public boolean containsAll(Abilities<T> abilities) { if (this.size() < abilities.size()) { return false; } for (T ability : abilities) { if (!contains(ability)) { return false; } } return true; }
boolean canAdd = false; boolean withCost = false; Abilities<ActivatedManaAbilityImpl> manaAbilities = permanent.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, game); for (ActivatedManaAbilityImpl ability : manaAbilities) { if (canUse == null) {
public List<Permanent> getPhasedIn(UUID controllerId) { return field.values() .stream() .filter(perm -> perm.getAbilities().containsKey(PhasingAbility.getInstance().getId()) && perm.isPhasedIn() && perm.isControlledBy(controllerId)) .collect(Collectors.toList()); }
@Override public boolean apply(Game game, Ability source) { Card card = game.getCard(source.getSourceId()); if (card != null) { return card.getAbilities().stream() .filter(a -> a instanceof BuybackAbility) .anyMatch(Ability::isActivated); } return false; } }