refactor CardList to use Predicates and have less methods (to replace it later with pure List<Card>) and perform any special actions (filtering, cmc calculation, max creture power, etc) with predicates

This commit is contained in:
Maxmtg
2012-09-23 10:16:24 +00:00
parent 7786ef990d
commit cc0351db74
37 changed files with 670 additions and 1008 deletions

View File

@@ -20,6 +20,7 @@ package forge;
import java.util.ArrayList;
import java.util.List;
import forge.CardPredicates.Presets;
import forge.game.player.Player;
import forge.game.zone.ZoneType;
import forge.util.closures.Predicate;
@@ -86,7 +87,7 @@ public abstract class AllZoneUtil {
* @return a CardList with all cards currently in a graveyard
*/
public static CardList getCardsIn(final ZoneType zone, final String cardName) {
return AllZoneUtil.getCardsIn(zone).getName(cardName);
return AllZoneUtil.getCardsIn(zone).filter(CardPredicates.nameEquals(cardName));
}
// ////////// Creatures
@@ -99,7 +100,7 @@ public abstract class AllZoneUtil {
*/
public static CardList getCreaturesInPlay() {
final CardList creats = AllZoneUtil.getCardsIn(ZoneType.Battlefield);
return creats.filter(CardPredicates.CREATURES);
return creats.filter(Presets.CREATURES);
}
/**
@@ -111,7 +112,7 @@ public abstract class AllZoneUtil {
*/
public static CardList getCreaturesInPlay(final Player player) {
final CardList creats = player.getCardsIn(ZoneType.Battlefield);
return creats.filter(CardPredicates.CREATURES);
return creats.filter(Presets.CREATURES);
}
// /////////////// Lands
@@ -124,7 +125,7 @@ public abstract class AllZoneUtil {
* @return a CardList containing all lands the given player has in play
*/
public static CardList getPlayerLandsInPlay(final Player player) {
return player.getCardsIn(ZoneType.Battlefield).filter(CardPredicates.LANDS);
return player.getCardsIn(ZoneType.Battlefield).filter(Presets.LANDS);
}
/**
@@ -133,7 +134,7 @@ public abstract class AllZoneUtil {
* @return a CardList of all lands on the battlefield
*/
public static CardList getLandsInPlay() {
return AllZoneUtil.getCardsIn(ZoneType.Battlefield).filter(CardPredicates.LANDS);
return AllZoneUtil.getCardsIn(ZoneType.Battlefield).filter(Presets.LANDS);
}
// =============================================================================

View File

@@ -57,6 +57,7 @@ import forge.game.player.Player;
import forge.game.zone.ZoneType;
import forge.item.CardDb;
import forge.util.MyRandom;
import forge.util.closures.PredicateString;
/**
* <p>
@@ -6228,25 +6229,6 @@ public class Card extends GameEntity implements Comparable<Card> {
return -1;
}
/**
* <p>
* keywordsContain.
* </p>
*
* @param keyword
* a {@link java.lang.String} object.
* @return a boolean.
*/
public final boolean keywordsContain(final String keyword) {
final ArrayList<String> a = this.getKeyword();
for (int i = 0; i < a.size(); i++) {
if (a.get(i).toString().contains(keyword)) {
return true;
}
}
return false;
}
/**
* <p>
* hasAnyKeyword.
@@ -6658,13 +6640,13 @@ public class Card extends GameEntity implements Comparable<Card> {
}
} else if (property.startsWith("Above")) { // "Are Above" Source
final CardList list = this.getOwner().getCardsIn(ZoneType.Graveyard);
if (!list.getAbove(source, this)) {
if (list.indexOf(source) >= list.indexOf(this)) {
return false;
}
} else if (property.startsWith("DirectlyAbove")) { // "Are Directly Above"
// Source
final CardList list = this.getOwner().getCardsIn(ZoneType.Graveyard);
if (!list.getDirectlyAbove(source, this)) {
if (list.indexOf(this) - list.indexOf(source) != 1) {
return false;
}
} else if (property.startsWith("TopGraveyardCreature")) {

View File

@@ -121,90 +121,6 @@ public class CardList implements Iterable<Card> {
this.list = new ArrayList<Card>(size);
}
/**
* <p>
* getColor.
* </p>
*
* @param cardColor
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getColor(final String cardColor) {
final CardList list = new CardList();
for (final Card c : this) {
if (cardColor.equals("Multicolor") && (c.getColor().size() > 1)) {
list.add(c);
} else if (c.isColor(cardColor) && (c.getColor().size() == 1)) {
list.add(c);
}
}
return list;
} // getColor()
/**
* Get cards that match the given color string. Use the card's ManaCost
* to determine color.
* @param cardColor desired color
* @return CardList
*/
public final CardList getColorByManaCost(final String cardColor) {
final CardList ret = new CardList();
for (final Card c : this) {
ArrayList<String> colors = CardUtil.getOnlyColors(c);
if (colors.contains(cardColor)) {
ret.add(c);
}
}
return ret;
} // getColorByManaCost()
/**
* <p>
* getOnly2Colors.
* </p>
*
* @param clr1
* a {@link java.lang.String} object.
* @param clr2
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getOnly2Colors(final String clr1, final String clr2) {
final CardList list = new CardList();
list.addAll(this);
final Predicate<Card> clrF = new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
if (c.isColorless()) {
return true;
}
final ArrayList<CardColor> cClrs = c.getColor();
for (int i = 0; i < cClrs.size(); i++) {
CardColor cc = cClrs.get(i);
for (final String s : cc.toStringArray()) {
if (!s.equals(clr1) && !s.equals(clr2)) {
return false;
}
}
}
return true;
}
};
return list.filter(clrF);
}
/**
* <p>
* reverse.
* </p>
*/
public final void reverse() {
Collections.reverse(this.list);
}
/** {@inheritDoc} */
@Override
public final boolean equals(final Object a) {
@@ -236,43 +152,6 @@ public class CardList implements Iterable<Card> {
return (41 * (41 + this.list.size() + this.list.hashCode()));
}
// removes one copy of that card
/**
* <p>
* remove.
* </p>
*
* @param cardName
* a {@link java.lang.String} object.
*/
public final void remove(final String cardName) {
final CardList find = this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.getName().equals(cardName);
}
});
if (0 < find.size()) {
this.remove(find.get(0));
} else {
throw new RuntimeException("CardList : remove(String cardname), error - card name not found: " + cardName
+ " - contents of Arraylist:" + this.list);
}
} // remove(String cardName)
/**
* <p>
* size.
* </p>
*
* @return a int.
*/
public final int size() {
return this.list.size();
}
/**
* <p>
* add.
@@ -325,374 +204,6 @@ public class CardList implements Iterable<Card> {
}
}
/**
* <p>
* contains.
* </p>
*
* @param c
* a {@link forge.Card} object.
* @return a boolean.
*/
public final boolean contains(final Card c) {
return this.list.contains(c);
}
// probably remove getCard() in the future
/**
* <p>
* getCard.
* </p>
*
* @param index
* a int.
* @return a {@link forge.Card} object.
*/
public final Card getCard(final int index) {
return this.list.get(index);
}
/**
* <p>
* get.
* </p>
*
* @param i
* a int.
* @return a {@link forge.Card} object.
*/
public final Card get(final int i) {
return this.getCard(i);
}
/**
* <p>
* containsName.
* </p>
*
* @param c
* a {@link forge.Card} object.
* @return a boolean.
*/
public final boolean containsName(final Card c) {
return this.containsName(c.getName());
}
/**
* <p>
* containsName.
* </p>
*
* @param name
* a {@link java.lang.String} object.
* @return a boolean.
*/
public final boolean containsName(final String name) {
for (int i = 0; i < this.size(); i++) {
if (this.getCard(i).getName().equals(name)) {
return true;
}
}
return false;
}
// returns new subset of all the cards with the same name
/**
* <p>
* getName.
* </p>
*
* @param name
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getName(final String name) {
final CardList c = new CardList();
for (int i = 0; i < this.size(); i++) {
if (this.getCard(i).getName().equals(name)) {
c.add(this.getCard(i));
}
}
return c;
}
// returns new subset of all the cards that have a different name
/**
* <p>
* getNotName.
* </p>
*
* @param name
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getNotName(final String name) {
final CardList c = new CardList();
for (int i = 0; i < this.size(); i++) {
if (!this.getCard(i).getName().equals(name)) {
c.add(this.getCard(i));
}
}
return c;
}
/**
* <p>
* getImageName.
* </p>
*
* @param name
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getImageName(final String name) {
final CardList c = new CardList();
for (int i = 0; i < this.size(); i++) {
if (this.getCard(i).getImageName().equals(name)) {
c.add(this.getCard(i));
}
}
return c;
}
/**
* <p>
* getController.
* </p>
*
* @param player
* a {@link forge.game.player.Player} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getController(final Player player) {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.getController().isPlayer(player);
}
});
}
/**
* <p>
* getOwner.
* </p>
*
* @param player
* a {@link forge.game.player.Player} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getOwner(final Player player) {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.getOwner().isPlayer(player);
}
});
}
// cardType is like "Land" or "Goblin", returns a new CardList that is a
// subset of current CardList
/**
* <p>
* getType.
* </p>
*
* @param cardType
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getType(final String cardType) {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.isType(cardType);
}
});
}
// cardType is like "Land" or "Goblin", returns a new CardList with cards
// that do not have this type
/**
* <p>
* getNotType.
* </p>
*
* @param cardType
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getNotType(final String cardType) {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return !c.isType(cardType);
}
});
}
/**
* <p>
* getPermanents.
* </p>
*
* @return a {@link forge.CardList} object.
*/
public final CardList getPermanents() {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.isPermanent();
}
});
}
/**
* <p>
* getKeyword.
* </p>
*
* @param keyword
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getKeyword(final String keyword) {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.hasKeyword(keyword);
}
});
}
/**
* <p>
* getNotKeyword.
* </p>
*
* @param keyword
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getNotKeyword(final String keyword) {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return !c.hasKeyword(keyword);
}
});
}
// get all cards that have this string in their keywords
/**
* <p>
* getKeywordsContain.
* </p>
*
* @param keyword
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getKeywordsContain(final String keyword) {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.keywordsContain(keyword);
}
});
}
// get all cards that don't have this string in their keywords
/**
* <p>
* getKeywordsDontContain.
* </p>
*
* @param keyword
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getKeywordsDontContain(final String keyword) {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return !c.keywordsContain(keyword);
}
});
}
/**
* <p>
* getTokens.
* </p>
*
* @return a {@link forge.CardList} object.
*/
public final CardList getTokens() {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.isToken();
}
});
}
/**
* Create a new list of cards by applying a filter to this one.
*
* @param filt
* determines which cards are present in the resulting list
*
* @return a subset of this CardList whose items meet the filtering
* criteria; may be empty, but never null.
*/
public final CardList filter(final Predicate<Card> filt) {
final CardList result = new CardList();
for (final Card card : this) {
if (filt.isTrue(card)) {
result.add(card);
}
}
return result;
}
/**
* <p>
* toArray.
* </p>
*
* @return an array of {@link forge.Card} objects.
*/
public final Card[] toArray() {
final Card[] c = new Card[this.list.size()];
this.list.toArray(c);
return c;
}
/** {@inheritDoc} */
@Override
public final String toString() {
return this.list.toString();
}
/**
* <p>
* isEmpty.
* </p>
*
* @return a boolean.
*/
public final boolean isEmpty() {
return this.list.isEmpty();
}
/**
* <p>
* remove.
@@ -746,6 +257,45 @@ public class CardList implements Iterable<Card> {
}
}
/**
* <p>
* isEmpty.
* </p>
*
* @return a boolean.
*/
public final boolean isEmpty() {
return this.list.isEmpty();
}
/**
* <p>
* size.
* </p>
*
* @return a int.
*/
public final int size() {
return this.list.size();
}
public final int indexOf(Card obj) {
return list.indexOf(obj);
}
/**
* <p>
* get.
* </p>
*
* @param i
* a int.
* @return a {@link forge.Card} object.
*/
public final Card get(final int i) {
return this.list.get(i);
}
/**
* <p>
* clear.
@@ -768,6 +318,28 @@ public class CardList implements Iterable<Card> {
Collections.shuffle(this.list, MyRandom.getRandom());
}
/**
* <p>
* reverse.
* </p>
*/
public final void reverse() {
Collections.reverse(this.list);
}
/**
* <p>
* toArray.
* </p>
*
* @return an array of {@link forge.Card} objects.
*/
public final Card[] toArray() {
final Card[] c = new Card[this.list.size()];
this.list.toArray(c);
return c;
}
/**
* <p>
* sort.
@@ -780,22 +352,84 @@ public class CardList implements Iterable<Card> {
Collections.sort(this.list, c);
}
/** {@inheritDoc} */
@Override
public final String toString() {
return this.list.toString();
}
/**
* Create a new list of cards by applying a filter to this one.
*
* @param filt
* determines which cards are present in the resulting list
*
* @return a subset of this CardList whose items meet the filtering
* criteria; may be empty, but never null.
*/
public final CardList filter(final Predicate<Card> filt) {
return new CardList(filt.select(this));
}
/**
* <p>
* getTargetableCards.
* getColor.
* </p>
*
* @param source
* a {@link forge.Card} object.
* @param cardColor
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getTargetableCards(final SpellAbility source) {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return source.canTarget(c);
public final CardList getColor(final String cardColor) {
final CardList list = new CardList();
for (final Card c : this) {
if (cardColor.equals("Multicolor") && (c.getColor().size() > 1)) {
list.add(c);
} else if (c.isColor(cardColor) && (c.getColor().size() == 1)) {
list.add(c);
}
});
}
return list;
} // getColor()
public final boolean contains(final Card c) {
return this.list.contains(c);
}
public final boolean containsName(final String name) {
return CardPredicates.nameEquals(name).any(list);
}
public final CardList getController(final Player player) {
return this.filter(CardPredicates.isController(player));
}
// cardType is like "Land" or "Goblin", returns a new CardList that is a
// subset of current CardList
public final CardList getType(final String cardType) {
return this.filter(CardPredicates.isType(cardType));
}
// cardType is like "Land" or "Goblin", returns a new CardList with cards
// that do not have this type
public final CardList getNotType(final String cardType) {
return this.filter(Predicate.not(CardPredicates.isType(cardType)));
}
public final CardList getKeyword(final String keyword) {
return this.filter(CardPredicates.hasKeyword(keyword));
}
public final CardList getNotKeyword(final String keyword) {
return this.filter(Predicate.not(CardPredicates.hasKeyword(keyword)));
}
public final CardList getTargetableCards(final SpellAbility source) {
return this.filter(CardPredicates.isTargetableBy(source));
}
/**
@@ -855,40 +489,6 @@ public class CardList implements Iterable<Card> {
});
}
/**
* <p>
* getEquipMagnets.
* </p>
*
* @return a {@link forge.CardList} object.
*/
public final CardList getEquipMagnets() {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return (c.isCreature() && (c.getSVar("EquipMe").equals("Multiple") || (c.getSVar("EquipMe").equals(
"Once") && !c.isEquipped())));
}
});
}
/**
* <p>
* getEnchantMagnets.
* </p>
*
* @return a {@link forge.CardList} object.
*/
public final CardList getEnchantMagnets() {
return this.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return (c.isCreature() && (c.getSVar("EnchantMe").equals("Multiple") || (c.getSVar("EnchantMe").equals(
"Once") && !c.isEnchanted())));
}
});
}
/**
* <p>
* getPossibleBlockers.
@@ -986,58 +586,5 @@ public class CardList implements Iterable<Card> {
});
}
/**
* getAbove.
*
* @param source
* a Card object
* @param compared
* a Card object
* @return a boolean
*/
public final boolean getAbove(final Card source, final Card compared) {
if (source.equals(compared)) {
return false;
}
for (final Card itr : this) {
if (itr.equals(source)) {
return true;
} else if (itr.equals(compared)) {
return false;
}
}
return false;
}
/**
* getDirectlyAbove.
*
* @param source
* a Card object
* @param compared
* a Card object
* @return a boolean
*/
public final boolean getDirectlyAbove(final Card source, final Card compared) {
if (source.equals(compared)) {
return false;
}
boolean checkNext = false;
for (final Card itr : this) {
if (checkNext) {
if (itr.equals(compared)) {
return true;
}
return false;
} else if (itr.equals(source)) {
checkNext = true;
} else if (itr.equals(compared)) {
return false;
}
}
return false;
}
} // end class CardList

View File

@@ -17,7 +17,10 @@
*/
package forge;
import forge.card.spellability.SpellAbility;
import forge.game.player.Player;
import forge.util.closures.Predicate;
import forge.util.closures.PredicateString;
/**
* <p>
@@ -28,205 +31,253 @@ import forge.util.closures.Predicate;
* @version $Id$
*/
public final class CardPredicates {
/**
* a Predicate<Card> to get all cards that are tapped.
*/
public static Predicate<Card> TAPPED = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isTapped();
}
};
/**
* a Predicate<Card> to get all cards that are untapped.
*/
public static Predicate<Card> UNTAPPED = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isUntapped();
}
};
public static Predicate<Card> isController(final Player p) {
return new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.getController().isPlayer(p);
}
};
}
public static Predicate<Card> isOwner(final Player p) {
return new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.getOwner().isPlayer(p);
}
};
}
/**
* a Predicate<Card> to get all creatures.
*/
public static Predicate<Card> CREATURES = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isCreature();
}
};
public static Predicate<Card> isType(final String cardType) {
return new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.isType(cardType);
}
};
}
/**
* a Predicate<Card> to get all enchantments.
*/
public static Predicate<Card> ENCHANTMENTS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isEnchantment();
}
};
public static Predicate<Card> hasKeyword(final String keyword) {
return new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return c.hasKeyword(keyword);
}
};
}
/**
* a Predicate<Card> to get all equipment.
*/
public static Predicate<Card> EQUIPMENT = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isEquipment();
}
};
public static Predicate<Card> containsKeyword(final String keyword) {
return new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return PredicateString.contains(keyword).any(c.getKeyword());
}
};
}
/**
* a Predicate<Card> to get all unenchanted cards in a list.
*/
public static Predicate<Card> UNENCHANTED = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return !c.isEnchanted();
}
};
public static Predicate<Card> isTargetableBy(final SpellAbility source) {
return new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return source.canTarget(c);
}
};
}
/**
* a Predicate<Card> to get all enchanted cards in a list.
*/
public static Predicate<Card> ENCHANTED = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isEnchanted();
}
};
public static Predicate<Card> nameEquals(final String name) {
return new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.getName().equals(name);
}
};
}
/**
* a Predicate<Card> to get all nontoken cards.
*/
public static Predicate<Card> NON_TOKEN = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return !c.isToken();
}
};
public static class Presets {
/**
* a Predicate<Card> to get all token cards.
*/
public static Predicate<Card> TOKEN = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isToken();
}
};
/**
* a Predicate<Card> to get all cards that are tapped.
*/
public static Predicate<Card> TAPPED = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isTapped();
}
};
/**
* a Predicate<Card> to get all cards that are untapped.
*/
public static Predicate<Card> UNTAPPED = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isUntapped();
}
};
/**
* a Predicate<Card> to get all creatures.
*/
public static Predicate<Card> CREATURES = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isCreature();
}
};
/**
* a Predicate<Card> to get all enchantments.
*/
public static Predicate<Card> ENCHANTMENTS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isEnchantment();
}
};
/**
* a Predicate<Card> to get all equipment.
*/
public static Predicate<Card> EQUIPMENT = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isEquipment();
}
};
/**
* a Predicate<Card> to get all unenchanted cards in a list.
*/
public static Predicate<Card> UNENCHANTED = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return !c.isEnchanted();
}
};
/**
* a Predicate<Card> to get all enchanted cards in a list.
*/
public static Predicate<Card> ENCHANTED = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isEnchanted();
}
};
/**
* a Predicate<Card> to get all nontoken cards.
*/
public static Predicate<Card> NON_TOKEN = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return !c.isToken();
}
};
/**
* a Predicate<Card> to get all token cards.
*/
public static Predicate<Card> TOKEN = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isToken();
}
};
/**
* a Predicate<Card> to get all nonbasic lands.
*/
public static Predicate<Card> NON_BASIC_LAND = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return !c.isBasicLand();
}
};
/**
* a Predicate<Card> to get all basicLands.
*/
public static Predicate<Card> BASIC_LANDS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
// the isBasicLand() check here may be sufficient...
return c.isLand() && c.isBasicLand();
}
};
/**
* a Predicate<Card> to get all artifacts.
*/
public static Predicate<Card> ARTIFACTS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isArtifact();
}
};
/**
* a Predicate<Card> to get all nonartifacts.
*/
public static Predicate<Card> NON_ARTIFACTS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return !c.isArtifact();
}
};
/**
* a Predicate<Card> to get all lands.
*/
public static Predicate<Card> LANDS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isLand();
}
};
/**
* a Predicate<Card> to get all nonlands.
*/
public static Predicate<Card> NON_LANDS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return !c.isLand();
}
};
/**
* a Predicate<Card> to get all cards that are black.
*/
public static Predicate<Card> BLACK = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isBlack();
}
};
/**
* a Predicate<Card> to get all cards that are blue.
*/
public static Predicate<Card> BLUE = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isBlue();
}
};
/**
* a Predicate<Card> to get all cards that are green.
*/
public static Predicate<Card> GREEN = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isGreen();
}
};
/**
* a Predicate<Card> to get all cards that are red.
*/
public static Predicate<Card> RED = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isRed();
}
};
/**
* a Predicate<Card> to get all cards that are white.
*/
public static Predicate<Card> WHITE = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isWhite();
}
};
/**
* a Predicate<Card> to get all nonbasic lands.
*/
public static Predicate<Card> NON_BASIC_LAND = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return !c.isBasicLand();
}
};
/**
* a Predicate<Card> to get all basicLands.
*/
public static Predicate<Card> BASIC_LANDS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
// the isBasicLand() check here may be sufficient...
return c.isLand() && c.isBasicLand();
}
};
/**
* a Predicate<Card> to get all artifacts.
*/
public static Predicate<Card> ARTIFACTS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isArtifact();
}
};
/**
* a Predicate<Card> to get all nonartifacts.
*/
public static Predicate<Card> NON_ARTIFACTS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return !c.isArtifact();
}
};
/**
* a Predicate<Card> to get all lands.
*/
public static Predicate<Card> LANDS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isLand();
}
};
/**
* a Predicate<Card> to get all nonlands.
*/
public static Predicate<Card> NON_LANDS = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return !c.isLand();
}
};
/**
* a Predicate<Card> to get all cards that are black.
*/
public static Predicate<Card> BLACK = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isBlack();
}
};
/**
* a Predicate<Card> to get all cards that are blue.
*/
public static Predicate<Card> BLUE = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isBlue();
}
};
/**
* a Predicate<Card> to get all cards that are green.
*/
public static Predicate<Card> GREEN = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isGreen();
}
};
/**
* a Predicate<Card> to get all cards that are red.
*/
public static Predicate<Card> RED = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isRed();
}
};
/**
* a Predicate<Card> to get all cards that are white.
*/
public static Predicate<Card> WHITE = new Predicate<Card>() {
@Override
public boolean isTrue(Card c) {
return c.isWhite();
}
};
}
}

View File

@@ -22,6 +22,7 @@ import java.util.HashMap;
import javax.swing.JOptionPane;
import forge.CardPredicates.Presets;
import forge.card.abilityfactory.AbilityFactory;
import forge.card.cardfactory.CardFactoryUtil;
import forge.card.cost.Cost;
@@ -849,37 +850,34 @@ public final class GameActionUtil {
return;
}
final CardList playerPerms = player.getCardsIn(ZoneType.Battlefield);
final CardList playerLiches = player.getCardsIn(ZoneType.Battlefield, "Lich");
if (AllZoneUtil.isCardInPlay("Lich", player)) {
final CardList lichs = playerPerms.getName("Lich");
for (final Card crd : lichs) {
final Card lich = crd;
final SpellAbility ability = new Ability(lich, "0") {
@Override
public void resolve() {
for (int i = 0; i < damage; i++) {
CardList nonTokens = player.getCardsIn(ZoneType.Battlefield);
nonTokens = nonTokens.filter(CardPredicates.NON_TOKEN);
if (nonTokens.size() == 0) {
player.loseConditionMet(GameLossReason.SpellEffect, lich.getName());
} else {
player.sacrificePermanent("Select a permanent to sacrifice", nonTokens);
}
for (final Card lich : playerLiches) {
final SpellAbility ability = new Ability(lich, "0") {
@Override
public void resolve() {
for (int i = 0; i < damage; i++) {
CardList nonTokens = player.getCardsIn(ZoneType.Battlefield);
nonTokens = nonTokens.filter(Presets.NON_TOKEN);
if (nonTokens.size() == 0) {
player.loseConditionMet(GameLossReason.SpellEffect, lich.getName());
} else {
player.sacrificePermanent("Select a permanent to sacrifice", nonTokens);
}
}
};
}
};
final StringBuilder sb = new StringBuilder();
sb.append(lich.getName()).append(" - ").append(lich.getController());
sb.append(" sacrifices ").append(damage).append(" nontoken permanents.");
ability.setStackDescription(sb.toString());
final StringBuilder sb = new StringBuilder();
sb.append(lich.getName()).append(" - ").append(lich.getController());
sb.append(" sacrifices ").append(damage).append(" nontoken permanents.");
ability.setStackDescription(sb.toString());
AllZone.getStack().addSimultaneousStackEntry(ability);
AllZone.getStack().addSimultaneousStackEntry(ability);
}
}
if (c.getName().equals("Whirling Dervish") || c.getName().equals("Dunerider Outlaw")) {
GameActionUtil.playerCombatDamageWhirlingDervish(c);
}
@@ -1155,7 +1153,7 @@ public final class GameActionUtil {
produces.put("Swamp", "B");
CardList lands = AllZoneUtil.getCardsInGame();
lands = lands.filter(CardPredicates.LANDS);
lands = lands.filter(Presets.LANDS);
// remove all abilities granted by this Command
for (final Card land : lands) {
@@ -1250,12 +1248,9 @@ public final class GameActionUtil {
@Override
public void execute() {
final CardList alphaStatuses = AllZone.getHumanPlayer().getCardsIn(ZoneType.Battlefield)
.getName("Alpha Status");
alphaStatuses.addAll(AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).getName("Alpha Status"));
final CardList alphaStatuses = AllZoneUtil.getCardsIn(ZoneType.Battlefield, "Alpha Status");
final CardList allCreatures = AllZone.getHumanPlayer().getCardsIn(ZoneType.Battlefield).getType("Creature");
allCreatures.addAll(AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).getType("Creature"));
final CardList allCreatures = AllZoneUtil.getCreaturesInPlay();
for (int i = 0; i < this.previouslyPumped.size(); i++) {
this.previouslyPumped.get(i).addSemiPermanentAttackBoost(0 - this.previouslyPumpedValue.get(i));
@@ -1408,8 +1403,7 @@ public final class GameActionUtil {
}
private int countSoundTheCalls() {
CardList list = AllZoneUtil.getCardsIn(ZoneType.Graveyard);
list = list.getName("Sound the Call");
CardList list = AllZoneUtil.getCardsIn(ZoneType.Graveyard, "Sound the Call");
return list.size();
}

View File

@@ -27,7 +27,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.Command;
import forge.GameActionUtil;
@@ -579,10 +579,24 @@ public class AbilityFactoryAttach {
String stCheck = null;
if (attachSource.isAura()) {
stCheck = "EnchantedBy";
magnetList = list.getEnchantMagnets();
magnetList = list.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
if ( !c.isCreature() ) return false;
String sVar = c.getSVar("EnchantMe");
return sVar.equals("Multiple") || (sVar.equals("Once") && !c.isEnchanted());
}
});
} else if (attachSource.isEquipment()) {
stCheck = "EquippedBy";
magnetList = list.getEquipMagnets();
magnetList = list.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
if ( !c.isCreature() ) return false;
String sVar = c.getSVar("EquipMe");
return sVar.equals("Multiple") || (sVar.equals("Once") && !c.isEquipped());
}
});
}
if ((magnetList != null) && !magnetList.isEmpty()) {
@@ -682,7 +696,7 @@ public class AbilityFactoryAttach {
if (attachSource.isAura()) {
// TODO For Auras like Rancor, that aren't as likely to lead to
// card disadvantage, this check should be skipped
prefList = prefList.filter(Predicate.not(CardPredicates.ENCHANTED));
prefList = prefList.filter(Predicate.not(Presets.ENCHANTED));
}
if (!grantingAbilities) {

View File

@@ -27,8 +27,9 @@ import forge.AllZoneUtil;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardList;
import forge.CardPredicates;
import forge.CardListUtil;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.GameActionUtil;
import forge.GameEntity;
@@ -494,7 +495,7 @@ public final class AbilityFactoryChangeZone {
if (params.containsKey("Ninjutsu")) {
if (source.isType("Legendary") && !AllZoneUtil.isCardInPlay("Mirror Gallery")) {
final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
if (list.containsName(source.getName())) {
if (CardPredicates.nameEquals(source.getName()).any(list)) {
return false;
}
}
@@ -1205,14 +1206,15 @@ public final class AbilityFactoryChangeZone {
c = CardFactoryUtil.getBestAI(fetchList);
} else {
// Don't fetch another tutor with the same name
if (origin.contains(ZoneType.Library) && !fetchList.getNotName(card.getName()).isEmpty()) {
fetchList = fetchList.getNotName(card.getName());
CardList sameNamed = fetchList.filter(Predicate.not(CardPredicates.nameEquals(card.getName())));
if (origin.contains(ZoneType.Library) && !sameNamed.isEmpty()) {
fetchList = sameNamed;
}
Player ai = AllZone.getComputerPlayer();
// Does AI need a land?
CardList hand = ai.getCardsIn(ZoneType.Hand);
System.out.println("Lands in hand = " + hand.filter(CardPredicates.LANDS).size() + ", on battlefield = " + ai.getCardsIn(ZoneType.Battlefield).filter(CardPredicates.LANDS).size());
if (hand.filter(CardPredicates.LANDS).size() == 0 && ai.getCardsIn(ZoneType.Battlefield).filter(CardPredicates.LANDS).size() < 4) {
System.out.println("Lands in hand = " + hand.filter(Presets.LANDS).size() + ", on battlefield = " + ai.getCardsIn(ZoneType.Battlefield).filter(Presets.LANDS).size());
if (hand.filter(Presets.LANDS).size() == 0 && ai.getCardsIn(ZoneType.Battlefield).filter(Presets.LANDS).size() < 4) {
boolean canCastSomething = false;
for (Card cardInHand : hand) {
canCastSomething |= ComputerUtil.payManaCost(cardInHand.getFirstSpellAbility(), AllZone.getComputerPlayer(), true, 0, false);
@@ -1646,7 +1648,7 @@ public final class AbilityFactoryChangeZone {
CardList list = AllZoneUtil.getCardsIn(origin);
list = list.getValidCards(tgt.getValidTgts(), AllZone.getComputerPlayer(), source);
if (source.isInZone(ZoneType.Hand)) {
list = list.getNotName(source.getName()); // Don't get the same card back.
list = list.filter(Predicate.not(CardPredicates.nameEquals(source.getName()))); // Don't get the same card back.
}
if (list.size() < tgt.getMinTargets(sa.getSourceCard(), sa)) {
@@ -2958,10 +2960,10 @@ public final class AbilityFactoryChangeZone {
// if Shuffle parameter exists, and any amount of cards were owned by
// that player, then shuffle that library
if (params.containsKey("Shuffle")) {
if (cards.getOwner(AllZone.getHumanPlayer()).size() > 0) {
if (cards.filter(CardPredicates.isOwner(AllZone.getHumanPlayer())).size() > 0) {
AllZone.getHumanPlayer().shuffle();
}
if (cards.getOwner(AllZone.getComputerPlayer()).size() > 0) {
if (cards.filter(CardPredicates.isOwner(AllZone.getComputerPlayer())).size() > 0) {
AllZone.getComputerPlayer().shuffle();
}
}

View File

@@ -33,7 +33,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.Constant;
import forge.card.cardfactory.CardFactoryUtil;
@@ -1643,7 +1643,7 @@ public final class AbilityFactoryChoose {
}
} else {
CardList list = AllZoneUtil.getCardsInGame().getController(AllZone.getHumanPlayer());
list = list.filter(Predicate.not(CardPredicates.LANDS));
list = list.filter(Predicate.not(Presets.LANDS));
if (!list.isEmpty()) {
chosen = list.get(0).getName();
}
@@ -1976,8 +1976,8 @@ public final class AbilityFactoryChoose {
}
} else { // Computer
if (params.containsKey("AILogic") && params.get("AILogic").equals("BestBlocker")) {
if (choices.filter(CardPredicates.UNTAPPED).isEmpty()) {
choices = choices.filter(CardPredicates.UNTAPPED);
if (choices.filter(Presets.UNTAPPED).isEmpty()) {
choices = choices.filter(Presets.UNTAPPED);
}
chosen.add(CardFactoryUtil.getBestCreatureAI(choices));
} else {

View File

@@ -28,7 +28,7 @@ import forge.AllZoneUtil;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Command;
import forge.Singletons;
import forge.card.cost.Cost;
@@ -323,7 +323,7 @@ public final class AbilityFactoryCopy {
}
Card choice;
if (list.filter(CardPredicates.CREATURES).size() > 0) {
if (list.filter(Presets.CREATURES).size() > 0) {
choice = CardFactoryUtil.getBestCreatureAI(list);
} else {
choice = CardFactoryUtil.getMostExpensivePermanentAI(list, sa, true);

View File

@@ -26,7 +26,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.cardfactory.CardFactoryUtil;
import forge.card.cost.Cost;
@@ -403,7 +403,7 @@ public class AbilityFactoryPermanentState {
untapList = untapList.getTargetableCards(sa);
untapList = untapList.getValidCards(tgt.getValidTgts(), source.getController(), source);
untapList = untapList.filter(CardPredicates.TAPPED);
untapList = untapList.filter(Presets.TAPPED);
// filter out enchantments and planeswalkers, their tapped state doesn't
// matter.
final String[] tappablePermanents = { "Creature", "Land", "Artifact" };
@@ -486,7 +486,7 @@ public class AbilityFactoryPermanentState {
}
// try to just tap already tapped things
tapList = list.filter(CardPredicates.UNTAPPED);
tapList = list.filter(Presets.UNTAPPED);
if (AbilityFactoryPermanentState.untapTargetList(source, tgt, af, sa, mandatory, tapList)) {
return true;
@@ -634,7 +634,7 @@ public class AbilityFactoryPermanentState {
} else {
CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
list = list.getType(valid);
list = list.filter(CardPredicates.TAPPED);
list = list.filter(Presets.TAPPED);
int count = 0;
while ((list.size() != 0) && (count < num)) {
@@ -996,7 +996,7 @@ public class AbilityFactoryPermanentState {
private static boolean tapPrefTargeting(final Card source, final Target tgt, final AbilityFactory af,
final SpellAbility sa, final boolean mandatory) {
CardList tapList = AllZone.getHumanPlayer().getCardsIn(ZoneType.Battlefield);
tapList = tapList.filter(CardPredicates.UNTAPPED);
tapList = tapList.filter(Presets.UNTAPPED);
tapList = tapList.getValidCards(tgt.getValidTgts(), source.getController(), source);
// filter out enchantments and planeswalkers, their tapped state doesn't matter.
final String[] tappablePermanents = { "Creature", "Land", "Artifact" };
@@ -1133,7 +1133,7 @@ public class AbilityFactoryPermanentState {
}
// try to just tap already tapped things
tapList = list.filter(CardPredicates.TAPPED);
tapList = list.filter(Presets.TAPPED);
if (AbilityFactoryPermanentState.tapTargetList(af, sa, tapList, mandatory)) {
return true;
@@ -1752,7 +1752,7 @@ public class AbilityFactoryPermanentState {
}
validTappables = validTappables.getValidCards(valid, source.getController(), source);
validTappables = validTappables.filter(CardPredicates.UNTAPPED);
validTappables = validTappables.filter(Presets.UNTAPPED);
final Random r = MyRandom.getRandom();
boolean rr = false;
@@ -1794,7 +1794,7 @@ public class AbilityFactoryPermanentState {
private static CardList getTapAllTargets(final String valid, final Card source) {
CardList tmpList = AllZoneUtil.getCardsIn(ZoneType.Battlefield);
tmpList = tmpList.getValidCards(valid, source.getController(), source);
tmpList = tmpList.filter(CardPredicates.UNTAPPED);
tmpList = tmpList.filter(Presets.UNTAPPED);
return tmpList;
}

View File

@@ -6,7 +6,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Command;
import forge.Counters;
import forge.Singletons;
@@ -352,7 +352,7 @@ class CardFactoryArtifacts {
final Player player = this.getTargetPlayer();
CardList lands = player.getCardsIn(ZoneType.Graveyard);
lands = lands.filter(CardPredicates.BASIC_LANDS);
lands = lands.filter(Presets.BASIC_LANDS);
if (card.getController().isHuman()) {
// now, select up to four lands
int end = -1;

View File

@@ -26,8 +26,8 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardListUtil;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.Command;
import forge.Singletons;
@@ -422,7 +422,7 @@ class CardFactoryAuras {
// This includes creatures Animate Dead can't enchant once
// in play.
// The human may try to Animate them, the AI will not.
return AllZoneUtil.getCardsIn(ZoneType.Graveyard).filter(CardPredicates.CREATURES);
return AllZoneUtil.getCardsIn(ZoneType.Graveyard).filter(Presets.CREATURES);
}
@Override

View File

@@ -23,6 +23,7 @@ import java.util.List;
import javax.swing.JOptionPane;
import com.esotericsoftware.minlog.Log;
import com.google.common.base.Predicates;
import forge.AllZone;
import forge.AllZoneUtil;
@@ -30,6 +31,7 @@ import forge.Card;
import forge.CardCharacteristicName;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.Command;
import forge.Constant;
@@ -73,8 +75,8 @@ public class CardFactoryCreatures {
@Override
public boolean canPlayAI() {
final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
return Predicate.or(CardPredicates.nameEquals("Glorious Anthem"), CardPredicates.nameEquals("Gaea's Anthem")).any(list);
return list.containsName("Glorious Anthem") || list.containsName("Gaea's Anthem");
}
};
// Do not remove SpellAbilities created by AbilityFactory or
@@ -223,7 +225,7 @@ public class CardFactoryCreatures {
} else { // computer
CardList art = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
art = art.filter(CardPredicates.ARTIFACTS);
art = art.filter(Presets.ARTIFACTS);
CardList list = new CardList(art);
list = list.filter(new Predicate<Card>() {
@@ -316,12 +318,11 @@ public class CardFactoryCreatures {
list.addAll(AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield));
color[0] = Constant.Color.WHITE;
int max = list.getKeywordsContain(color[0]).size();
int max = 0;
list.filter(CardPredicates.containsKeyword(color[0])).size();
final String[] colors = { Constant.Color.BLUE, Constant.Color.BLACK, Constant.Color.RED,
Constant.Color.GREEN };
for (final String c : colors) {
final int cmp = list.getKeywordsContain(c).size();
for (final String c : Constant.Color.ONLY_COLORS) {
final int cmp = list.filter(CardPredicates.containsKeyword(c)).size();
if (cmp > max) {
max = cmp;
color[0] = c;
@@ -420,7 +421,7 @@ public class CardFactoryCreatures {
@Override
public void resolve() {
CardList allTokens = AllZoneUtil.getCreaturesInPlay(card.getController());
allTokens = allTokens.filter(CardPredicates.TOKEN);
allTokens = allTokens.filter(Presets.TOKEN);
CardFactoryUtil.copyTokens(allTokens);
}
@@ -428,7 +429,7 @@ public class CardFactoryCreatures {
@Override
public boolean canPlayAI() {
CardList allTokens = AllZoneUtil.getCreaturesInPlay(AllZone.getComputerPlayer());
allTokens = allTokens.filter(CardPredicates.TOKEN);
allTokens = allTokens.filter(Presets.TOKEN);
return allTokens.size() >= 2;
}
@@ -1043,7 +1044,7 @@ public class CardFactoryCreatures {
public boolean canPlayAI() {
// get all creatures
CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Graveyard);
list = list.filter(CardPredicates.CREATURES);
list = list.filter(Presets.CREATURES);
return 0 < list.size();
}
});
@@ -1065,12 +1066,12 @@ public class CardFactoryCreatures {
final Player opp = player.getOpponent();
int max = 0;
CardList play = opp.getCardsIn(ZoneType.Battlefield);
play = play.filter(CardPredicates.NON_TOKEN);
play = play.filter(CardPredicates.WHITE);
play = play.filter(Presets.NON_TOKEN);
play = play.filter(Presets.WHITE);
max += play.size();
CardList grave = opp.getCardsIn(ZoneType.Graveyard);
grave = grave.filter(CardPredicates.WHITE);
grave = grave.filter(Presets.WHITE);
max += grave.size();
final String[] life = new String[max + 1];

View File

@@ -21,7 +21,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Command;
import forge.Singletons;
import forge.card.cost.Cost;
@@ -417,7 +417,7 @@ public class CardFactoryInstants {
@Override
public void resolve() {
final Player you = card.getController();
final CardList ens = AllZoneUtil.getCardsIn(ZoneType.Battlefield).filter(CardPredicates.ENCHANTMENTS);
final CardList ens = AllZoneUtil.getCardsIn(ZoneType.Battlefield).filter(Presets.ENCHANTMENTS);
final CardList toReturn = ens.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {

View File

@@ -23,7 +23,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Command;
import forge.Counters;
import forge.GameActionUtil;
@@ -250,7 +250,7 @@ class CardFactoryLands {
}
} // selectCard()
}; // Input
if ((AllZoneUtil.getPlayerLandsInPlay(AllZone.getHumanPlayer()).filter(CardPredicates.UNTAPPED)
if ((AllZoneUtil.getPlayerLandsInPlay(AllZone.getHumanPlayer()).filter(Presets.UNTAPPED)
.size() < 2)) {
Singletons.getModel().getGameAction().sacrifice(card, null);
return;
@@ -297,7 +297,7 @@ class CardFactoryLands {
if (this.player.isComputer()) {
if (land.size() > 0) {
CardList tappedLand = new CardList(land);
tappedLand = tappedLand.filter(CardPredicates.TAPPED);
tappedLand = tappedLand.filter(Presets.TAPPED);
// if any are tapped, sacrifice it
// else sacrifice random
if (tappedLand.size() > 0) {
@@ -378,7 +378,7 @@ class CardFactoryLands {
@Override
public void execute() {
CardList plains = AllZoneUtil.getPlayerLandsInPlay(card.getController());
plains = plains.filter(CardPredicates.UNTAPPED);
plains = plains.filter(Presets.UNTAPPED);
if (this.player.isComputer()) {
if (plains.size() > 1) {
@@ -397,7 +397,7 @@ class CardFactoryLands {
}
} else { // this is the human resolution
final int[] paid = { 0 };
if ((AllZoneUtil.getPlayerLandsInPlay(AllZone.getHumanPlayer()).filter(CardPredicates.UNTAPPED)
if ((AllZoneUtil.getPlayerLandsInPlay(AllZone.getHumanPlayer()).filter(Presets.UNTAPPED)
.size() < 2)) {
Singletons.getModel().getGameAction().sacrifice(card, null);
return;

View File

@@ -30,8 +30,9 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardListUtil;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.Command;
import forge.Singletons;
@@ -310,10 +311,10 @@ public class CardFactorySorceries {
@Override
public boolean canPlayAI() {
CardList humTokenCreats = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer());
humTokenCreats = humTokenCreats.filter(CardPredicates.TOKEN);
humTokenCreats = humTokenCreats.filter(Presets.TOKEN);
CardList compTokenCreats = AllZoneUtil.getCreaturesInPlay(AllZone.getComputerPlayer());
compTokenCreats = compTokenCreats.filter(CardPredicates.TOKEN);
compTokenCreats = compTokenCreats.filter(Presets.TOKEN);
return compTokenCreats.size() > humTokenCreats.size();
} // canPlayAI()
@@ -321,7 +322,7 @@ public class CardFactorySorceries {
@Override
public void resolve() {
CardList tokens = AllZoneUtil.getCreaturesInPlay();
tokens = tokens.filter(CardPredicates.TOKEN);
tokens = tokens.filter(Presets.TOKEN);
CardFactoryUtil.copyTokens(tokens);
@@ -564,7 +565,7 @@ public class CardFactorySorceries {
final CardList lib = player.getCardsIn(ZoneType.Library);
for (final Card c : grave) {
final CardList remLib = lib.getName(c.getName());
final CardList remLib = lib.filter(CardPredicates.nameEquals(c.getName()));
for (final Card rem : remLib) {
Singletons.getModel().getGameAction().exile(rem);
lib.remove(rem);
@@ -1404,7 +1405,7 @@ public class CardFactorySorceries {
@Override
public void showMessage() {
CardList grave = card.getController().getCardsIn(ZoneType.Graveyard);
grave = grave.filter(CardPredicates.CREATURES);
grave = grave.filter(Presets.CREATURES);
grave = grave.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
@@ -1554,7 +1555,7 @@ public class CardFactorySorceries {
// get all
final CardList creatures = AllZoneUtil.getCreaturesInPlay();
CardList grave = card.getController().getCardsIn(ZoneType.Graveyard);
grave = grave.filter(CardPredicates.CREATURES);
grave = grave.filter(Presets.CREATURES);
if (AllZone.getHumanPlayer().canBeTargetedBy(spell)
|| AllZone.getComputerPlayer().canBeTargetedBy(spell)) {
@@ -1635,7 +1636,7 @@ public class CardFactorySorceries {
// Sacrifice an artifact
CardList arts = p.getCardsIn(ZoneType.Battlefield);
arts = arts.filter(CardPredicates.ARTIFACTS);
arts = arts.filter(Presets.ARTIFACTS);
final Object toSac = GuiUtils.chooseOneOrNone("Sacrifice an artifact", arts.toArray());
if (toSac != null) {
final Card c = (Card) toSac;
@@ -1648,7 +1649,7 @@ public class CardFactorySorceries {
// Search your library for an artifact
final CardList lib = p.getCardsIn(ZoneType.Library);
GuiUtils.chooseOneOrNone("Looking at Library", lib.toArray());
final CardList libArts = lib.filter(CardPredicates.ARTIFACTS);
final CardList libArts = lib.filter(Presets.ARTIFACTS);
final Object o = GuiUtils.chooseOneOrNone("Search for artifact", libArts.toArray());
if (o != null) {
newArtifact[0] = (Card) o;

View File

@@ -32,8 +32,8 @@ import forge.AllZoneUtil;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardList;
import forge.CardPredicates;
import forge.CardListUtil;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.Command;
import forge.CommandArgs;
@@ -2576,7 +2576,7 @@ public class CardFactoryUtil {
// Count$ColoredCreatures *a DOMAIN for creatures*
if (sq[0].contains("ColoredCreatures")) {
someCards.addAll(cardController.getCardsIn(ZoneType.Battlefield));
someCards = someCards.filter(CardPredicates.CREATURES);
someCards = someCards.filter(Presets.CREATURES);
final String[] colors = { "green", "white", "red", "blue", "black" };
@@ -3082,11 +3082,11 @@ public class CardFactoryUtil {
// "Untapped Lands" - Count$UntappedTypeYouCtrl.Land
if (sq[0].contains("Untapped")) {
someCards = someCards.filter(CardPredicates.UNTAPPED);
someCards = someCards.filter(Presets.UNTAPPED);
}
if (sq[0].contains("Tapped")) {
someCards = someCards.filter(CardPredicates.TAPPED);
someCards = someCards.filter(Presets.TAPPED);
}
// String sq0 = sq[0].toLowerCase();
@@ -3096,23 +3096,23 @@ public class CardFactoryUtil {
// }
// "White Creatures" - Count$WhiteTypeYouCtrl.Creature
if (sq[0].contains("White")) {
someCards = someCards.filter(CardPredicates.WHITE);
someCards = someCards.filter(Presets.WHITE);
}
if (sq[0].contains("Blue")) {
someCards = someCards.filter(CardPredicates.BLUE);
someCards = someCards.filter(Presets.BLUE);
}
if (sq[0].contains("Black")) {
someCards = someCards.filter(CardPredicates.BLACK);
someCards = someCards.filter(Presets.BLACK);
}
if (sq[0].contains("Red")) {
someCards = someCards.filter(CardPredicates.RED);
someCards = someCards.filter(Presets.RED);
}
if (sq[0].contains("Green")) {
someCards = someCards.filter(CardPredicates.GREEN);
someCards = someCards.filter(Presets.GREEN);
}
if (sq[0].contains("Multicolor")) {
@@ -3147,7 +3147,7 @@ public class CardFactoryUtil {
int mmc = 0;
int cmc = 0;
for (int i = 0; i < someCards.size(); i++) {
cmc = someCards.getCard(i).getManaCost().getCMC();
cmc = someCards.get(i).getManaCost().getCMC();
if (cmc > mmc) {
mmc = cmc;
}
@@ -3628,7 +3628,7 @@ public class CardFactoryUtil {
final CardList list = new CardList();
for (int tokenAdd = 0; tokenAdd < tokenList.size(); tokenAdd++) {
final Card thisToken = tokenList.getCard(tokenAdd);
final Card thisToken = tokenList.get(tokenAdd);
final ArrayList<String> tal = thisToken.getType();
final String[] tokenTypes = new String[tal.size()];

View File

@@ -19,7 +19,7 @@ package forge.card.cost;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.card.abilityfactory.AbilityFactory;
import forge.card.spellability.SpellAbility;
import forge.control.input.Input;
@@ -119,7 +119,7 @@ public class CostTapType extends CostPartWithList {
if (cost.getTap()) {
typeList.remove(source);
}
typeList = typeList.filter(CardPredicates.UNTAPPED);
typeList = typeList.filter(Presets.UNTAPPED);
final Integer amount = this.convertAmount();
if ((typeList.size() == 0) || ((amount != null) && (typeList.size() < amount))) {
@@ -154,7 +154,7 @@ public class CostTapType extends CostPartWithList {
CardList typeList = ability.getActivatingPlayer().getCardsIn(ZoneType.Battlefield);
typeList = typeList.getValidCards(this.getType().split(";"), ability.getActivatingPlayer(),
ability.getSourceCard());
typeList = typeList.filter(CardPredicates.UNTAPPED);
typeList = typeList.filter(Presets.UNTAPPED);
final String amount = this.getAmount();
Integer c = this.convertAmount();
if (c == null) {
@@ -189,7 +189,7 @@ public class CostTapType extends CostPartWithList {
CardList typeList = ability.getActivatingPlayer().getCardsIn(ZoneType.Battlefield);
typeList = typeList.getValidCards(this.getType().split(";"), ability.getActivatingPlayer(),
ability.getSourceCard());
typeList = typeList.filter(CardPredicates.UNTAPPED);
typeList = typeList.filter(Presets.UNTAPPED);
c = typeList.size();
source.setSVar("ChosenX", "Number$" + Integer.toString(c));
}

View File

@@ -20,7 +20,7 @@ package forge.card.cost;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.card.abilityfactory.AbilityFactory;
import forge.card.spellability.SpellAbility;
import forge.control.input.Input;
@@ -124,7 +124,7 @@ public class CostUntapType extends CostPartWithList {
if (cost.getUntap()) {
typeList.remove(source);
}
typeList = typeList.filter(CardPredicates.TAPPED);
typeList = typeList.filter(Presets.TAPPED);
final Integer amount = this.convertAmount();
if ((typeList.size() == 0) || ((amount != null) && (typeList.size() < amount))) {
@@ -160,7 +160,7 @@ public class CostUntapType extends CostPartWithList {
CardList typeList = AllZoneUtil.getCardsIn(ZoneType.Battlefield);
typeList = typeList.getValidCards(this.getType().split(";"), ability.getActivatingPlayer(),
ability.getSourceCard());
typeList = typeList.filter(CardPredicates.TAPPED);
typeList = typeList.filter(Presets.TAPPED);
if (untap) {
typeList.remove(source);
}
@@ -201,7 +201,7 @@ public class CostUntapType extends CostPartWithList {
if (untap) {
typeList.remove(source);
}
typeList = typeList.filter(CardPredicates.TAPPED);
typeList = typeList.filter(Presets.TAPPED);
c = typeList.size();
source.setSVar("ChosenX", "Number$" + Integer.toString(c));
}

View File

@@ -23,6 +23,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.Command;
import forge.CommandReturn;
import forge.Singletons;
@@ -339,7 +340,7 @@ public class SpellPermanent extends Spell {
// check on legendary
if (card.isType("Legendary") && !AllZoneUtil.isCardInPlay("Mirror Gallery")) {
final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
if (list.containsName(card.getName())) {
if (CardPredicates.nameEquals(card.getName()).any(list)) {
return false;
}
}

View File

@@ -11,7 +11,7 @@ import javax.swing.JOptionPane;
import forge.AllZone;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.Constant;
import forge.GameAction;
@@ -446,9 +446,9 @@ public class GameNew {
private static void seeWhoPlaysFirst() {
final GameAction ga = Singletons.getModel().getGameAction();
CardList hLibrary = AllZone.getHumanPlayer().getCardsIn(ZoneType.Library);
hLibrary = hLibrary.filter(CardPredicates.NON_LANDS);
hLibrary = hLibrary.filter(Presets.NON_LANDS);
CardList cLibrary = AllZone.getComputerPlayer().getCardsIn(ZoneType.Library);
cLibrary = cLibrary.filter(CardPredicates.NON_LANDS);
cLibrary = cLibrary.filter(Presets.NON_LANDS);
final boolean starterDetermined = false;
int cutCount = 0;

View File

@@ -852,7 +852,7 @@ public class Combat {
if (bFirstStrike) {
CombatUtil.checkUnblockedAttackers(unblocked.get(j));
} else {
if (!unblocked.getCard(j).hasFirstStrike() && !unblocked.getCard(j).hasDoubleStrike()) {
if (!unblocked.get(j).hasFirstStrike() && !unblocked.get(j).hasDoubleStrike()) {
CombatUtil.checkUnblockedAttackers(unblocked.get(j));
}
}

View File

@@ -23,7 +23,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.trigger.TriggerType;
import forge.game.player.Player;
@@ -101,7 +101,7 @@ public class PhaseUtil {
Singletons.getModel().getGameAction().resetActivationsPerTurn();
final CardList lands = AllZoneUtil.getPlayerLandsInPlay(turn).filter(CardPredicates.UNTAPPED);
final CardList lands = AllZoneUtil.getPlayerLandsInPlay(turn).filter(Presets.UNTAPPED);
turn.setNumPowerSurgeLands(lands.size());
// anything before this point happens regardless of whether the Untap

View File

@@ -23,7 +23,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Counters;
import forge.GameActionUtil;
import forge.GameEntity;
@@ -195,7 +195,7 @@ public class Untap extends Phase implements java.io.Serializable {
if (Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn().isComputer()) {
// search for lands the computer has and only untap 1
CardList landList = AllZoneUtil.getPlayerLandsInPlay(AllZone.getComputerPlayer());
landList = landList.filter(CardPredicates.TAPPED).filter(new Predicate<Card>() {
landList = landList.filter(Presets.TAPPED).filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return Untap.canUntap(c);
@@ -228,7 +228,7 @@ public class Untap extends Phase implements java.io.Serializable {
} // selectCard()
}; // Input
CardList landList = AllZoneUtil.getPlayerLandsInPlay(AllZone.getHumanPlayer());
landList = landList.filter(CardPredicates.TAPPED).filter(new Predicate<Card>() {
landList = landList.filter(Presets.TAPPED).filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return Untap.canUntap(c);
@@ -242,8 +242,8 @@ public class Untap extends Phase implements java.io.Serializable {
if (AllZoneUtil.isCardInPlay("Damping Field") || AllZoneUtil.isCardInPlay("Imi Statue")) {
if (Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn().isComputer()) {
CardList artList = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
artList = artList.filter(CardPredicates.ARTIFACTS);
artList = artList.filter(CardPredicates.TAPPED).filter(new Predicate<Card>() {
artList = artList.filter(Presets.ARTIFACTS);
artList = artList.filter(Presets.TAPPED).filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return Untap.canUntap(c);
@@ -277,8 +277,8 @@ public class Untap extends Phase implements java.io.Serializable {
} // selectCard()
}; // Input
CardList artList = AllZone.getHumanPlayer().getCardsIn(ZoneType.Battlefield);
artList = artList.filter(CardPredicates.ARTIFACTS);
artList = artList.filter(CardPredicates.TAPPED).filter(new Predicate<Card>() {
artList = artList.filter(Presets.ARTIFACTS);
artList = artList.filter(Presets.TAPPED).filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return Untap.canUntap(c);
@@ -292,7 +292,7 @@ public class Untap extends Phase implements java.io.Serializable {
if ((AllZoneUtil.isCardInPlay("Smoke") || AllZoneUtil.isCardInPlay("Stoic Angel"))) {
if (Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn().isComputer()) {
CardList creatures = AllZoneUtil.getCreaturesInPlay(AllZone.getComputerPlayer());
creatures = creatures.filter(CardPredicates.TAPPED).filter(new Predicate<Card>() {
creatures = creatures.filter(Presets.TAPPED).filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return Untap.canUntap(c);
@@ -326,7 +326,7 @@ public class Untap extends Phase implements java.io.Serializable {
} // selectCard()
}; // Input
CardList creatures = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer());
creatures = creatures.filter(CardPredicates.TAPPED).filter(new Predicate<Card>() {
creatures = creatures.filter(Presets.TAPPED).filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return Untap.canUntap(c);

View File

@@ -23,8 +23,9 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardListUtil;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Command;
import forge.Counters;
import forge.GameAction;
@@ -481,7 +482,7 @@ public class Upkeep extends Phase implements java.io.Serializable {
final Card abyss = c;
final CardList abyssGetTargets = AllZoneUtil.getCreaturesInPlay(player)
.filter(CardPredicates.NON_ARTIFACTS);
.filter(Presets.NON_ARTIFACTS);
final Ability sacrificeCreature = new Ability(abyss, "") {
@Override
@@ -2277,9 +2278,9 @@ public class Upkeep extends Phase implements java.io.Serializable {
enchantmentsInLibrary = enchantmentsInLibrary.filter(new Predicate<Card>() {
@Override
public boolean isTrue(final Card c) {
return (c.isEnchantment() && c.hasKeyword("Enchant player")
return c.isEnchantment() && c.hasKeyword("Enchant player")
&& !source.getEnchantingPlayer().hasProtectionFrom(c)
&& !enchantmentsAttached.containsName(c));
&& !CardPredicates.nameEquals(c.getName()).any(enchantmentsAttached);
}
});
final Player player = source.getController();

View File

@@ -22,8 +22,9 @@ import java.util.Random;
import forge.AllZone;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardListUtil;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.cardfactory.CardFactoryUtil;
import forge.card.spellability.SpellAbility;
@@ -201,13 +202,13 @@ public class AIPlayer extends Player {
boolean bottom = false;
if (topN.get(i).isBasicLand()) {
CardList bl = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
bl = bl.filter(CardPredicates.BASIC_LANDS);
bl = bl.filter(CardPredicates.Presets.BASIC_LANDS);
bottom = bl.size() > 5; // if control more than 5 Basic land,
// probably don't need more
} else if (topN.get(i).isCreature()) {
CardList cl = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
cl = cl.filter(CardPredicates.CREATURES);
cl = cl.filter(CardPredicates.Presets.CREATURES);
bottom = cl.size() > 5; // if control more than 5 Creatures,
// probably don't need more
}

View File

@@ -26,8 +26,8 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardListUtil;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.GameActionUtil;
import forge.Singletons;
@@ -1213,7 +1213,7 @@ public class ComputerUtil {
return false;
}
CardList landList = computer.getCardsIn(ZoneType.Hand);
landList = landList.filter(CardPredicates.LANDS);
landList = landList.filter(Presets.LANDS);
final CardList lands = computer.getCardsIn(ZoneType.Graveyard);
for (final Card crd : lands) {
@@ -1631,7 +1631,7 @@ public class ComputerUtil {
typeList = typeList.getValidCards(type.split(","), activate.getController(), activate);
// is this needed?
typeList = typeList.filter(CardPredicates.UNTAPPED);
typeList = typeList.filter(Presets.UNTAPPED);
if (tap) {
typeList.remove(activate);
@@ -1671,7 +1671,7 @@ public class ComputerUtil {
typeList = typeList.getValidCards(type.split(","), activate.getController(), activate);
// is this needed?
typeList = typeList.filter(CardPredicates.TAPPED);
typeList = typeList.filter(Presets.TAPPED);
if (untap) {
typeList.remove(activate);

View File

@@ -373,8 +373,7 @@ public class ComputerUtilAttack {
// Beastmaster Ascension
if (AllZoneUtil.isCardInPlay("Beastmaster Ascension", AllZone.getComputerPlayer())
&& (this.attackers.size() > 1)) {
final CardList beastions = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield)
.getName("Beastmaster Ascension");
final CardList beastions = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield, "Beastmaster Ascension");
int minCreatures = 7;
for (final Card beastion : beastions) {
final int counters = beastion.getCounters(Counters.QUEST);
@@ -681,7 +680,7 @@ public class ComputerUtilAttack {
// get the list of attackers up to the first blocked one
final CardList attritionalAttackers = new CardList();
for (int x = 0; x < (this.attackers.size() - humanForces); x++) {
attritionalAttackers.add(this.attackers.getCard(x));
attritionalAttackers.add(this.attackers.get(x));
}
// until the attackers are used up or the player would run out of life
int attackRounds = 1;
@@ -689,7 +688,7 @@ public class ComputerUtilAttack {
// sum attacker damage
int damageThisRound = 0;
for (int y = 0; y < attritionalAttackers.size(); y++) {
damageThisRound += attritionalAttackers.getCard(y).getNetCombatDamage();
damageThisRound += attritionalAttackers.get(y).getNetCombatDamage();
}
// remove from player life
humanLife -= damageThisRound;

View File

@@ -23,6 +23,7 @@ import forge.AllZone;
import forge.Card;
import forge.CardList;
import forge.CardListUtil;
import forge.CardPredicates;
import forge.Counters;
import forge.GameEntity;
import forge.card.cardfactory.CardFactoryUtil;
@@ -397,9 +398,9 @@ public class ComputerUtilBlock {
private static Combat makeGangBlocks(final Combat combat) {
CardList currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft());
currentAttackers = currentAttackers.getKeywordsDontContain("Rampage");
currentAttackers = currentAttackers
.getKeywordsDontContain("CARDNAME can't be blocked by more than one creature.");
.filter(Predicate.not(CardPredicates.containsKeyword("Rampage")))
.filter(Predicate.not(CardPredicates.containsKeyword("CARDNAME can't be blocked by more than one creature.")));
CardList blockers;
// Try to block an attacker without first strike with a gang of first strikers
@@ -596,9 +597,10 @@ public class ComputerUtilBlock {
CardList chumpBlockers;
CardList tramplingAttackers = ComputerUtilBlock.getAttackers().getKeyword("Trample");
tramplingAttackers = tramplingAttackers.getKeywordsDontContain("Rampage"); // Don't make it worse
tramplingAttackers = tramplingAttackers
.getKeywordsDontContain("CARDNAME can't be blocked by more than one creature.");
.filter(Predicate.not(CardPredicates.containsKeyword("Rampage")))
.filter(Predicate.not(CardPredicates.containsKeyword("CARDNAME can't be blocked by more than one creature.")));
// TODO - should check here for a "rampage-like" trigger that replaced
// the keyword:
// "Whenever CARDNAME becomes blocked, it gets +1/+1 until end of turn for each creature blocking it."
@@ -643,12 +645,11 @@ public class ComputerUtilBlock {
CardList safeBlockers;
CardList blockers;
CardList targetAttackers = ComputerUtilBlock.getBlockedButUnkilled().getKeywordsDontContain("Rampage"); // Don't
// make
// it
// worse
targetAttackers = targetAttackers
.getKeywordsDontContain("CARDNAME can't be blocked by more than one creature.");
CardList targetAttackers = ComputerUtilBlock.getBlockedButUnkilled()
.filter(Predicate.not(CardPredicates.containsKeyword("Rampage")))
.filter(Predicate.not(CardPredicates.containsKeyword("CARDNAME can't be blocked by more than one creature.")));
// TODO - should check here for a "rampage-like" trigger that replaced
// the keyword:
// "Whenever CARDNAME becomes blocked, it gets +1/+1 until end of turn for each creature blocking it."

View File

@@ -32,6 +32,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardUtil;
import forge.Constant;
import forge.GameActionUtil;
@@ -1415,7 +1416,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* @return a CardList with all the cards currently in that player's library
*/
public final CardList getCardsIn(final ZoneType zone, final String cardName) {
return this.getCardsIn(zone).getName(cardName);
return this.getCardsIn(zone).filter(CardPredicates.nameEquals(cardName));
}
/**

View File

@@ -28,7 +28,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Command;
import forge.GameActionUtil;
import forge.Singletons;
@@ -762,7 +762,7 @@ public class MagicStack extends MyObservable {
if (sp.isSpell() && AllZoneUtil.isCardInPlay("Bazaar of Wonders")) {
boolean found = false;
CardList all = AllZoneUtil.getCardsIn(ZoneType.Battlefield);
all = all.filter(CardPredicates.NON_TOKEN);
all = all.filter(Presets.NON_TOKEN);
final CardList graves = AllZoneUtil.getCardsIn(ZoneType.Graveyard);
all.addAll(graves);

View File

@@ -24,7 +24,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Command;
import forge.GameActionUtil;
import forge.card.spellability.Ability;
@@ -163,7 +163,7 @@ public class PlayerZoneComesIntoPlay extends DefaultPlayerZone {
@Override
public void resolve() {
CardList lands = tisLand.getController().getCardsIn(ZoneType.Battlefield);
lands = lands.filter(CardPredicates.LANDS);
lands = lands.filter(Presets.LANDS);
for (final Card land : lands) {
land.tap();
}

View File

@@ -89,43 +89,43 @@ public final class SEditorUtil {
view.getLblTotal().setText(String.valueOf(deck.countAll()));
view.getLblCreature().setText(String.valueOf(CardRules.Predicates.Presets
.IS_CREATURE.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_CREATURE.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblLand().setText(String.valueOf(CardRules.Predicates.Presets
.IS_LAND.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_LAND.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblEnchantment().setText(String.valueOf(CardRules.Predicates.Presets
.IS_ENCHANTMENT.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_ENCHANTMENT.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblArtifact().setText(String.valueOf(CardRules.Predicates.Presets
.IS_ARTIFACT.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_ARTIFACT.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblInstant().setText(String.valueOf(CardRules.Predicates.Presets
.IS_INSTANT.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_INSTANT.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblSorcery().setText(String.valueOf(CardRules.Predicates.Presets
.IS_SORCERY.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_SORCERY.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblPlaneswalker().setText(String.valueOf(CardRules.Predicates.Presets
.IS_PLANESWALKER.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_PLANESWALKER.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblColorless().setText(String.valueOf(CardRules.Predicates.Presets
.IS_COLORLESS.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_COLORLESS.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblBlack().setText(String.valueOf(CardRules.Predicates.Presets
.IS_BLACK.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_BLACK.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblBlue().setText(String.valueOf(CardRules.Predicates.Presets
.IS_BLUE.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_BLUE.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblGreen().setText(String.valueOf(CardRules.Predicates.Presets
.IS_GREEN.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_GREEN.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblRed().setText(String.valueOf(CardRules.Predicates.Presets
.IS_RED.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_RED.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblWhite().setText(String.valueOf(CardRules.Predicates.Presets
.IS_WHITE.aggregate(deck, deck.getFnToCard(), deck.getFnToCount())));
.IS_WHITE.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
} // getStats()
/**

View File

@@ -70,81 +70,81 @@ public enum CStatistics implements ICDoc {
if (total == 0) { total = 1; }
tmp = CardRules.Predicates.Presets.IS_MULTICOLOR
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblMulti().setText(String.valueOf(tmp));
tmp = CardRules.Predicates.Presets.IS_CREATURE
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblCreature().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_LAND
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblLand().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_ENCHANTMENT
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblEnchantment().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_ARTIFACT
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblArtifact().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_INSTANT
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblInstant().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_SORCERY
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblSorcery().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_PLANESWALKER
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblPlaneswalker().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_COLORLESS
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblColorless().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = Predicate.and(
Predicates.isColor(CardColor.BLACK),
Predicates.hasCntColors((byte) 1))
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblBlack().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = Predicate.and(
Predicates.isColor(CardColor.BLUE),
Predicates.hasCntColors((byte) 1))
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblBlue().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = Predicate.and(
Predicates.isColor(CardColor.GREEN),
Predicates.hasCntColors((byte) 1))
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblGreen().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = Predicate.and(
Predicates.isColor(CardColor.RED),
Predicates.hasCntColors((byte) 1))
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblRed().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = Predicate.and(
Predicates.isColor(CardColor.WHITE),
Predicates.hasCntColors((byte) 1))
.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblWhite().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");

View File

@@ -33,7 +33,7 @@ import javax.swing.SwingWorker;
import forge.AllZone;
import forge.Card;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Command;
import forge.Constant;
import forge.Singletons;
@@ -149,7 +149,7 @@ public enum CDock implements ICDoc {
Player human = AllZone.getHumanPlayer();
if (ph.is(PhaseType.COMBAT_DECLARE_ATTACKERS, human)) {
for(Card c : human.getCardsIn(ZoneType.Battlefield).filter(CardPredicates.CREATURES)) {
for(Card c : human.getCardsIn(ZoneType.Battlefield).filter(Presets.CREATURES)) {
if (!c.isAttacking() && CombatUtil.canAttack(c, AllZone.getCombat())) {
AllZone.getCombat().addAttacker(c);
}

View File

@@ -539,7 +539,7 @@ public abstract class Predicate<T> {
* the value accessor
* @return the int
*/
public final <U> int aggregate(final Iterable<U> source, final Lambda1<T, U> accessor,
public final <U> int sum(final Iterable<U> source, final Lambda1<T, U> accessor,
final Lambda1<Integer, U> valueAccessor) {
int result = 0;
if (source != null) {
@@ -552,6 +552,38 @@ public abstract class Predicate<T> {
return result;
}
public final int sum(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
int result = 0;
if (source != null) {
for (final T c : source) {
if (this.isTrue(c)) {
result += valueAccessor.apply(c);
}
}
}
return result;
}
// Returns the element matching predicate conditions with the maximum value of whatever valueAccessor returns.
public final T max(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
if (source == null) { return null; }
T result = null;
int max = Integer.MIN_VALUE;
for (final T c : source) {
if (!this.isTrue(c)) { continue; }
int value = valueAccessor.apply(c);
if ( value > max ) {
result = c;
max = value;
}
}
return result;
}
// Random - algorithm adapted from Braid's GeneratorFunctions
/**
* Random.

View File

@@ -28,15 +28,14 @@ import org.apache.commons.lang3.StringUtils;
public abstract class PredicateString<T> extends Predicate<T> {
/** Possible operators for string operands. */
public enum StringOp {
/** The CONTAINS. */
CONTAINS,
/** The NO t_ contains. */
NOT_CONTAINS,
/** The CONTAINS ignore case. */
CONTAINS_IC,
/** The EQUALS. */
EQUALS,
/** The NO t_ equals. */
NOT_EQUALS
/** The EQUALS. */
EQUALS_IC
}
/** The operator. */
@@ -53,13 +52,13 @@ public abstract class PredicateString<T> extends Predicate<T> {
*/
protected final boolean op(final String op1, final String op2) {
switch (this.getOperator()) {
case CONTAINS:
case CONTAINS_IC:
return StringUtils.containsIgnoreCase(op1, op2);
case NOT_CONTAINS:
return !StringUtils.containsIgnoreCase(op1, op2);
case CONTAINS:
return StringUtils.contains(op1, op2);
case EQUALS:
return op1.equalsIgnoreCase(op2);
case NOT_EQUALS:
return op1.equals(op2);
case EQUALS_IC:
return op1.equalsIgnoreCase(op2);
default:
return false;
@@ -82,4 +81,38 @@ public abstract class PredicateString<T> extends Predicate<T> {
public StringOp getOperator() {
return operator;
}
public static PredicateString<String> contains(final String what) {
return new PredicateString<String>(StringOp.CONTAINS) {
@Override
public boolean isTrue(String subject) {
return op(subject, what);
}
};
}
public static PredicateString<String> containsIgnoreCase(final String what) {
return new PredicateString<String>(StringOp.CONTAINS_IC) {
@Override
public boolean isTrue(String subject) {
return op(subject, what);
}
};
}
public static PredicateString<String> equals(final String what) {
return new PredicateString<String>(StringOp.EQUALS) {
@Override
public boolean isTrue(String subject) {
return op(subject, what);
}
};
}
public static PredicateString<String> equalsIgnoreCase(final String what) {
return new PredicateString<String>(StringOp.EQUALS_IC) {
@Override
public boolean isTrue(String subject) {
return op(subject, what);
}
};
}
}