mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
more specific methods removed from CardList
This commit is contained in:
@@ -1789,7 +1789,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
j--;
|
||||
}
|
||||
|
||||
colors.addToCardColor(cc.toStringArray());
|
||||
colors.addToCardColor(cc);
|
||||
if (!cc.getAdditional()) {
|
||||
return colors;
|
||||
}
|
||||
@@ -1797,7 +1797,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
while (i >= 0) {
|
||||
final CardColor cc = this.getCharacteristics().getCardColor().get(i);
|
||||
i--;
|
||||
colors.addToCardColor(cc.toStringArray());
|
||||
colors.addToCardColor(cc);
|
||||
if (!cc.getAdditional()) {
|
||||
return colors;
|
||||
}
|
||||
@@ -1805,7 +1805,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
while (j >= 0) {
|
||||
final CardColor cc = globalChanges.get(j);
|
||||
j--;
|
||||
colors.addToCardColor(cc.toStringArray());
|
||||
colors.addToCardColor(cc);
|
||||
if (!cc.getAdditional()) {
|
||||
return colors;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
*/
|
||||
package forge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import forge.card.mana.ManaCost;
|
||||
|
||||
@@ -29,7 +32,15 @@ import forge.card.mana.ManaCost;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CardColor {
|
||||
public class CardColor implements Iterable<Color>{
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Iterable#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Color> iterator() {
|
||||
return col.iterator();
|
||||
}
|
||||
|
||||
// takes care of individual card color, for global color change effects use
|
||||
// AllZone.getGameInfo().getColorChanges()
|
||||
private final EnumSet<Color> col;
|
||||
@@ -134,6 +145,14 @@ public class CardColor {
|
||||
}
|
||||
}
|
||||
|
||||
public final void addToCardColor(final Iterable<Color> cc) {
|
||||
for( Color c : cc ) {
|
||||
if (!this.col.contains(c)) {
|
||||
this.col.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* fixColorless.
|
||||
@@ -188,4 +207,12 @@ public class CardColor {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public final List<String> toStringList() {
|
||||
final List<String> list = new ArrayList<String>(this.col.size());
|
||||
for (final Color c : this.col) {
|
||||
list.add(c.toString());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.game.phase.CombatUtil;
|
||||
import forge.game.player.Player;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.closures.Predicate;
|
||||
@@ -58,9 +57,6 @@ public class CardList extends ArrayList<Card> {
|
||||
this.add(c);
|
||||
}
|
||||
|
||||
public final void sort(final Comparator<Card> c) {
|
||||
Collections.sort(this, c);
|
||||
}
|
||||
/**
|
||||
* <p>
|
||||
* toArray.
|
||||
@@ -68,6 +64,7 @@ public class CardList extends ArrayList<Card> {
|
||||
*
|
||||
* @return an array of {@link forge.Card} objects.
|
||||
*/
|
||||
@Override
|
||||
public final Card[] toArray() {
|
||||
final Card[] c = new Card[this.size()];
|
||||
this.toArray(c);
|
||||
@@ -230,22 +227,8 @@ public class CardList extends ArrayList<Card> {
|
||||
return this.filter(CardPredicates.isTargetableBy(source));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getUnprotectedCards.
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* a {@link forge.Card} object.
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList getUnprotectedCards(final Card source) {
|
||||
return this.filter(new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(final Card c) {
|
||||
return !c.hasProtectionFrom(source);
|
||||
}
|
||||
});
|
||||
return this.filter(Predicate.not(CardPredicates.isProtectedFrom(source)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,91 +270,6 @@ public class CardList extends ArrayList<Card> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getPossibleAttackers.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList getPossibleAttackers() {
|
||||
return this.filter(new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(final Card c) {
|
||||
return (c.isCreature() && CombatUtil.canAttack(c));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getHighestConvertedManaCost.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public final int getHighestConvertedManaCost() {
|
||||
int total = 0;
|
||||
for (int i = 0; i < this.size(); i++) {
|
||||
total = Math.max(total, this.get(i).getCMC());
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getColored.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList getColored() {
|
||||
return this.filter(new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(final Card c) {
|
||||
return (!c.isColorless());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getMonoColored.
|
||||
* </p>
|
||||
* @param includeColorless should colorless cards be included?
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList getMonoColored(final boolean includeColorless) {
|
||||
return this.filter(new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(final Card c) {
|
||||
return (CardUtil.getColors(c).size() == 1 && (includeColorless || !c.isColorless()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <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()
|
||||
|
||||
|
||||
} // end class CardList
|
||||
|
||||
@@ -17,11 +17,9 @@
|
||||
*/
|
||||
package forge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
||||
import forge.card.cardfactory.CardFactoryUtil;
|
||||
import forge.util.closures.Predicate;
|
||||
|
||||
@@ -74,20 +72,34 @@ public class CardListUtil {
|
||||
return CardFactoryUtil.evaluateCreature(b) - CardFactoryUtil.evaluateCreature(a);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sorts a CardList by toughness, putting highest toughness first.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortDefense(final CardList list) {
|
||||
list.sort(DefenseComparator);
|
||||
} // sortDefense()
|
||||
|
||||
public static final Comparator<Card> CmcComparator = new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(final Card a, final Card b) {
|
||||
return b.getCMC() - a.getCMC();
|
||||
}
|
||||
};
|
||||
|
||||
public static final Comparator<Card> TextLenReverseComparator = new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(final Card a, final Card b) {
|
||||
final int aLen = a.getText().length();
|
||||
final int bLen = b.getText().length();
|
||||
return aLen - bLen;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Comparator<Card> getKeywordComparator(final String kw) {
|
||||
return new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(final Card a, final Card b) {
|
||||
int aV = a.hasKeyword(kw) ? 1 : 0;
|
||||
int bV = b.hasKeyword(kw) ? 1 : 0;
|
||||
return bV - aV;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// the higher the attack the better
|
||||
/**
|
||||
* <p>
|
||||
@@ -98,8 +110,7 @@ public class CardListUtil {
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortAttack(final CardList list) {
|
||||
|
||||
list.sort(AttackComparator);
|
||||
Collections.sort(list, AttackComparator);
|
||||
} // sortAttack()
|
||||
|
||||
/**
|
||||
@@ -112,7 +123,7 @@ public class CardListUtil {
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByEvaluateCreature(final CardList list) {
|
||||
list.sort(EvaluateCreatureComparator);
|
||||
Collections.sort(list, EvaluateCreatureComparator);
|
||||
} // sortByEvaluateCreature()
|
||||
|
||||
/**
|
||||
@@ -124,13 +135,7 @@ public class CardListUtil {
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByMostExpensive(final CardList list) {
|
||||
final Comparator<Card> com = new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(final Card a, final Card b) {
|
||||
return b.getCMC() - a.getCMC();
|
||||
}
|
||||
};
|
||||
list.sort(com);
|
||||
Collections.sort(list, CmcComparator);
|
||||
} // sortByMostExpensive()
|
||||
|
||||
// the lower the attack the better
|
||||
@@ -143,13 +148,7 @@ public class CardListUtil {
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortAttackLowFirst(final CardList list) {
|
||||
final Comparator<Card> com = new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(final Card a, final Card b) {
|
||||
return a.getNetCombatDamage() - b.getNetCombatDamage();
|
||||
}
|
||||
};
|
||||
list.sort(com);
|
||||
Collections.sort(list, Collections.reverseOrder(AttackComparator));
|
||||
} // sortAttackLowFirst()
|
||||
|
||||
/**
|
||||
@@ -174,114 +173,9 @@ public class CardListUtil {
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortFlying(final CardList list) {
|
||||
sortByKeyword(list, "Flying");
|
||||
Collections.sort(list, getKeywordComparator("Flying"));
|
||||
} // sortFlying()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* sortByKeyword.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
* @param kw
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public static void sortByKeyword(final CardList list, final String kw) {
|
||||
final String keyword = kw;
|
||||
final Comparator<Card> com = new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(final Card a, final Card b) {
|
||||
if (a.hasKeyword(keyword) && b.hasKeyword(keyword)) {
|
||||
return 0;
|
||||
} else if (a.hasKeyword(keyword)) {
|
||||
return -1;
|
||||
} else if (b.hasKeyword(keyword)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
list.sort(com);
|
||||
} // sortByKeyword()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* sortByDestroyEffect.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByDestroyEffect(final CardList list) {
|
||||
final Comparator<Card> com = new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(final Card a, final Card b) {
|
||||
final ArrayList<String> aKeywords = a.getKeyword();
|
||||
final ArrayList<String> bKeywords = b.getKeyword();
|
||||
|
||||
boolean aContains = false;
|
||||
boolean bContains = false;
|
||||
|
||||
for (final String kw : aKeywords) {
|
||||
if (kw.startsWith("Whenever") && kw.contains("into a graveyard from the battlefield,")) {
|
||||
aContains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (final String kw : bKeywords) {
|
||||
if (kw.startsWith("Whenever") && kw.contains("into a graveyard from the battlefield,")) {
|
||||
bContains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (aContains && bContains) {
|
||||
return 0;
|
||||
} else if (aContains) {
|
||||
return 1;
|
||||
} else if (bContains) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
list.sort(com);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* sortByTextLen.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByTextLen(final CardList list) {
|
||||
final Comparator<Card> com = new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(final Card a, final Card b) {
|
||||
final int aLen = a.getText().length();
|
||||
final int bLen = b.getText().length();
|
||||
|
||||
if (aLen == bLen) {
|
||||
return 0;
|
||||
} else if (aLen > bLen) {
|
||||
return 1;
|
||||
} else if (bLen > aLen) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
list.sort(com);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sorts a CardList from highest converted mana cost to lowest.
|
||||
@@ -291,26 +185,7 @@ public class CardListUtil {
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortCMC(final CardList list) {
|
||||
final Comparator<Card> com = new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(final Card a, final Card b) {
|
||||
final int cmcA = a.getManaCost().getCMC();
|
||||
final int cmcB = b.getManaCost().getCMC();
|
||||
|
||||
if (cmcA == cmcB) {
|
||||
return 0;
|
||||
}
|
||||
if (cmcA > cmcB) {
|
||||
return -1;
|
||||
}
|
||||
if (cmcB > cmcA) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
list.sort(com);
|
||||
Collections.sort( list, CmcComparator );
|
||||
} // sortCMC
|
||||
|
||||
/**
|
||||
@@ -351,72 +226,6 @@ public class CardListUtil {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* sumAttack.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.CardList} object.
|
||||
* @return a int.
|
||||
*/
|
||||
public static int sumAttack(final CardList c) {
|
||||
int attack = 0;
|
||||
|
||||
for (int i = 0; i < c.size(); i++) {
|
||||
// if(c.get(i).isCreature() && c.get(i).hasSecondStrike()) {
|
||||
if (c.get(i).isCreature()
|
||||
&& (!c.get(i).hasFirstStrike() || (c.get(i).hasDoubleStrike() && c.get(i).hasFirstStrike()))) {
|
||||
attack += c.get(i).getNetCombatDamage();
|
||||
}
|
||||
}
|
||||
// System.out.println("Total attack: " +attack);
|
||||
return attack;
|
||||
} // sumAttack()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* sumDefense.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.CardList} object.
|
||||
* @return a int.
|
||||
*/
|
||||
public static int sumDefense(final CardList c) {
|
||||
int defense = 0;
|
||||
|
||||
for (int i = 0; i < c.size(); i++) {
|
||||
// if(c.get(i).isCreature() && c.get(i).hasSecondStrike()) {
|
||||
if (c.get(i).isCreature()) {
|
||||
defense += c.get(i).getNetDefense();
|
||||
}
|
||||
}
|
||||
// System.out.println("Total attack: " +attack);
|
||||
return defense;
|
||||
} // sumAttack()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* sumFirstStrikeAttack.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.CardList} object.
|
||||
* @return a int.
|
||||
*/
|
||||
public static int sumFirstStrikeAttack(final CardList c) {
|
||||
int attack = 0;
|
||||
|
||||
for (int i = 0; i < c.size(); i++) {
|
||||
if (c.get(i).isCreature() && (c.get(i).hasFirstStrike() || c.get(i).hasDoubleStrike())) {
|
||||
attack += c.get(i).getNetCombatDamage();
|
||||
}
|
||||
}
|
||||
Log.debug("Total First Strike attack: " + attack);
|
||||
return attack;
|
||||
} // sumFirstStrikeAttack()
|
||||
|
||||
// Get the total converted mana cost of a card list
|
||||
/**
|
||||
* <p>
|
||||
@@ -428,15 +237,7 @@ public class CardListUtil {
|
||||
* @return a int.
|
||||
*/
|
||||
public static int sumCMC(final CardList c) {
|
||||
int cmc = 0;
|
||||
|
||||
for (int i = 0; i < c.size(); i++) {
|
||||
cmc += c.get(i).getManaCost().getCMC();
|
||||
}
|
||||
// System.out.println("Total CMC: " +cmc);
|
||||
|
||||
return cmc;
|
||||
|
||||
return CardPredicates.Presets.All.sum(c, CardPredicates.Accessors.fnGetCmc);
|
||||
} // sumCMC
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ package forge;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.game.phase.CombatUtil;
|
||||
import forge.game.player.Player;
|
||||
import forge.util.closures.Lambda1;
|
||||
import forge.util.closures.Predicate;
|
||||
import forge.util.closures.PredicateString;
|
||||
|
||||
@@ -104,13 +105,30 @@ public final class CardPredicates {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static final Predicate<Card> possibleAttackers = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(final Card c) {
|
||||
return (c.isCreature() && CombatUtil.canAttack(c));
|
||||
}
|
||||
};
|
||||
|
||||
public static Predicate<Card> isProtectedFrom(final Card source) {
|
||||
return new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(final Card c) {
|
||||
return !c.hasProtectionFrom(source);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static class Presets {
|
||||
|
||||
/**
|
||||
* a Predicate<Card> to get all cards that are tapped.
|
||||
*/
|
||||
public static Predicate<Card> TAPPED = new Predicate<Card>() {
|
||||
public static final Predicate<Card> TAPPED = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isTapped();
|
||||
@@ -119,7 +137,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all cards that are untapped.
|
||||
*/
|
||||
public static Predicate<Card> UNTAPPED = new Predicate<Card>() {
|
||||
public static final Predicate<Card> UNTAPPED = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isUntapped();
|
||||
@@ -128,7 +146,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all creatures.
|
||||
*/
|
||||
public static Predicate<Card> CREATURES = new Predicate<Card>() {
|
||||
public static final Predicate<Card> CREATURES = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isCreature();
|
||||
@@ -137,7 +155,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all enchantments.
|
||||
*/
|
||||
public static Predicate<Card> ENCHANTMENTS = new Predicate<Card>() {
|
||||
public static final Predicate<Card> ENCHANTMENTS = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isEnchantment();
|
||||
@@ -146,7 +164,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all equipment.
|
||||
*/
|
||||
public static Predicate<Card> EQUIPMENT = new Predicate<Card>() {
|
||||
public static final Predicate<Card> EQUIPMENT = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isEquipment();
|
||||
@@ -155,7 +173,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all unenchanted cards in a list.
|
||||
*/
|
||||
public static Predicate<Card> UNENCHANTED = new Predicate<Card>() {
|
||||
public static final Predicate<Card> UNENCHANTED = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return !c.isEnchanted();
|
||||
@@ -164,7 +182,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all enchanted cards in a list.
|
||||
*/
|
||||
public static Predicate<Card> ENCHANTED = new Predicate<Card>() {
|
||||
public static final Predicate<Card> ENCHANTED = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isEnchanted();
|
||||
@@ -173,7 +191,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all nontoken cards.
|
||||
*/
|
||||
public static Predicate<Card> NON_TOKEN = new Predicate<Card>() {
|
||||
public static final Predicate<Card> NON_TOKEN = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return !c.isToken();
|
||||
@@ -182,7 +200,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all token cards.
|
||||
*/
|
||||
public static Predicate<Card> TOKEN = new Predicate<Card>() {
|
||||
public static final Predicate<Card> TOKEN = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isToken();
|
||||
@@ -191,7 +209,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all nonbasic lands.
|
||||
*/
|
||||
public static Predicate<Card> NON_BASIC_LAND = new Predicate<Card>() {
|
||||
public static final Predicate<Card> NON_BASIC_LAND = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return !c.isBasicLand();
|
||||
@@ -200,7 +218,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all basicLands.
|
||||
*/
|
||||
public static Predicate<Card> BASIC_LANDS = new Predicate<Card>() {
|
||||
public static final Predicate<Card> BASIC_LANDS = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
// the isBasicLand() check here may be sufficient...
|
||||
@@ -210,7 +228,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all artifacts.
|
||||
*/
|
||||
public static Predicate<Card> ARTIFACTS = new Predicate<Card>() {
|
||||
public static final Predicate<Card> ARTIFACTS = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isArtifact();
|
||||
@@ -219,7 +237,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all nonartifacts.
|
||||
*/
|
||||
public static Predicate<Card> NON_ARTIFACTS = new Predicate<Card>() {
|
||||
public static final Predicate<Card> NON_ARTIFACTS = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return !c.isArtifact();
|
||||
@@ -228,7 +246,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all lands.
|
||||
*/
|
||||
public static Predicate<Card> LANDS = new Predicate<Card>() {
|
||||
public static final Predicate<Card> LANDS = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isLand();
|
||||
@@ -237,7 +255,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all nonlands.
|
||||
*/
|
||||
public static Predicate<Card> NON_LANDS = new Predicate<Card>() {
|
||||
public static final Predicate<Card> NON_LANDS = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return !c.isLand();
|
||||
@@ -246,7 +264,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all cards that are black.
|
||||
*/
|
||||
public static Predicate<Card> BLACK = new Predicate<Card>() {
|
||||
public static final Predicate<Card> BLACK = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isBlack();
|
||||
@@ -255,7 +273,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all cards that are blue.
|
||||
*/
|
||||
public static Predicate<Card> BLUE = new Predicate<Card>() {
|
||||
public static final Predicate<Card> BLUE = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isBlue();
|
||||
@@ -264,7 +282,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all cards that are green.
|
||||
*/
|
||||
public static Predicate<Card> GREEN = new Predicate<Card>() {
|
||||
public static final Predicate<Card> GREEN = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isGreen();
|
||||
@@ -273,7 +291,7 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all cards that are red.
|
||||
*/
|
||||
public static Predicate<Card> RED = new Predicate<Card>() {
|
||||
public static final Predicate<Card> RED = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isRed();
|
||||
@@ -282,13 +300,51 @@ public final class CardPredicates {
|
||||
/**
|
||||
* a Predicate<Card> to get all cards that are white.
|
||||
*/
|
||||
public static Predicate<Card> WHITE = new Predicate<Card>() {
|
||||
public static final Predicate<Card> WHITE = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isWhite();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public static final Predicate<Card> hasFirstStrike = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isCreature() && (c.hasFirstStrike() || c.hasDoubleStrike());
|
||||
}
|
||||
};
|
||||
public static final Predicate<Card> hasSecondStrike = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(Card c) {
|
||||
return c.isCreature() && (!c.hasFirstStrike() || c.hasDoubleStrike());
|
||||
}
|
||||
};
|
||||
public static final Predicate<Card> All = Predicate.getTrue(Card.class);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class Accessors {
|
||||
public static final Lambda1<Integer, Card> fnGetDefense = new Lambda1<Integer, Card>() {
|
||||
@Override
|
||||
public Integer apply(Card a) {
|
||||
return a.getNetDefense();
|
||||
}
|
||||
};
|
||||
|
||||
public static final Lambda1<Integer, Card> fnGetAttack = new Lambda1<Integer, Card>() {
|
||||
@Override
|
||||
public Integer apply(Card a) {
|
||||
return a.getNetCombatDamage();
|
||||
}
|
||||
};
|
||||
|
||||
public static final Lambda1<Integer, Card> fnGetCmc = new Lambda1<Integer, Card>() {
|
||||
@Override
|
||||
public Integer apply(Card a) {
|
||||
return a.getCMC();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package forge;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -134,7 +133,7 @@ public final class CardUtil {
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static List<String> getColors(final Card c) {
|
||||
return Arrays.asList(c.determineColor().toStringArray());
|
||||
return c.determineColor().toStringList();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -807,7 +806,7 @@ public final class CardUtil {
|
||||
final CardList res = new CardList();
|
||||
|
||||
for (final CardColor col : origin.getColor()) {
|
||||
for (final String strCol : col.toStringArray()) {
|
||||
for (final String strCol : col.toStringList()) {
|
||||
if (strCol.equalsIgnoreCase("Colorless")) {
|
||||
continue;
|
||||
}
|
||||
@@ -838,7 +837,7 @@ public final class CardUtil {
|
||||
usableColors.add("colorless");
|
||||
}
|
||||
for (final CardColor col : cardToConvoke.getColor()) {
|
||||
for (final String strCol : col.toStringArray()) {
|
||||
for (final String strCol : col.toStringList()) {
|
||||
if (strCol.equals("colorless")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -329,7 +329,8 @@ public class AbilityFactoryPump {
|
||||
|| ph.getPhase().isBefore(PhaseType.MAIN1)) {
|
||||
return false;
|
||||
}
|
||||
CardList attackers = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).getPossibleAttackers();
|
||||
|
||||
CardList attackers = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).filter(CardPredicates.possibleAttackers);
|
||||
if(!CombatUtil.canBlockAtLeastOne(card, attackers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package forge.card.abilityfactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
@@ -1402,8 +1403,7 @@ public class AbilityFactoryZoneAffecting {
|
||||
}
|
||||
}
|
||||
|
||||
CardListUtil.sortByTextLen(dPChHand);
|
||||
dChoices.add(dPChHand.get(0));
|
||||
Collections.sort(dPChHand, CardListUtil.TextLenReverseComparator);
|
||||
|
||||
CardListUtil.sortCMC(dPChHand);
|
||||
dChoices.add(dPChHand.get(0));
|
||||
|
||||
@@ -33,6 +33,7 @@ import forge.Card;
|
||||
import forge.CardCharacteristicName;
|
||||
import forge.CardList;
|
||||
import forge.CardListUtil;
|
||||
import forge.CardPredicates;
|
||||
import forge.CardPredicates.Presets;
|
||||
import forge.CardUtil;
|
||||
import forge.Command;
|
||||
@@ -2477,7 +2478,7 @@ public class CardFactoryUtil {
|
||||
list.add(AllZoneUtil.getCardState((Card) o));
|
||||
}
|
||||
}
|
||||
return CardListUtil.sumAttack(list);
|
||||
return CardPredicates.Presets.hasSecondStrike.sum(list, CardPredicates.Accessors.fnGetAttack);
|
||||
}
|
||||
|
||||
if (l[0].contains("RememberedSize")) {
|
||||
@@ -2567,7 +2568,7 @@ public class CardFactoryUtil {
|
||||
final String[] colors = { "green", "white", "red", "blue", "black" };
|
||||
|
||||
for (final String color : colors) {
|
||||
if (someCards.getColor(color).size() > 0) {
|
||||
if (!CardListUtil.getColor(someCards, color).isEmpty()) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
@@ -3033,16 +3034,7 @@ public class CardFactoryUtil {
|
||||
|
||||
// "Clerics you control" - Count$TypeYouCtrl.Cleric
|
||||
if (sq[0].contains("Type")) {
|
||||
someCards = someCards.filter(new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(final Card c) {
|
||||
if (c.isType(sq[1])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
someCards = someCards.filter(CardPredicates.isType(sq[1]));
|
||||
}
|
||||
|
||||
// "Named <CARDNAME> in all graveyards" - Count$NamedAllYards.<CARDNAME>
|
||||
@@ -3051,17 +3043,7 @@ public class CardFactoryUtil {
|
||||
if (sq[1].equals("CARDNAME")) {
|
||||
sq[1] = c.getName();
|
||||
}
|
||||
|
||||
someCards = someCards.filter(new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean isTrue(final Card c) {
|
||||
if (c.getName().equals(sq[1])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
someCards = someCards.filter(CardPredicates.nameEquals(sq[1]));
|
||||
}
|
||||
|
||||
// Refined qualities
|
||||
|
||||
@@ -27,14 +27,12 @@ import forge.AllZoneUtil;
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
import forge.CardListUtil;
|
||||
import forge.Constant;
|
||||
import forge.Counters;
|
||||
import forge.CardPredicates;
|
||||
import forge.CardPredicates.Presets;
|
||||
import forge.CardUtil;
|
||||
import forge.GameActionUtil;
|
||||
import forge.Singletons;
|
||||
import forge.card.abilityfactory.AbilityFactory;
|
||||
import forge.card.abilityfactory.AbilityFactoryMana;
|
||||
import forge.card.cardfactory.CardFactoryUtil;
|
||||
import forge.card.cost.Cost;
|
||||
import forge.card.cost.CostMana;
|
||||
@@ -1329,14 +1327,15 @@ public class ComputerUtil {
|
||||
// don't play the land if it has cycling and enough lands are
|
||||
// available
|
||||
final ArrayList<SpellAbility> spellAbilities = c.getSpellAbilities();
|
||||
|
||||
final CardList hand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand);
|
||||
CardList lands = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
|
||||
lands.addAll(hand);
|
||||
lands = lands.getType("Land");
|
||||
int maxCmcInHand = Predicate.getTrue(Card.class).max(hand, CardPredicates.Accessors.fnGetCmc);
|
||||
for (final SpellAbility sa : spellAbilities) {
|
||||
if (sa.isCycling()) {
|
||||
final CardList hand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand);
|
||||
CardList lands = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
|
||||
lands.addAll(hand);
|
||||
lands = lands.getType("Land");
|
||||
|
||||
if (lands.size() >= Math.max(hand.getHighestConvertedManaCost(), 6)) {
|
||||
if (lands.size() >= Math.max(maxCmcInHand, 6)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2208,7 +2207,7 @@ public class ComputerUtil {
|
||||
final CardList landsInPlay = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).getType("Land");
|
||||
final CardList landsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).getType("Land");
|
||||
final CardList nonLandsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).getNotType("Land");
|
||||
final int highestCMC = Math.max(6, nonLandsInHand.getHighestConvertedManaCost());
|
||||
final int highestCMC = Math.max(6, Predicate.getTrue(Card.class).max(nonLandsInHand, CardPredicates.Accessors.fnGetCmc));
|
||||
final int discardCMC = discard.getCMC();
|
||||
if (discard.isLand()) {
|
||||
if (landsInPlay.size() >= highestCMC
|
||||
|
||||
@@ -1396,7 +1396,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
||||
return result;
|
||||
}
|
||||
|
||||
public final CardList getCardsIn(final ZoneType[] zones) {
|
||||
public final CardList getCardsIn(final ZoneType... zones) {
|
||||
final CardList result = new CardList();
|
||||
for (final ZoneType z : zones) {
|
||||
if (this.getZone(z) != null) {
|
||||
|
||||
@@ -482,8 +482,23 @@ public abstract class Predicate<T> {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns the value matching predicate conditions with the maximum value of whatever valueAccessor returns.
|
||||
public final Integer max(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
|
||||
if (source == null) { return null; }
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (final T c : source) {
|
||||
if (!this.isTrue(c)) { continue; }
|
||||
|
||||
int value = valueAccessor.apply(c);
|
||||
if ( value > max ) {
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
public final T maxItem(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
|
||||
if (source == null) { return null; }
|
||||
|
||||
T result = null;
|
||||
|
||||
Reference in New Issue
Block a user