mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Guava migration - Inline Predicate varargs methods
This commit is contained in:
@@ -1390,9 +1390,11 @@ public class AiAttackController {
|
|||||||
boolean canTrampleOverDefenders = attacker.hasKeyword(Keyword.TRAMPLE) && attacker.getNetCombatDamage() > Aggregates.sum(validBlockers, Card::getNetToughness);
|
boolean canTrampleOverDefenders = attacker.hasKeyword(Keyword.TRAMPLE) && attacker.getNetCombatDamage() > Aggregates.sum(validBlockers, Card::getNetToughness);
|
||||||
|
|
||||||
// used to check that CanKillAllDangerous check makes sense in context where creatures with dangerous abilities are present
|
// used to check that CanKillAllDangerous check makes sense in context where creatures with dangerous abilities are present
|
||||||
boolean dangerousBlockersPresent = Iterables.any(validBlockers, Predicates.or(
|
boolean dangerousBlockersPresent = Iterables.any(validBlockers,
|
||||||
CardPredicates.hasKeyword(Keyword.WITHER), CardPredicates.hasKeyword(Keyword.INFECT),
|
CardPredicates.hasKeyword(Keyword.WITHER)
|
||||||
CardPredicates.hasKeyword(Keyword.LIFELINK)));
|
.or(CardPredicates.hasKeyword(Keyword.INFECT))
|
||||||
|
.or(CardPredicates.hasKeyword(Keyword.LIFELINK))
|
||||||
|
);
|
||||||
|
|
||||||
// total power of the defending creatures, used in predicting whether a gang block can kill the attacker
|
// total power of the defending creatures, used in predicting whether a gang block can kill the attacker
|
||||||
int defPower = CardLists.getTotalPower(validBlockers, true, false);
|
int defPower = CardLists.getTotalPower(validBlockers, true, false);
|
||||||
|
|||||||
@@ -1442,11 +1442,14 @@ public class SpecialCardAi {
|
|||||||
public static boolean consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
int loyalty = sa.getHostCard().getCounters(CounterEnumType.LOYALTY);
|
int loyalty = sa.getHostCard().getCounters(CounterEnumType.LOYALTY);
|
||||||
CardCollection creaturesToGet = CardLists.filter(ai.getCardsIn(ZoneType.Graveyard),
|
CardCollection creaturesToGet = CardLists.filter(ai.getCardsIn(ZoneType.Graveyard),
|
||||||
Predicates.and(CardPredicates.Presets.CREATURES, CardPredicates.lessCMC(loyalty - 1), card -> {
|
CardPredicates.Presets.CREATURES
|
||||||
final Card copy = CardCopyService.getLKICopy(card);
|
.and(CardPredicates.lessCMC(loyalty - 1))
|
||||||
ComputerUtilCard.applyStaticContPT(ai.getGame(), copy, null);
|
.and(card -> {
|
||||||
return copy.getNetToughness() > 0;
|
final Card copy = CardCopyService.getLKICopy(card);
|
||||||
}));
|
ComputerUtilCard.applyStaticContPT(ai.getGame(), copy, null);
|
||||||
|
return copy.getNetToughness() > 0;
|
||||||
|
})
|
||||||
|
);
|
||||||
CardLists.sortByCmcDesc(creaturesToGet);
|
CardLists.sortByCmcDesc(creaturesToGet);
|
||||||
|
|
||||||
if (creaturesToGet.isEmpty()) {
|
if (creaturesToGet.isEmpty()) {
|
||||||
|
|||||||
@@ -136,8 +136,11 @@ public class ChooseSourceAi extends SpellAbilityAi {
|
|||||||
if (!Iterables.isEmpty(options)) {
|
if (!Iterables.isEmpty(options)) {
|
||||||
List<Card> oppCreatures = CardLists.filter(options, Predicates.and(CardPredicates.Presets.CREATURES,
|
List<Card> oppCreatures = CardLists.filter(options, Predicates.and(CardPredicates.Presets.CREATURES,
|
||||||
Predicates.not(CardPredicates.isOwner(aiChoser))));
|
Predicates.not(CardPredicates.isOwner(aiChoser))));
|
||||||
List<Card> aiNonCreatures = CardLists.filter(options, Predicates.and(Predicates.not(CardPredicates.Presets.CREATURES),
|
List<Card> aiNonCreatures = CardLists.filter(options,
|
||||||
CardPredicates.Presets.PERMANENTS, CardPredicates.isOwner(aiChoser)));
|
Predicates.not(CardPredicates.Presets.CREATURES)
|
||||||
|
.and(CardPredicates.Presets.PERMANENTS)
|
||||||
|
.and(CardPredicates.isOwner(aiChoser))
|
||||||
|
);
|
||||||
|
|
||||||
if (!oppCreatures.isEmpty()) {
|
if (!oppCreatures.isEmpty()) {
|
||||||
return ComputerUtilCard.getBestCreatureAI(oppCreatures);
|
return ComputerUtilCard.getBestCreatureAI(oppCreatures);
|
||||||
|
|||||||
@@ -892,7 +892,11 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
|
|
||||||
// See if there's an indestructible target that can be used
|
// See if there's an indestructible target that can be used
|
||||||
CardCollection indestructible = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield),
|
CardCollection indestructible = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield),
|
||||||
Predicates.and(CardPredicates.Presets.CREATURES, CardPredicates.Presets.PLANESWALKERS, CardPredicates.hasKeyword(Keyword.INDESTRUCTIBLE), CardPredicates.isTargetableBy(sa)));
|
CardPredicates.Presets.CREATURES
|
||||||
|
.and(CardPredicates.Presets.PLANESWALKERS) //TODO: Should this be "or" Planeswalkers?
|
||||||
|
.and(CardPredicates.hasKeyword(Keyword.INDESTRUCTIBLE))
|
||||||
|
.and(CardPredicates.isTargetableBy(sa))
|
||||||
|
);
|
||||||
|
|
||||||
if (!indestructible.isEmpty()) {
|
if (!indestructible.isEmpty()) {
|
||||||
Card c = ComputerUtilCard.getWorstPermanentAI(indestructible, false, false, false, false);
|
Card c = ComputerUtilCard.getWorstPermanentAI(indestructible, false, false, false, false);
|
||||||
@@ -905,7 +909,7 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
}
|
}
|
||||||
else if (tgt.canTgtPlaneswalker()) {
|
else if (tgt.canTgtPlaneswalker()) {
|
||||||
// Second pass for planeswalkers: choose AI's worst planeswalker
|
// Second pass for planeswalkers: choose AI's worst planeswalker
|
||||||
final Card c = ComputerUtilCard.getWorstPlaneswalkerToDamage(CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), Predicates.and(CardPredicates.Presets.PLANESWALKERS), CardPredicates.isTargetableBy(sa)));
|
final Card c = ComputerUtilCard.getWorstPlaneswalkerToDamage(CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.PLANESWALKERS, CardPredicates.isTargetableBy(sa)));
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
sa.getTargets().add(c);
|
sa.getTargets().add(c);
|
||||||
if (divided) {
|
if (divided) {
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ public class MutateAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// Filter out some abilities that are useless
|
// Filter out some abilities that are useless
|
||||||
// TODO: add other stuff useless for Mutate here
|
// TODO: add other stuff useless for Mutate here
|
||||||
mutateTgts = CardLists.filter(mutateTgts, Predicates.not(Predicates.or(
|
mutateTgts = CardLists.filter(mutateTgts, Predicates.not(
|
||||||
CardPredicates.hasKeyword(Keyword.DEFENDER),
|
CardPredicates.hasKeyword(Keyword.DEFENDER)
|
||||||
CardPredicates.hasKeyword("CARDNAME can't attack."),
|
.or(CardPredicates.hasKeyword("CARDNAME can't attack."))
|
||||||
CardPredicates.hasKeyword("CARDNAME can't block."),
|
.or(CardPredicates.hasKeyword("CARDNAME can't block."))
|
||||||
card -> ComputerUtilCard.isUselessCreature(aiPlayer, card)
|
.or(card -> ComputerUtilCard.isUselessCreature(aiPlayer, card))
|
||||||
)));
|
));
|
||||||
|
|
||||||
if (mutateTgts.isEmpty()) {
|
if (mutateTgts.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -584,9 +584,12 @@ public final class CardRulesPredicates {
|
|||||||
Predicates.or(Presets.IS_CREATURE, Presets.IS_PLANESWALKER));
|
Predicates.or(Presets.IS_CREATURE, Presets.IS_PLANESWALKER));
|
||||||
|
|
||||||
/** The Constant IS_NON_CREATURE_SPELL. **/
|
/** The Constant IS_NON_CREATURE_SPELL. **/
|
||||||
public static final Predicate<CardRules> IS_NON_CREATURE_SPELL = Predicates
|
public static final Predicate<CardRules> IS_NON_CREATURE_SPELL =
|
||||||
.or(Presets.IS_SORCERY, Presets.IS_INSTANT, Presets.IS_PLANESWALKER, Presets.IS_ENCHANTMENT,
|
Presets.IS_SORCERY
|
||||||
Predicates.and(Presets.IS_ARTIFACT, Predicates.not(Presets.IS_CREATURE)));
|
.or(Presets.IS_INSTANT)
|
||||||
|
.or(Presets.IS_PLANESWALKER)
|
||||||
|
.or(Presets.IS_ENCHANTMENT) //TODO: Battles? Is testing these one by one really the best way to check "non-creature"?
|
||||||
|
.or(Presets.IS_ARTIFACT.and(Presets.IS_CREATURE.negate()));
|
||||||
|
|
||||||
/** The Constant isWhite. */
|
/** The Constant isWhite. */
|
||||||
public static final Predicate<CardRules> IS_WHITE = CardRulesPredicates.isColor(MagicColor.WHITE);
|
public static final Predicate<CardRules> IS_WHITE = CardRulesPredicates.isColor(MagicColor.WHITE);
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ public abstract class DeckGeneratorBase {
|
|||||||
if (useArtifacts) {
|
if (useArtifacts) {
|
||||||
hasColor = Predicates.or(hasColor, COLORLESS_CARDS);
|
hasColor = Predicates.or(hasColor, COLORLESS_CARDS);
|
||||||
}
|
}
|
||||||
return Iterables.filter(pool.getAllCards(), Predicates.compose(Predicates.and(canPlay, hasColor, canUseInFormat), PaperCard::getRules));
|
return Iterables.filter(pool.getAllCards(), Predicates.compose(canPlay.and(hasColor).and(canUseInFormat), PaperCard::getRules));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Map<String, Integer> countLands(ItemPool<PaperCard> outList) {
|
protected static Map<String, Integer> countLands(ItemPool<PaperCard> outList) {
|
||||||
@@ -390,7 +390,7 @@ public abstract class DeckGeneratorBase {
|
|||||||
Predicate<CardRules> dualLandFilter = CardRulesPredicates.coreType(true, CardType.CoreType.Land);
|
Predicate<CardRules> dualLandFilter = CardRulesPredicates.coreType(true, CardType.CoreType.Land);
|
||||||
Predicate<CardRules> exceptBasicLand = Predicates.not(CardRulesPredicates.Presets.IS_BASIC_LAND);
|
Predicate<CardRules> exceptBasicLand = Predicates.not(CardRulesPredicates.Presets.IS_BASIC_LAND);
|
||||||
|
|
||||||
Iterable<PaperCard> landCards = pool.getAllCards(Predicates.compose(Predicates.and(dualLandFilter, exceptBasicLand, canPlay), PaperCard::getRules));
|
Iterable<PaperCard> landCards = pool.getAllCards(Predicates.compose(dualLandFilter.and(exceptBasicLand).and(canPlay), PaperCard::getRules));
|
||||||
Iterable<String> dualLandPatterns = Arrays.asList("Add \\{([WUBRG])\\} or \\{([WUBRG])\\}",
|
Iterable<String> dualLandPatterns = Arrays.asList("Add \\{([WUBRG])\\} or \\{([WUBRG])\\}",
|
||||||
"Add \\{([WUBRG])\\}, \\{([WUBRG])\\}, or \\{([WUBRG])\\}",
|
"Add \\{([WUBRG])\\}, \\{([WUBRG])\\}, or \\{([WUBRG])\\}",
|
||||||
"Add \\{([WUBRG])\\}\\{([WUBRG])\\}",
|
"Add \\{([WUBRG])\\}\\{([WUBRG])\\}",
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ public abstract class ItemPredicate {
|
|||||||
*
|
*
|
||||||
* @return the predicate
|
* @return the predicate
|
||||||
*/
|
*/
|
||||||
public static final Predicate<InventoryItem> IsTournamentPack = card -> card instanceof TournamentPack && !((TournamentPack) card).isStarterDeck();
|
public static final Predicate<Object> IsTournamentPack = card -> card instanceof TournamentPack && !((TournamentPack) card).isStarterDeck();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that the inventory item is a Starter Deck.
|
* Checks that the inventory item is a Starter Deck.
|
||||||
*
|
*
|
||||||
* @return the predicate
|
* @return the predicate
|
||||||
*/
|
*/
|
||||||
public static final Predicate<InventoryItem> IsStarterDeck = card -> card instanceof TournamentPack && ((TournamentPack) card).isStarterDeck();
|
public static final Predicate<Object> IsStarterDeck = card -> card instanceof TournamentPack && ((TournamentPack) card).isStarterDeck();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that the inventory item is a Prebuilt Deck.
|
* Checks that the inventory item is a Prebuilt Deck.
|
||||||
@@ -40,6 +40,6 @@ public abstract class ItemPredicate {
|
|||||||
*/
|
*/
|
||||||
public static class Presets {
|
public static class Presets {
|
||||||
/** The Item IsPack. */
|
/** The Item IsPack. */
|
||||||
public static final Predicate<InventoryItem> IS_PACK_OR_DECK = Predicates.or(IsBoosterPack, IsFatPack, IsTournamentPack, IsStarterDeck, IsPrebuiltDeck);
|
public static final Predicate<Object> IS_PACK_OR_DECK = IsBoosterPack.or(IsFatPack).or(IsTournamentPack).or(IsStarterDeck).or(IsPrebuiltDeck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -613,31 +613,31 @@ public class BoosterGenerator {
|
|||||||
ps.addAll(Iterables.filter(src, predicate));
|
ps.addAll(Iterables.filter(src, predicate));
|
||||||
|
|
||||||
} else if (mainCode.equalsIgnoreCase(BoosterSlots.UNCOMMON_RARE)) { // for sets like ARN, where U1 cards are considered rare and U3 are uncommon
|
} else if (mainCode.equalsIgnoreCase(BoosterSlots.UNCOMMON_RARE)) { // for sets like ARN, where U1 cards are considered rare and U3 are uncommon
|
||||||
Predicate<PaperCard> predicateRares = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred);
|
Predicate<PaperCard> predicateRares = setPred.and(Presets.IS_RARE).and(extraPred);
|
||||||
ps.addAll(Iterables.filter(src, predicateRares));
|
ps.addAll(Iterables.filter(src, predicateRares));
|
||||||
|
|
||||||
Predicate<PaperCard> predicateUncommon = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_UNCOMMON, extraPred);
|
Predicate<PaperCard> predicateUncommon = setPred.and(Presets.IS_UNCOMMON).and(extraPred);
|
||||||
ps.addAll(Iterables.filter(src, predicateUncommon), 3);
|
ps.addAll(Iterables.filter(src, predicateUncommon), 3);
|
||||||
|
|
||||||
} else if (mainCode.equalsIgnoreCase(BoosterSlots.RARE_MYTHIC)) {
|
} else if (mainCode.equalsIgnoreCase(BoosterSlots.RARE_MYTHIC)) {
|
||||||
// Typical ratio of rares to mythics is 53:15, changing to 35:10 in smaller sets.
|
// Typical ratio of rares to mythics is 53:15, changing to 35:10 in smaller sets.
|
||||||
// To achieve the desired 1:8 are all mythics are added once, and all rares added twice per print sheet.
|
// To achieve the desired 1:8 are all mythics are added once, and all rares added twice per print sheet.
|
||||||
|
|
||||||
Predicate<PaperCard> predicateMythic = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE, extraPred);
|
Predicate<PaperCard> predicateMythic = setPred.and(Presets.IS_MYTHIC_RARE).and(extraPred);
|
||||||
ps.addAll(Iterables.filter(src, predicateMythic));
|
ps.addAll(Iterables.filter(src, predicateMythic));
|
||||||
|
|
||||||
Predicate<PaperCard> predicateRare = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred);
|
Predicate<PaperCard> predicateRare = setPred.and(Presets.IS_RARE).and(extraPred);
|
||||||
ps.addAll(Iterables.filter(src, predicateRare), 2);
|
ps.addAll(Iterables.filter(src, predicateRare), 2);
|
||||||
} else if (mainCode.equalsIgnoreCase(BoosterSlots.UNCOMMON_RARE_MYTHIC)) {
|
} else if (mainCode.equalsIgnoreCase(BoosterSlots.UNCOMMON_RARE_MYTHIC)) {
|
||||||
// Extended version of RARE_MYTHIC, used for Alchemy slots
|
// Extended version of RARE_MYTHIC, used for Alchemy slots
|
||||||
|
|
||||||
Predicate<PaperCard> predicateMythic = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE, extraPred);
|
Predicate<PaperCard> predicateMythic = setPred.and(Presets.IS_MYTHIC_RARE).and(extraPred);
|
||||||
ps.addAll(Iterables.filter(src, predicateMythic));
|
ps.addAll(Iterables.filter(src, predicateMythic));
|
||||||
|
|
||||||
Predicate<PaperCard> predicateRare = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred);
|
Predicate<PaperCard> predicateRare = setPred.and(Presets.IS_RARE).and(extraPred);
|
||||||
ps.addAll(Iterables.filter(src, predicateRare), 2);
|
ps.addAll(Iterables.filter(src, predicateRare), 2);
|
||||||
|
|
||||||
Predicate<PaperCard> predicateUncommon = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_UNCOMMON, extraPred);
|
Predicate<PaperCard> predicateUncommon = setPred.and(Presets.IS_UNCOMMON).and(extraPred);
|
||||||
ps.addAll(Iterables.filter(src, predicateUncommon), 4);
|
ps.addAll(Iterables.filter(src, predicateUncommon), 4);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Booster generator: operator could not be parsed - " + mainCode);
|
throw new IllegalArgumentException("Booster generator: operator could not be parsed - " + mainCode);
|
||||||
@@ -670,10 +670,9 @@ public class BoosterGenerator {
|
|||||||
Predicate<PaperCard> toAdd = null;
|
Predicate<PaperCard> toAdd = null;
|
||||||
if (operator.equalsIgnoreCase(BoosterSlots.DUAL_FACED_CARD)) {
|
if (operator.equalsIgnoreCase(BoosterSlots.DUAL_FACED_CARD)) {
|
||||||
toAdd = Predicates.compose(
|
toAdd = Predicates.compose(
|
||||||
Predicates.or(
|
CardRulesPredicates.splitType(CardSplitType.Transform)
|
||||||
CardRulesPredicates.splitType(CardSplitType.Transform),
|
.or(CardRulesPredicates.splitType(CardSplitType.Meld))
|
||||||
CardRulesPredicates.splitType(CardSplitType.Meld),
|
.or(CardRulesPredicates.splitType(CardSplitType.Modal)
|
||||||
CardRulesPredicates.splitType(CardSplitType.Modal)
|
|
||||||
),
|
),
|
||||||
PaperCard::getRules);
|
PaperCard::getRules);
|
||||||
} else if (operator.equalsIgnoreCase(BoosterSlots.LAND)) { toAdd = Predicates.compose(CardRulesPredicates.Presets.IS_LAND, PaperCard::getRules);
|
} else if (operator.equalsIgnoreCase(BoosterSlots.LAND)) { toAdd = Predicates.compose(CardRulesPredicates.Presets.IS_LAND, PaperCard::getRules);
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class ItemPool<T extends InventoryItem> implements Iterable<Entry<T, Inte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final <U extends InventoryItem> int countAll(Predicate<U> condition, Class<U> cls) {
|
public final <U extends InventoryItem> int countAll(Predicate<? super U> condition, Class<U> cls) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
Map<T, Integer> matchingKeys = Maps.filterKeys(this.items, item -> cls.isInstance(item) && (condition.test((U)item)));
|
Map<T, Integer> matchingKeys = Maps.filterKeys(this.items, item -> cls.isInstance(item) && (condition.test((U)item)));
|
||||||
for (Integer i : matchingKeys.values()) {
|
for (Integer i : matchingKeys.values()) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package forge.util;
|
package forge.util;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -14,25 +13,10 @@ public class Predicates {
|
|||||||
//TODO: Should be able to clean up the casting here.
|
//TODO: Should be able to clean up the casting here.
|
||||||
return x -> Iterables.all(components, (Predicate<Predicate<? super T>>) i -> i.test(x));
|
return x -> Iterables.all(components, (Predicate<Predicate<? super T>>) i -> i.test(x));
|
||||||
}
|
}
|
||||||
public static <T> Predicate<T> and(Predicate<? super T>... components) {
|
|
||||||
//TODO: Switch to iterables all once it stops being confused and the others are inlined.
|
|
||||||
//Or just switch this to chained "and"s by hand.
|
|
||||||
return x -> {
|
|
||||||
for(Predicate<? super T> predicate : components) {
|
|
||||||
if(!predicate.test(x))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public static <T> Predicate<T> or(Iterable<? extends Predicate<? super T>> components) {
|
public static <T> Predicate<T> or(Iterable<? extends Predicate<? super T>> components) {
|
||||||
//TODO: Should be able to clean up the casting here.
|
//TODO: Should be able to clean up the casting here.
|
||||||
return x -> Iterables.any(components, (Predicate<Predicate<? super T>>) i -> i.test(x));
|
return x -> Iterables.any(components, (Predicate<Predicate<? super T>>) i -> i.test(x));
|
||||||
}
|
}
|
||||||
public static <T> Predicate<T> or(Predicate<? super T>... components) {
|
|
||||||
//TODO: Faster implementation. Or just do this one by hand.
|
|
||||||
return or(Arrays.asList(components));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <A, B> Predicate<A> compose(Predicate<B> predicate, Function<A, ? extends B> function) {
|
public static <A, B> Predicate<A> compose(Predicate<B> predicate, Function<A, ? extends B> function) {
|
||||||
return x -> predicate.test(function.apply(x));
|
return x -> predicate.test(function.apply(x));
|
||||||
|
|||||||
@@ -75,11 +75,12 @@ public class PlanarConquestCommanderGeneraterGA extends PlanarConquestGeneraterG
|
|||||||
cards.add(StaticData.instance().getCommonCards().getUniqueByName(cardName));
|
cards.add(StaticData.instance().getCommonCards().getUniqueByName(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterable<PaperCard> filtered= Iterables.filter(cards, Predicates.and(
|
Iterable<PaperCard> filtered= Iterables.filter(cards,
|
||||||
Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_DECKS, PaperCard::getRules),
|
Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_DECKS, PaperCard::getRules)
|
||||||
Predicates.compose(CardRulesPredicates.Presets.IS_PLANESWALKER, PaperCard::getRules),
|
.and(Predicates.compose(CardRulesPredicates.Presets.IS_PLANESWALKER, PaperCard::getRules))
|
||||||
//Predicates.compose(CardRulesPredicates.Presets.IS_LEGENDARY, PaperCard.FN_GET_RULES),
|
//.and(Predicates.compose(CardRulesPredicates.Presets.IS_LEGENDARY, PaperCard::getRules))
|
||||||
gameFormat.getFilterPrinted()));
|
.and(gameFormat.getFilterPrinted())
|
||||||
|
);
|
||||||
|
|
||||||
List<PaperCard> filteredList = Lists.newArrayList(filtered);
|
List<PaperCard> filteredList = Lists.newArrayList(filtered);
|
||||||
rankedList = CardRanker.rankCardsInDeck(filteredList);
|
rankedList = CardRanker.rankCardsInDeck(filteredList);
|
||||||
|
|||||||
@@ -105,10 +105,11 @@ public class PlanarConquestGeneraterGA extends AbstractGeneticAlgorithm<Deck> {
|
|||||||
cards.add(StaticData.instance().getCommonCards().getUniqueByName(cardName));
|
cards.add(StaticData.instance().getCommonCards().getUniqueByName(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterable<PaperCard> filtered= Iterables.filter(cards, Predicates.and(
|
Iterable<PaperCard> filtered= Iterables.filter(cards,
|
||||||
Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_DECKS, PaperCard::getRules),
|
Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_DECKS, PaperCard::getRules)
|
||||||
Predicates.compose(CardRulesPredicates.Presets.IS_NON_LAND, PaperCard::getRules),
|
.and(Predicates.compose(CardRulesPredicates.Presets.IS_NON_LAND, PaperCard::getRules))
|
||||||
gameFormat.getFilterPrinted()));
|
.and(gameFormat.getFilterPrinted())
|
||||||
|
);
|
||||||
|
|
||||||
List<PaperCard> filteredList = Lists.newArrayList(filtered);
|
List<PaperCard> filteredList = Lists.newArrayList(filtered);
|
||||||
setRankedList(CardRanker.rankCardsInDeck(filteredList));
|
setRankedList(CardRanker.rankCardsInDeck(filteredList));
|
||||||
|
|||||||
@@ -77,11 +77,12 @@ public class PlanarConquestTribalGeneraterGA extends PlanarConquestGeneraterGA {
|
|||||||
cards.add(StaticData.instance().getCommonCards().getUniqueByName(cardName));
|
cards.add(StaticData.instance().getCommonCards().getUniqueByName(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterable<PaperCard> filteredTribe= Iterables.filter(cards, Predicates.and(
|
Iterable<PaperCard> filteredTribe= Iterables.filter(cards,
|
||||||
Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_DECKS, PaperCard::getRules),
|
Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_DECKS, PaperCard::getRules)
|
||||||
Predicates.compose(CardRulesPredicates.hasCreatureType("Pirate"), PaperCard::getRules),
|
.and(Predicates.compose(CardRulesPredicates.hasCreatureType("Pirate"), PaperCard::getRules))
|
||||||
Predicates.compose(CardRulesPredicates.Presets.IS_CREATURE, PaperCard::getRules),
|
.and(Predicates.compose(CardRulesPredicates.Presets.IS_CREATURE, PaperCard::getRules))
|
||||||
gameFormat.getFilterPrinted()));
|
.and(gameFormat.getFilterPrinted())
|
||||||
|
);
|
||||||
|
|
||||||
List<PaperCard> filteredListTribe = Lists.newArrayList(filteredTribe);
|
List<PaperCard> filteredListTribe = Lists.newArrayList(filteredTribe);
|
||||||
rankedList = CardRanker.rankCardsInDeck(filteredListTribe);
|
rankedList = CardRanker.rankCardsInDeck(filteredListTribe);
|
||||||
|
|||||||
@@ -663,9 +663,8 @@ public class DeckgenUtil {
|
|||||||
// Get random multicolor Legendary creature
|
// Get random multicolor Legendary creature
|
||||||
final DeckFormat format = gameType.getDeckFormat();
|
final DeckFormat format = gameType.getDeckFormat();
|
||||||
Predicate<CardRules> canPlay = forAi ? DeckGeneratorBase.AI_CAN_PLAY : CardRulesPredicates.IS_KEPT_IN_RANDOM_DECKS;
|
Predicate<CardRules> canPlay = forAi ? DeckGeneratorBase.AI_CAN_PLAY : CardRulesPredicates.IS_KEPT_IN_RANDOM_DECKS;
|
||||||
@SuppressWarnings("unchecked")
|
Predicate<PaperCard> legal = format.isLegalCardPredicate().and(format.isLegalCommanderPredicate());
|
||||||
Iterable<PaperCard> legends = cardDb.getAllCards(Predicates.and(format.isLegalCardPredicate(), format.isLegalCommanderPredicate(),
|
Iterable<PaperCard> legends = cardDb.getAllCards(legal.and(Predicates.compose(canPlay, PaperCard::getRules)));
|
||||||
Predicates.compose(canPlay, PaperCard::getRules)));
|
|
||||||
|
|
||||||
commander = Aggregates.random(legends);
|
commander = Aggregates.random(legends);
|
||||||
return generateRandomCommanderDeck(commander, format, forAi, false);
|
return generateRandomCommanderDeck(commander, format, forAi, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user