mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-11 16:26:22 +00:00
Guava migration - Replace select usages of Iterables.filter
This commit is contained in:
@@ -62,6 +62,7 @@ import io.sentry.Sentry;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -2205,7 +2206,7 @@ public class AiController {
|
||||
|
||||
// TODO move to more common place
|
||||
private static <T> List<T> filterList(List<T> input, Predicate<? super T> pred) {
|
||||
List<T> filtered = Lists.newArrayList(Iterables.filter(input, pred));
|
||||
List<T> filtered = input.stream().filter(pred).collect(Collectors.toList());
|
||||
input.removeAll(filtered);
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@@ -250,12 +250,11 @@ public class ComputerUtilCard {
|
||||
|
||||
final List<Card> bLand = CardLists.getType(land, sminBL);
|
||||
|
||||
for (Card ut : Iterables.filter(bLand, CardPredicates.UNTAPPED)) {
|
||||
return ut;
|
||||
}
|
||||
|
||||
// TODO potentially risky if simulation mode currently able to reach this from triggers
|
||||
return Aggregates.random(bLand); // random tapped land of least represented type
|
||||
return bLand.stream()
|
||||
.filter(CardPredicates.UNTAPPED)
|
||||
.findFirst()
|
||||
// TODO potentially risky if simulation mode currently able to reach this from triggers
|
||||
.orElseGet(() -> Aggregates.random(bLand)); // random tapped land of least represented type
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,12 +41,12 @@ import forge.game.trigger.Trigger;
|
||||
import forge.game.trigger.TriggerType;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Iterables;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.TextUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ComputerUtilMana {
|
||||
private final static boolean DEBUG_MANA_PAYMENT = false;
|
||||
@@ -264,7 +264,10 @@ public class ComputerUtilMana {
|
||||
saList = filteredList;
|
||||
break;
|
||||
case "NotSameCard":
|
||||
saList = Lists.newArrayList(Iterables.filter(filteredList, saPay -> !saPay.getHostCard().getName().equals(sa.getHostCard().getName())));
|
||||
String hostName = sa.getHostCard().getName();
|
||||
saList = filteredList.stream()
|
||||
.filter(saPay -> !saPay.getHostCard().getName().equals(hostName))
|
||||
.collect(Collectors.toList());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -685,7 +685,7 @@ public class SpecialCardAi {
|
||||
// Goblin Polka Band
|
||||
public static class GoblinPolkaBand {
|
||||
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||
int maxPotentialTgts = Lists.newArrayList(Iterables.filter(ai.getOpponents().getCreaturesInPlay(), CardPredicates.UNTAPPED)).size();
|
||||
int maxPotentialTgts = ai.getOpponents().getCreaturesInPlay().filter(CardPredicates.UNTAPPED).size();
|
||||
int maxPotentialPayment = ComputerUtilMana.determineLeftoverMana(sa, ai, "R", false);
|
||||
|
||||
int numTgts = Math.min(maxPotentialPayment, maxPotentialTgts);
|
||||
@@ -1295,7 +1295,7 @@ public class SpecialCardAi {
|
||||
|
||||
public static boolean considerSecondTarget(final Player ai, final SpellAbility sa) {
|
||||
Card firstTgt = sa.getParent().getTargetCard();
|
||||
Iterable<Card> candidates = Iterables.filter(ai.getOpponents().getCardsIn(ZoneType.Battlefield),
|
||||
CardCollection candidates = ai.getOpponents().getCardsIn(ZoneType.Battlefield).filter(
|
||||
CardPredicates.sharesCardTypeWith(firstTgt).and(CardPredicates.isTargetableBy(sa)));
|
||||
Card secondTgt = Aggregates.random(candidates);
|
||||
if (secondTgt != null) {
|
||||
|
||||
@@ -13,11 +13,11 @@ import forge.game.spellability.AbilitySub;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.Iterables;
|
||||
import forge.util.collect.FCollection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class ChooseGenericAi extends SpellAbilityAi {
|
||||
@@ -84,7 +84,9 @@ public class ChooseGenericAi extends SpellAbilityAi {
|
||||
} else if ("Random".equals(logic)) {
|
||||
return Aggregates.random(spells);
|
||||
} else if ("Phasing".equals(logic)) { // Teferi's Realm : keep aggressive
|
||||
List<SpellAbility> filtered = Lists.newArrayList(Iterables.filter(spells, sp -> !sp.getDescription().contains("Creature") && !sp.getDescription().contains("Land")));
|
||||
List<SpellAbility> filtered = spells.stream()
|
||||
.filter(sp -> !sp.getDescription().contains("Creature") && !sp.getDescription().contains("Land"))
|
||||
.collect(Collectors.toList());
|
||||
return Aggregates.random(filtered);
|
||||
} else if ("PayUnlessCost".equals(logic)) {
|
||||
for (final SpellAbility sp : spells) {
|
||||
|
||||
@@ -23,7 +23,6 @@ import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Iterables;
|
||||
|
||||
public class CountersMultiplyAi extends SpellAbilityAi {
|
||||
|
||||
@@ -103,7 +102,9 @@ public class CountersMultiplyAi extends SpellAbilityAi {
|
||||
if (list.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
Card safeMatch = Iterables.getFirst(Iterables.filter(list, CardPredicates.hasCounters().negate()), null);
|
||||
Card safeMatch = list.stream()
|
||||
.filter(CardPredicates.hasCounters().negate())
|
||||
.findFirst().orElse(null);
|
||||
sa.getTargets().add(safeMatch == null ? list.getFirst() : safeMatch);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package forge.ai.ability;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import forge.ai.AiController;
|
||||
import forge.ai.AiProps;
|
||||
|
||||
@@ -38,6 +38,7 @@ import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
public final static String foilSuffix = "+";
|
||||
@@ -827,7 +828,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
return null; // nothing to do
|
||||
|
||||
// Filter Cards Editions based on set preferences
|
||||
List<CardEdition> acceptedEditions = Lists.newArrayList(Iterables.filter(cardEditions, artPref::accept));
|
||||
List<CardEdition> acceptedEditions = cardEditions.stream().filter(artPref::accept).collect(Collectors.toList());
|
||||
|
||||
/* At this point, it may be possible that Art Preference is too-strict for the requested card!
|
||||
i.e. acceptedEditions.size() == 0!
|
||||
@@ -899,6 +900,10 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
}).values();
|
||||
}
|
||||
|
||||
public List<PaperCard> getUniqueCardsNoAlt(String cardName) {
|
||||
return Lists.newArrayList(Maps.filterEntries(uniqueCardsByName, entry -> entry.getKey().equals(entry.getValue().getName())).get(getName(cardName)));
|
||||
}
|
||||
|
||||
public PaperCard getUniqueByName(final String name) {
|
||||
return uniqueCardsByName.get(getName(name));
|
||||
}
|
||||
@@ -940,8 +945,23 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
return Multimaps.filterEntries(allCardsByName, entry -> entry.getKey().equals(entry.getValue().getName())).values();
|
||||
}
|
||||
|
||||
public Collection<PaperCard> getAllNonPromoCards() {
|
||||
return Lists.newArrayList(Iterables.filter(getAllCards(), paperCard -> {
|
||||
@Override
|
||||
public Stream<PaperCard> streamAllCards() {
|
||||
return allCardsByName.values().stream();
|
||||
}
|
||||
@Override
|
||||
public Stream<PaperCard> streamUniqueCards() {
|
||||
return uniqueCardsByName.values().stream();
|
||||
}
|
||||
public Stream<PaperCard> streamAllCardsNoAlt() {
|
||||
return allCardsByName.entries().stream().filter(e -> e.getKey().equals(e.getValue().getName())).map(Entry::getValue);
|
||||
}
|
||||
public Stream<PaperCard> streamUniqueCardsNoAlt() {
|
||||
return uniqueCardsByName.entrySet().stream().filter(e -> e.getKey().equals(e.getValue().getName())).map(Entry::getValue);
|
||||
}
|
||||
public Stream<PaperCard> streamAllNonPromoCards() {
|
||||
//TODO: This should probably just be a filter to tack onto streamAllCards
|
||||
return streamAllCards().filter(paperCard -> {
|
||||
CardEdition edition = null;
|
||||
try {
|
||||
edition = editions.getEditionByCodeOrThrow(paperCard.getEdition());
|
||||
@@ -949,11 +969,19 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
return false;
|
||||
}
|
||||
return edition != null && edition.getType() != Type.PROMO;
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public Stream<ICardFace> streamAllFaces() {
|
||||
return facesByName.values().stream();
|
||||
}
|
||||
|
||||
public Collection<PaperCard> getAllNonPromoCards() {
|
||||
return streamAllNonPromoCards().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Collection<PaperCard> getUniqueCardsNoAltNoOnline() {
|
||||
return Lists.newArrayList(Iterables.filter(getUniqueCardsNoAlt(), paperCard -> {
|
||||
return streamUniqueCardsNoAlt().filter(paperCard -> {
|
||||
CardEdition edition = null;
|
||||
try {
|
||||
edition = editions.getEditionByCodeOrThrow(paperCard.getEdition());
|
||||
@@ -963,11 +991,12 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Collection<PaperCard> getAllNonPromosNonReprintsNoAlt() {
|
||||
return Lists.newArrayList(Iterables.filter(getAllCardsNoAlt(), paperCard -> {
|
||||
//TODO: This should probably also be a stream filter.
|
||||
return streamAllCardsNoAlt().filter(paperCard -> {
|
||||
CardEdition edition = null;
|
||||
try {
|
||||
edition = editions.getEditionByCodeOrThrow(paperCard.getEdition());
|
||||
@@ -977,7 +1006,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public String getName(final String cardName) {
|
||||
@@ -1007,19 +1036,19 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
*/
|
||||
@Override
|
||||
public List<PaperCard> getAllCards(Predicate<PaperCard> predicate) {
|
||||
return Lists.newArrayList(Iterables.filter(getAllCards(), predicate));
|
||||
return streamAllCards().filter(predicate).collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PaperCard> getAllCards(final String cardName, Predicate<PaperCard> predicate){
|
||||
return Lists.newArrayList(Iterables.filter(getAllCards(cardName), predicate));
|
||||
return getAllCards(cardName).stream().filter(predicate).collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a modifiable list of cards matching the given predicate
|
||||
*/
|
||||
public List<PaperCard> getAllCardsNoAlt(Predicate<PaperCard> predicate) {
|
||||
return Lists.newArrayList(Iterables.filter(getAllCardsNoAlt(), predicate));
|
||||
return streamAllCardsNoAlt().filter(predicate).collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
// Do I want a foiled version of these cards?
|
||||
|
||||
@@ -304,9 +304,7 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
creatureTypes.addAll(getAllCreatureTypes());
|
||||
creatureTypes.removeAll(this.excludedCreatureSubtypes);
|
||||
} else {
|
||||
for (final String t : Iterables.filter(subtypes, Predicates.IS_CREATURE_TYPE)) {
|
||||
creatureTypes.add(t);
|
||||
}
|
||||
subtypes.stream().filter(Predicates.IS_CREATURE_TYPE).forEach(creatureTypes::add);
|
||||
}
|
||||
return creatureTypes;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface ICardDatabase extends Iterable<PaperCard> {
|
||||
/**
|
||||
@@ -85,6 +86,9 @@ public interface ICardDatabase extends Iterable<PaperCard> {
|
||||
Collection<PaperCard> getAllCards(CardEdition edition);
|
||||
Collection<PaperCard> getUniqueCards();
|
||||
|
||||
Stream<PaperCard> streamAllCards();
|
||||
Stream<PaperCard> streamUniqueCards();
|
||||
|
||||
/* UTILITY METHODS
|
||||
* =============== */
|
||||
int getMaxArtIndex(String cardName);
|
||||
|
||||
@@ -38,11 +38,9 @@ public class DeckGenPool implements IDeckGenPool {
|
||||
@Override
|
||||
public PaperCard getCard(String name, String edition) {
|
||||
Predicate<PaperCard> filter = PaperCardPredicates.printedInSet(edition).and(PaperCardPredicates.name(name));
|
||||
Iterable<PaperCard> editionCards=Iterables.filter(cards.values(), filter);
|
||||
if (editionCards.iterator().hasNext()){
|
||||
return editionCards.iterator().next();
|
||||
}
|
||||
return getCard(name);
|
||||
return cards.values().stream()
|
||||
.filter(filter)
|
||||
.findFirst().orElseGet(() -> getCard(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,11 +22,11 @@ import forge.StaticData;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.item.generation.BoosterGenerator;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.Iterables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class SealedProduct implements InventoryItemFromSet {
|
||||
|
||||
@@ -114,6 +114,6 @@ public abstract class SealedProduct implements InventoryItemFromSet {
|
||||
protected List<PaperCard> getRandomBasicLands(final String setCode, final int count) {
|
||||
Predicate<PaperCard> cardsRule = PaperCardPredicates.printedInSet(setCode)
|
||||
.and(PaperCardPredicates.fromRules(CardRulesPredicates.IS_BASIC_LAND));
|
||||
return Aggregates.random(Iterables.filter(StaticData.instance().getCommonCards().getAllCards(), cardsRule), count);
|
||||
return Aggregates.random(StaticData.instance().getCommonCards().streamAllCards().filter(cardsRule).collect(Collectors.toList()), count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ public class Iterables {
|
||||
public static <T> Iterable<T> filter(Iterable<T> iterable, Predicate<? super T> filter) {
|
||||
return () -> StreamSupport.stream(iterable.spliterator(), false).filter(filter).iterator();
|
||||
}
|
||||
public static <T> Iterable<T> filter(Collection<T> iterable, Predicate<? super T> filter) {
|
||||
return () -> iterable.stream().filter(filter).iterator();
|
||||
}
|
||||
public static <T> Iterable<T> filter(final Iterable<?> iterable, final Class<T> desiredType) {
|
||||
return () -> StreamSupport.stream(iterable.spliterator(), false)
|
||||
.filter(desiredType::isInstance)
|
||||
@@ -63,10 +66,6 @@ public class Iterables {
|
||||
|
||||
//TODO: Inline everything below.
|
||||
|
||||
public static <T> Iterable<T> filter(Collection<T> iterable, Predicate<? super T> filter) {
|
||||
return () -> iterable.stream().filter(filter).iterator();
|
||||
}
|
||||
|
||||
|
||||
public static int size(Collection<?> collection) {
|
||||
return collection.size();
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.util.storage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import forge.util.IHasName;
|
||||
|
||||
@@ -35,4 +36,5 @@ public interface IStorage<T> extends Iterable<T>, IHasName {
|
||||
IStorage<IStorage<T>> getFolders();
|
||||
IStorage<T> tryGetFolder(String path);
|
||||
IStorage<T> getFolderOrCreate(String path);
|
||||
Stream<T> stream();
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -65,6 +66,11 @@ public class StorageBase<T> implements IStorage<T> {
|
||||
return map.values().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<T> stream() {
|
||||
return map.values().stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String name) {
|
||||
return name != null && map.containsKey(name);
|
||||
|
||||
@@ -495,7 +495,7 @@ public class AbilityUtils {
|
||||
players.addAll(player.getOpponents());
|
||||
val = playerXCount(players, calcX[1], card, ability);
|
||||
} else if (hType.equals("RegisteredOpponents")) {
|
||||
players.addAll(Iterables.filter(game.getRegisteredPlayers(), PlayerPredicates.isOpponentOf(player)));
|
||||
players.addAll(game.getRegisteredPlayers().filter(PlayerPredicates.isOpponentOf(player)));
|
||||
val = playerXCount(players, calcX[1], card, ability);
|
||||
} else if (hType.equals("Other")) {
|
||||
players.addAll(player.getAllOtherPlayers());
|
||||
|
||||
@@ -150,7 +150,7 @@ public class CopyPermanentEffect extends TokenEffectBase {
|
||||
List<Card> tgtCards = Lists.newArrayList();
|
||||
|
||||
if (sa.hasParam("ValidSupportedCopy")) {
|
||||
List<PaperCard> cards = Lists.newArrayList(StaticData.instance().getCommonCards().getUniqueCards());
|
||||
Iterable<PaperCard> cards = StaticData.instance().getCommonCards().getUniqueCards();
|
||||
String valid = sa.getParam("ValidSupportedCopy");
|
||||
if (valid.contains("X")) {
|
||||
valid = TextUtil.fastReplace(valid,
|
||||
@@ -158,11 +158,11 @@ public class CopyPermanentEffect extends TokenEffectBase {
|
||||
}
|
||||
if (StringUtils.containsIgnoreCase(valid, "creature")) {
|
||||
Predicate<PaperCard> cpp = PaperCardPredicates.fromRules(CardRulesPredicates.IS_CREATURE);
|
||||
cards = Lists.newArrayList(Iterables.filter(cards, cpp));
|
||||
cards = Iterables.filter(cards, cpp);
|
||||
}
|
||||
if (StringUtils.containsIgnoreCase(valid, "equipment")) {
|
||||
Predicate<PaperCard> cpp = PaperCardPredicates.fromRules(CardRulesPredicates.IS_EQUIPMENT);
|
||||
cards = Lists.newArrayList(Iterables.filter(cards, cpp));
|
||||
cards = Iterables.filter(cards, cpp);
|
||||
}
|
||||
if (sa.hasParam("RandomCopied")) {
|
||||
List<PaperCard> copysource = Lists.newArrayList(cards);
|
||||
|
||||
@@ -2,6 +2,7 @@ package forge.game.ability.effects;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import forge.card.CardStateName;
|
||||
import forge.card.GamePieceType;
|
||||
@@ -10,7 +11,6 @@ import forge.util.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.StaticData;
|
||||
import forge.card.CardRulesPredicates;
|
||||
@@ -117,13 +117,11 @@ public class PlayEffect extends SpellAbilityEffect {
|
||||
cards.add(StaticData.instance().getCommonCards().getUniqueByName(name));
|
||||
}
|
||||
} else if (valid.equalsIgnoreCase("sorcery")) {
|
||||
cards = Lists.newArrayList(StaticData.instance().getCommonCards().getUniqueCards());
|
||||
final Predicate<PaperCard> cpp = PaperCardPredicates.fromRules(CardRulesPredicates.IS_SORCERY);
|
||||
cards = Lists.newArrayList(Iterables.filter(cards, cpp));
|
||||
cards = StaticData.instance().getCommonCards().streamUniqueCards().filter(cpp).collect(Collectors.toList());
|
||||
} else if (valid.equalsIgnoreCase("instant")) {
|
||||
cards = Lists.newArrayList(StaticData.instance().getCommonCards().getUniqueCards());
|
||||
final Predicate<PaperCard> cpp = PaperCardPredicates.fromRules(CardRulesPredicates.IS_INSTANT);
|
||||
cards = Lists.newArrayList(Iterables.filter(cards, cpp));
|
||||
cards = StaticData.instance().getCommonCards().streamUniqueCards().filter(cpp).collect(Collectors.toList());
|
||||
}
|
||||
if (sa.hasParam("RandomCopied")) {
|
||||
final CardCollection choice = new CardCollection();
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package forge.game.ability.effects;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -18,7 +19,6 @@ import forge.game.spellability.SpellAbility;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.PaperCardPredicates;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.Iterables;
|
||||
|
||||
public class PlayLandVariantEffect extends SpellAbilityEffect {
|
||||
|
||||
@@ -28,10 +28,9 @@ public class PlayLandVariantEffect extends SpellAbilityEffect {
|
||||
final Player activator = sa.getActivatingPlayer();
|
||||
final Game game = source.getGame();
|
||||
final String landType = sa.getParam("Clone");
|
||||
List<PaperCard> cards = Lists.newArrayList(StaticData.instance().getCommonCards().getUniqueCards());
|
||||
Stream<PaperCard> cardStream = StaticData.instance().getCommonCards().streamUniqueCards();
|
||||
if ("BasicLand".equals(landType)) {
|
||||
final Predicate<PaperCard> cpp = PaperCardPredicates.fromRules(CardRulesPredicates.IS_BASIC_LAND);
|
||||
cards = Lists.newArrayList(Iterables.filter(cards, cpp));
|
||||
cardStream = cardStream.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_BASIC_LAND));
|
||||
}
|
||||
// current color of source card
|
||||
final ColorSet color = source.getColor();
|
||||
@@ -47,8 +46,8 @@ public class PlayLandVariantEffect extends SpellAbilityEffect {
|
||||
}
|
||||
}
|
||||
|
||||
final Predicate<PaperCard> cp = x -> landNames.contains(x.getName());
|
||||
cards = Lists.newArrayList(Iterables.filter(cards, cp));
|
||||
cardStream = cardStream.filter(x -> landNames.contains(x.getName()));
|
||||
List<PaperCard> cards = cardStream.collect(Collectors.toList());
|
||||
// get a random basic land
|
||||
Card random;
|
||||
// if activator cannot play the random land, loop
|
||||
|
||||
@@ -3371,9 +3371,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
if (ck.isRemoveNonMana()) {
|
||||
// List only has nonMana
|
||||
if (null == mana) {
|
||||
List<SpellAbility> toRemove = Lists.newArrayList(
|
||||
Iterables.filter(list, SpellAbilityPredicates.isManaAbility().negate()));
|
||||
list.removeAll(toRemove);
|
||||
list.removeIf(SpellAbilityPredicates.isManaAbility().negate());
|
||||
} else if (false == mana) {
|
||||
list.clear();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package forge.game.card;
|
||||
|
||||
import forge.util.collect.FCollection;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CardCollection extends FCollection<Card> implements CardCollectionView {
|
||||
private static final long serialVersionUID = -8133537013727100275L;
|
||||
|
||||
@@ -123,6 +125,16 @@ public class CardCollection extends FCollection<Card> implements CardCollectionV
|
||||
return new CardCollection(super.subList(fromIndex, toIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CardCollection containing the elements from this collection which match
|
||||
* the given predicate.
|
||||
*/
|
||||
public CardCollection filter(Predicate<? super Card> test) {
|
||||
CardCollection out = new CardCollection();
|
||||
this.stream().filter(test).forEach(out::add);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* An unmodifiable, empty {@link CardCollection}.
|
||||
*/
|
||||
|
||||
@@ -6,11 +6,11 @@ package forge.game.card;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.ForwardingTable;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.Table;
|
||||
|
||||
import forge.game.CardTraitBase;
|
||||
@@ -23,7 +23,6 @@ import forge.game.player.Player;
|
||||
import forge.game.player.PlayerCollection;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.trigger.TriggerType;
|
||||
import forge.util.Iterables;
|
||||
|
||||
public class CardDamageMap extends ForwardingTable<Card, GameEntity, Integer> {
|
||||
private Table<Card, GameEntity, Integer> dataMap = HashBasedTable.create();
|
||||
@@ -193,10 +192,10 @@ public class CardDamageMap extends ForwardingTable<Card, GameEntity, Integer> {
|
||||
Set<Card> filteredSource = null;
|
||||
Set<GameEntity> filteredTarget = null;
|
||||
if (validSource != null) {
|
||||
filteredSource = Sets.newHashSet(Iterables.filter(rowKeySet(), GameObjectPredicates.restriction(validSource.split(","), host.getController(), host, sa)));
|
||||
filteredSource = rowKeySet().stream().filter(GameObjectPredicates.restriction(validSource.split(","), host.getController(), host, sa)).collect(Collectors.toSet());
|
||||
}
|
||||
if (validTarget != null) {
|
||||
filteredTarget = Sets.newHashSet(Iterables.filter(columnKeySet(), GameObjectPredicates.restriction(validTarget.split(","), host.getController(), host, sa)));
|
||||
filteredTarget = columnKeySet().stream().filter(GameObjectPredicates.restriction(validTarget.split(","), host.getController(), host, sa)).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
for (Table.Cell<Card, GameEntity, Integer> c : cellSet()) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.game.card;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -39,7 +40,6 @@ import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityPredicates;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Iterables;
|
||||
import forge.util.TextUtil;
|
||||
import forge.util.collect.FCollection;
|
||||
|
||||
@@ -142,7 +142,9 @@ public final class CardUtil {
|
||||
}
|
||||
|
||||
public static List<SpellAbility> getThisTurnActivated(final String valid, final Card src, final CardTraitBase ctb, final Player controller) {
|
||||
return Lists.newArrayList(Iterables.filter(src.getGame().getStack().getAbilityActivatedThisTurn(), SpellAbilityPredicates.isValid(valid.split(","), controller, src, ctb)));
|
||||
return src.getGame().getStack().getAbilityActivatedThisTurn().stream()
|
||||
.filter(SpellAbilityPredicates.isValid(valid.split(","), controller, src, ctb))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Card> getCastSinceBeginningOfYourLastTurn(final String valid, final Card src, final CardTraitBase ctb, final Player controller) {
|
||||
|
||||
@@ -2,13 +2,14 @@ package forge.game.card;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import forge.util.Iterables;
|
||||
import forge.game.GameObject;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
import com.google.common.collect.ForwardingTable;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Table;
|
||||
|
||||
import forge.game.CardTraitBase;
|
||||
@@ -48,8 +49,8 @@ public class TokenCreateTable extends ForwardingTable<Player, Card, Integer> {
|
||||
}
|
||||
|
||||
if (validOwner != null) {
|
||||
filteredPlayer = Lists.newArrayList(Iterables.filter(rowKeySet(),
|
||||
GameObjectPredicates.restriction(validOwner.split(","), host.getController(), host, ctb)));
|
||||
Predicate<GameObject> restriction = GameObjectPredicates.restriction(validOwner.split(","), host.getController(), host, ctb);
|
||||
filteredPlayer = rowKeySet().stream().filter(restriction).collect(Collectors.toList());
|
||||
if (filteredPlayer.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -34,6 +34,7 @@ import forge.util.collect.FCollection;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -385,7 +386,8 @@ public class SpellAbilityCondition extends SpellAbilityVariables {
|
||||
}
|
||||
}
|
||||
|
||||
final int left = Iterables.size(Iterables.filter(list, GameObjectPredicates.restriction(getIsPresent().split(","), activator, host, sa)));
|
||||
Predicate<GameObject> restriction = GameObjectPredicates.restriction(getIsPresent().split(","), activator, host, sa);
|
||||
final int left = (int) list.stream().filter(restriction).count();
|
||||
|
||||
final String rightString = this.getPresentCompare().substring(2);
|
||||
int right = AbilityUtils.calculateAmount(host, rightString, sa);
|
||||
@@ -416,7 +418,8 @@ public class SpellAbilityCondition extends SpellAbilityVariables {
|
||||
}
|
||||
}
|
||||
|
||||
final int left = Iterables.size(Iterables.filter(list, GameObjectPredicates.restriction(getIsPresent2().split(","), activator, host, sa)));
|
||||
Predicate<GameObject> restriction = GameObjectPredicates.restriction(getIsPresent2().split(","), activator, host, sa);
|
||||
final int left = (int) list.stream().filter(restriction).count();
|
||||
|
||||
final String rightString = this.getPresentCompare2().substring(2);
|
||||
int right = AbilityUtils.calculateAmount(host, rightString, sa);
|
||||
|
||||
@@ -38,7 +38,6 @@ import forge.game.staticability.StaticAbilityNumLoyaltyAct;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Expressions;
|
||||
import forge.util.Iterables;
|
||||
import forge.util.collect.FCollection;
|
||||
|
||||
/**
|
||||
@@ -468,7 +467,8 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
|
||||
list = new FCollection<>(game.getCardsIn(getPresentZone()));
|
||||
}
|
||||
|
||||
final int left = Iterables.size(Iterables.filter(list, GameObjectPredicates.restriction(getIsPresent().split(","), activator, c, sa)));
|
||||
Predicate<GameObject> restriction = GameObjectPredicates.restriction(getIsPresent().split(","), activator, c, sa);
|
||||
final int left = (int) list.stream().filter(restriction).count();
|
||||
|
||||
final String rightString = this.getPresentCompare().substring(2);
|
||||
int right = AbilityUtils.calculateAmount(c, rightString, sa);
|
||||
|
||||
@@ -102,7 +102,7 @@ public class TriggerHandler {
|
||||
|
||||
public final void handlePlayerDefinedDelTriggers(final Player player) {
|
||||
final List<Trigger> playerTriggers = playerDefinedDelayedTriggers.removeAll(player);
|
||||
Iterables.filter(playerTriggers, CardTraitPredicates.hasParam("ThisTurn")).forEach(thisTurnDelayedTriggers::add);
|
||||
playerTriggers.stream().filter(CardTraitPredicates.hasParam("ThisTurn")).forEach(thisTurnDelayedTriggers::add);
|
||||
delayedTriggers.addAll(playerTriggers);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import forge.card.CardDb;
|
||||
import forge.item.PaperCardPredicates;
|
||||
import forge.util.Iterables;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
@@ -356,15 +356,15 @@ public class ImportSourceAnalyzer {
|
||||
// set card pics
|
||||
//
|
||||
|
||||
private static void addSetCards(final Map<String, String> cardFileNames, final Iterable<PaperCard> library, final Predicate<PaperCard> filter) {
|
||||
for (final PaperCard c : Iterables.filter(library, filter)) {
|
||||
private static void addSetCards(final Map<String, String> cardFileNames, final CardDb library, final Predicate<PaperCard> filter) {
|
||||
library.streamAllCards().filter(filter).forEach(c -> {
|
||||
String filename = c.getCardImageKey() + ".jpg";
|
||||
cardFileNames.put(filename, filename);
|
||||
if (c.hasBackFace()) {
|
||||
filename = c.getCardAltImageKey() + ".jpg";
|
||||
cardFileNames.put(filename, filename);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Map<String, Map<String, String>> cardFileNamesBySet;
|
||||
@@ -375,8 +375,8 @@ public class ImportSourceAnalyzer {
|
||||
for (final CardEdition ce : FModel.getMagicDb().getEditions()) {
|
||||
final Map<String, String> cardFileNames = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
final Predicate<PaperCard> filter = PaperCardPredicates.printedInSet(ce.getCode());
|
||||
addSetCards(cardFileNames, FModel.getMagicDb().getCommonCards().getAllCards(), filter);
|
||||
addSetCards(cardFileNames, FModel.getMagicDb().getVariantCards().getAllCards(), filter);
|
||||
addSetCards(cardFileNames, FModel.getMagicDb().getCommonCards(), filter);
|
||||
addSetCards(cardFileNames, FModel.getMagicDb().getVariantCards(), filter);
|
||||
cardFileNamesBySet.put(ce.getCode2(), cardFileNames);
|
||||
}
|
||||
|
||||
@@ -384,14 +384,14 @@ public class ImportSourceAnalyzer {
|
||||
nameUpdates = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
final Predicate<PaperCard> predPlanes = arg0 -> arg0.getRules().getType().isPlane() || arg0.getRules().getType().isPhenomenon();
|
||||
|
||||
for (final PaperCard c : Iterables.filter(FModel.getMagicDb().getVariantCards().getAllCards(), predPlanes)) {
|
||||
FModel.getMagicDb().getVariantCards().streamAllCards().filter(predPlanes).forEach(c -> {
|
||||
String baseName = c.getCardImageKey();
|
||||
nameUpdates.put(baseName + ".full.jpg", baseName + ".jpg");
|
||||
if (c.hasBackFace()) {
|
||||
baseName = c.getCardAltImageKey();
|
||||
nameUpdates.put(baseName + ".full.jpg", baseName + ".jpg");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final CardEdition.Collection editions = FModel.getMagicDb().getEditions();
|
||||
|
||||
@@ -16,12 +16,13 @@ import forge.model.FModel;
|
||||
import forge.screens.home.quest.DialogChooseFormats;
|
||||
import forge.screens.home.quest.DialogChooseSets;
|
||||
import forge.screens.match.controllers.CDetailPicture;
|
||||
import forge.util.Iterables;
|
||||
import forge.util.Localizer;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* ItemManager for cards
|
||||
@@ -76,7 +77,8 @@ public class CardManager extends ItemManager<PaperCard> {
|
||||
continue; // skip card
|
||||
|
||||
// Try to retain only those editions accepted by the current Card Art Preference Policy
|
||||
List<CardEdition> acceptedEditions = Lists.newArrayList(Iterables.filter(entriesByEdition.keySet(), ed -> StaticData.instance().getCardArtPreference().accept(ed)));
|
||||
Predicate<CardEdition> editionPredicate = ed -> StaticData.instance().getCardArtPreference().accept(ed);
|
||||
List<CardEdition> acceptedEditions = entriesByEdition.keySet().stream().filter(editionPredicate).collect(Collectors.toList());
|
||||
|
||||
// If policy too strict, fall back to getting all editions.
|
||||
if (acceptedEditions.size() == 0)
|
||||
|
||||
@@ -1007,7 +1007,7 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel implem
|
||||
this.model.addItems(items);
|
||||
}
|
||||
else if (useFilter) {
|
||||
final Predicate<Entry<T, Integer>> pred = x -> this.filterPredicate.test(x.getKey());;
|
||||
final Predicate<Entry<T, Integer>> pred = x -> this.filterPredicate.test(x.getKey());
|
||||
this.model.addItems(Iterables.filter(this.pool, pred));
|
||||
}
|
||||
else if (this.wantUnique) {
|
||||
|
||||
@@ -3,8 +3,7 @@ package forge.planarconquestgenerate;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import forge.GuiDesktop;
|
||||
import forge.StaticData;
|
||||
@@ -24,7 +23,6 @@ import forge.item.PaperCardPredicates;
|
||||
import forge.localinstance.properties.ForgeConstants;
|
||||
import forge.localinstance.properties.ForgePreferences;
|
||||
import forge.model.FModel;
|
||||
import forge.util.Iterables;
|
||||
|
||||
public class PlanarConquestCommanderGeneraterGA extends PlanarConquestGeneraterGA {
|
||||
|
||||
@@ -75,14 +73,14 @@ public class PlanarConquestCommanderGeneraterGA extends PlanarConquestGeneraterG
|
||||
cards.add(StaticData.instance().getCommonCards().getUniqueByName(cardName));
|
||||
}
|
||||
|
||||
Iterable<PaperCard> filtered= Iterables.filter(cards,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS
|
||||
List<PaperCard> filteredList = cards.stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS
|
||||
.and(CardRulesPredicates.IS_PLANESWALKER)
|
||||
//.and(CardRulesPredicates.IS_LEGENDARY)
|
||||
).and(gameFormat.getFilterPrinted())
|
||||
);
|
||||
))
|
||||
.filter(gameFormat.getFilterPrinted())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<PaperCard> filteredList = Lists.newArrayList(filtered);
|
||||
rankedList = CardRanker.rankCardsInDeck(filteredList);
|
||||
List<Deck> decks = new ArrayList<>();
|
||||
for(PaperCard card: rankedList.subList(0,cardsToUse)){
|
||||
|
||||
@@ -4,13 +4,12 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import forge.item.PaperCardPredicates;
|
||||
import forge.util.*;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.GuiDesktop;
|
||||
import forge.LobbyPlayer;
|
||||
import forge.StaticData;
|
||||
@@ -106,13 +105,12 @@ public class PlanarConquestGeneraterGA extends AbstractGeneticAlgorithm<Deck> {
|
||||
cards.add(StaticData.instance().getCommonCards().getUniqueByName(cardName));
|
||||
}
|
||||
|
||||
Iterable<PaperCard> filtered= Iterables.filter(cards,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS
|
||||
.and(CardRulesPredicates.IS_NON_LAND)
|
||||
).and(gameFormat.getFilterPrinted())
|
||||
);
|
||||
List<PaperCard> filteredList = cards.stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS
|
||||
.and(CardRulesPredicates.IS_NON_LAND)))
|
||||
.filter(gameFormat.getFilterPrinted())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<PaperCard> filteredList = Lists.newArrayList(filtered);
|
||||
setRankedList(CardRanker.rankCardsInDeck(filteredList));
|
||||
List<Deck> decks = new ArrayList<>();
|
||||
for(PaperCard card: getRankedList().subList(0,cardsToUse)){
|
||||
|
||||
@@ -3,8 +3,7 @@ package forge.planarconquestgenerate;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import forge.GuiDesktop;
|
||||
import forge.StaticData;
|
||||
@@ -23,7 +22,6 @@ import forge.item.PaperCardPredicates;
|
||||
import forge.localinstance.properties.ForgeConstants;
|
||||
import forge.localinstance.properties.ForgePreferences;
|
||||
import forge.model.FModel;
|
||||
import forge.util.Iterables;
|
||||
|
||||
public class PlanarConquestTribalGeneraterGA extends PlanarConquestGeneraterGA {
|
||||
|
||||
@@ -77,14 +75,13 @@ public class PlanarConquestTribalGeneraterGA extends PlanarConquestGeneraterGA {
|
||||
cards.add(StaticData.instance().getCommonCards().getUniqueByName(cardName));
|
||||
}
|
||||
|
||||
Iterable<PaperCard> filteredTribe= Iterables.filter(cards,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS
|
||||
List<PaperCard> filteredListTribe = cards.stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS
|
||||
.and(CardRulesPredicates.hasCreatureType("Pirate"))
|
||||
.and(CardRulesPredicates.IS_CREATURE)
|
||||
).and(gameFormat.getFilterPrinted())
|
||||
);
|
||||
.and(CardRulesPredicates.IS_CREATURE)))
|
||||
.filter(gameFormat.getFilterPrinted())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<PaperCard> filteredListTribe = Lists.newArrayList(filteredTribe);
|
||||
rankedList = CardRanker.rankCardsInDeck(filteredListTribe);
|
||||
List<Deck> decks = new ArrayList<>();
|
||||
for(PaperCard card: rankedList.subList(0,cardsToUse)){
|
||||
|
||||
@@ -2,7 +2,6 @@ package forge.adventure.util;
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.google.common.collect.Lists;
|
||||
import forge.StaticData;
|
||||
import forge.adventure.data.ConfigData;
|
||||
import forge.adventure.data.GeneratedDeckData;
|
||||
@@ -27,6 +26,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static forge.adventure.data.RewardData.generateAllCards;
|
||||
|
||||
@@ -804,15 +804,22 @@ public class CardUtil {
|
||||
}
|
||||
|
||||
public static PaperCard getCardByName(String cardName) {
|
||||
List<PaperCard> validCards = Lists.newArrayList(Iterables.filter(getFullCardPool(Config.instance().getSettingData().useAllCardVariants),
|
||||
input -> input.getCardName().equals(cardName)));
|
||||
List<PaperCard> validCards;
|
||||
//Faster to ask the CardDB for a card name than it is to search the pool.
|
||||
if (Config.instance().getSettingData().useAllCardVariants)
|
||||
validCards = FModel.getMagicDb().getCommonCards().getAllCards(cardName);
|
||||
else
|
||||
validCards = FModel.getMagicDb().getCommonCards().getUniqueCardsNoAlt(cardName);
|
||||
|
||||
return validCards.get(Current.world().getRandom().nextInt(validCards.size()));
|
||||
}
|
||||
|
||||
public static PaperCard getCardByNameAndEdition(String cardName, String edition) {
|
||||
List<PaperCard> validCards = Lists.newArrayList(Iterables.filter(getFullCardPool(Config.instance().getSettingData().useAllCardVariants),
|
||||
input -> input.getCardName().equals(cardName) && input.getEdition().equals(edition)));
|
||||
List<PaperCard> cardPool = Config.instance().getSettingData().useAllCardVariants
|
||||
? FModel.getMagicDb().getCommonCards().getAllCards(cardName)
|
||||
: FModel.getMagicDb().getCommonCards().getUniqueCardsNoAlt(cardName);
|
||||
List<PaperCard> validCards = cardPool.stream()
|
||||
.filter(input -> input.getEdition().equals(edition)).collect(Collectors.toList());
|
||||
|
||||
if (validCards.isEmpty()) {
|
||||
System.err.println("Unexpected behavior: tried to call getCardByNameAndEdition for card " + cardName + " from the edition " + edition + ", but didn't find it in the DB. A random existing instance will be returned.");
|
||||
|
||||
@@ -9,13 +9,11 @@ import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import forge.item.PaperCardPredicates;
|
||||
import forge.util.Iterables;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.deck.io.CardThemedMatrixIO;
|
||||
import forge.deck.io.DeckStorage;
|
||||
@@ -73,9 +71,9 @@ public final class CardRelationMatrixGenerator {
|
||||
ForgeConstants.DECK_GEN_DIR, false),
|
||||
true);
|
||||
|
||||
final Iterable<PaperCard> cards = Iterables.filter(format.getAllCards(),
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND));
|
||||
List<PaperCard> cardList = Lists.newArrayList(cards);
|
||||
List<PaperCard> cardList = format.getAllCards().stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND))
|
||||
.collect(Collectors.toList());
|
||||
cardList.add(FModel.getMagicDb().getCommonCards().getCard("Wastes"));
|
||||
Map<String, Integer> cardIntegerMap = new HashMap<>();
|
||||
Map<Integer, PaperCard> integerCardMap = new HashMap<>();
|
||||
@@ -88,18 +86,19 @@ public final class CardRelationMatrixGenerator {
|
||||
|
||||
for (PaperCard card:cardList){
|
||||
for (Deck deck:decks){
|
||||
if (deck.getMain().contains(card)){
|
||||
for (PaperCard pairCard:Iterables.filter(deck.getMain().toFlatList(),
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND))){
|
||||
if (!pairCard.getName().equals(card.getName())){
|
||||
if (deck.getMain().contains(card)) {
|
||||
String cardName = card.getName();
|
||||
deck.getMain().toFlatList().stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND))
|
||||
.filter(pairCard -> !pairCard.getName().equals(cardName))
|
||||
.forEach(pairCard -> {
|
||||
try {
|
||||
int old = matrix[cardIntegerMap.get(card.getName())][cardIntegerMap.get(pairCard.getName())];
|
||||
matrix[cardIntegerMap.get(card.getName())][cardIntegerMap.get(pairCard.getName())] = old + 1;
|
||||
}catch (NullPointerException ne){
|
||||
int old = matrix[cardIntegerMap.get(cardName)][cardIntegerMap.get(pairCard.getName())];
|
||||
matrix[cardIntegerMap.get(cardName)][cardIntegerMap.get(pairCard.getName())] = old + 1;
|
||||
} catch (NullPointerException ne) {
|
||||
//Todo: Not sure what was failing here
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,9 +141,9 @@ public final class CardRelationMatrixGenerator {
|
||||
true);
|
||||
|
||||
//get all cards
|
||||
final Iterable<PaperCard> cards = Iterables.filter(FModel.getMagicDb().getCommonCards().getUniqueCards(),
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND));
|
||||
List<PaperCard> cardList = Lists.newArrayList(cards);
|
||||
List<PaperCard> cardList = FModel.getMagicDb().getCommonCards().streamUniqueCards()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND))
|
||||
.collect(Collectors.toList());
|
||||
cardList.add(FModel.getMagicDb().getCommonCards().getCard("Wastes"));
|
||||
Map<String, Integer> cardIntegerMap = new HashMap<>();
|
||||
Map<Integer, PaperCard> integerCardMap = new HashMap<>();
|
||||
@@ -157,7 +156,7 @@ public final class CardRelationMatrixGenerator {
|
||||
}
|
||||
|
||||
//filter to just legal commanders
|
||||
List<PaperCard> legends = Lists.newArrayList(Iterables.filter(cardList, format.isLegalCommanderPredicate()));
|
||||
List<PaperCard> legends = cardList.stream().filter(format.isLegalCommanderPredicate()).collect(Collectors.toList());
|
||||
|
||||
//generate lookups for legends to link commander names to matrix rows
|
||||
for (int i=0; i<legends.size(); ++i){
|
||||
@@ -199,25 +198,25 @@ public final class CardRelationMatrixGenerator {
|
||||
//update the matrix by incrementing the connectivity count for each card in the deck
|
||||
public static void updateLegendMatrix(Deck deck, PaperCard legend, Map<String, Integer> cardIntegerMap,
|
||||
Map<String, Integer> legendIntegerMap, int[][] matrix){
|
||||
for (PaperCard pairCard:Iterables.filter(deck.getMain().toFlatList(),
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND))){
|
||||
if (!pairCard.getName().equals(legend.getName())){
|
||||
String cardName = legend.getName();
|
||||
deck.getMain().toFlatList().stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND))
|
||||
.filter(pairCard -> !pairCard.getName().equals(cardName))
|
||||
.forEach(pairCard -> {
|
||||
try {
|
||||
int old = matrix[legendIntegerMap.get(legend.getName())][cardIntegerMap.get(pairCard.getName())];
|
||||
matrix[legendIntegerMap.get(legend.getName())][cardIntegerMap.get(pairCard.getName())] = old + 1;
|
||||
}catch (NullPointerException ne){
|
||||
int old = matrix[legendIntegerMap.get(cardName)][cardIntegerMap.get(pairCard.getName())];
|
||||
matrix[legendIntegerMap.get(cardName)][cardIntegerMap.get(pairCard.getName())] = old + 1;
|
||||
} catch (NullPointerException ne) {
|
||||
//Todo: Not sure what was failing here
|
||||
ne.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
//add partner commanders to matrix
|
||||
if(deck.getCommanders().size()>1){
|
||||
for(PaperCard partner:deck.getCommanders()){
|
||||
if(!partner.equals(legend)){
|
||||
int old = matrix[legendIntegerMap.get(legend.getName())][cardIntegerMap.get(partner.getName())];
|
||||
matrix[legendIntegerMap.get(legend.getName())][cardIntegerMap.get(partner.getName())] = old + 1;
|
||||
int old = matrix[legendIntegerMap.get(cardName)][cardIntegerMap.get(partner.getName())];
|
||||
matrix[legendIntegerMap.get(cardName)][cardIntegerMap.get(partner.getName())] = old + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package forge.deck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRules;
|
||||
@@ -13,7 +14,6 @@ import forge.item.PaperCard;
|
||||
import forge.item.PaperCardPredicates;
|
||||
import forge.model.FModel;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.Iterables;
|
||||
|
||||
/**
|
||||
* Created by maustin on 09/05/2017.
|
||||
@@ -23,11 +23,11 @@ public class CommanderDeckGenerator extends DeckProxy implements Comparable<Comm
|
||||
if (format.equals(DeckFormat.Brawl)){
|
||||
return getBrawlDecks(format, isForAi, isCardGen);
|
||||
}
|
||||
ItemPool uniqueCards;
|
||||
ItemPool<PaperCard> uniqueCards;
|
||||
if (isCardGen){
|
||||
uniqueCards = new ItemPool<>(PaperCard.class);
|
||||
String matrixKey = (format.equals(DeckFormat.TinyLeaders) ? DeckFormat.Commander : format).toString(); //use Commander for Tiny Leaders
|
||||
HashMap matrixPool = CardRelationMatrixGenerator.cardPools.get(matrixKey);
|
||||
HashMap<String, List<Map.Entry<PaperCard, Integer>>> matrixPool = CardRelationMatrixGenerator.cardPools.get(matrixKey);
|
||||
if (matrixPool != null) {
|
||||
Iterable<String> legendNames = matrixPool.keySet();
|
||||
for (String legendName : legendNames) {
|
||||
@@ -39,18 +39,15 @@ public class CommanderDeckGenerator extends DeckProxy implements Comparable<Comm
|
||||
uniqueCards = ItemPool.createFrom(FModel.getMagicDb().getCommonCards().getUniqueCards(), PaperCard.class);
|
||||
}
|
||||
Predicate<CardRules> canPlay = isForAi ? DeckGeneratorBase.AI_CAN_PLAY : CardRulesPredicates.IS_KEPT_IN_RANDOM_DECKS;
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterable<PaperCard> legends = Iterables.filter(uniqueCards.toFlatList(), format.isLegalCommanderPredicate()
|
||||
.and(PaperCardPredicates.fromRules(canPlay)));
|
||||
final List<DeckProxy> decks = new ArrayList<>();
|
||||
for (PaperCard legend: legends) {
|
||||
decks.add(new CommanderDeckGenerator(legend, format, isForAi, isCardGen));
|
||||
}
|
||||
return decks;
|
||||
return uniqueCards.toFlatList().stream()
|
||||
.filter(format.isLegalCommanderPredicate())
|
||||
.filter(PaperCardPredicates.fromRules(canPlay))
|
||||
.map(legend -> new CommanderDeckGenerator(legend, format, isForAi, isCardGen))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<DeckProxy> getBrawlDecks(final DeckFormat format, boolean isForAi, boolean isCardGen){
|
||||
ItemPool uniqueCards;
|
||||
ItemPool<PaperCard> uniqueCards;
|
||||
if (isCardGen){
|
||||
uniqueCards = new ItemPool<>(PaperCard.class);
|
||||
//TODO: update to actual Brawl model from real Brawl decks
|
||||
@@ -63,14 +60,11 @@ public class CommanderDeckGenerator extends DeckProxy implements Comparable<Comm
|
||||
uniqueCards = ItemPool.createFrom(FModel.getMagicDb().getCommonCards().getUniqueCards(), PaperCard.class);
|
||||
}
|
||||
Predicate<CardRules> canPlay = isForAi ? DeckGeneratorBase.AI_CAN_PLAY : CardRulesPredicates.IS_KEPT_IN_RANDOM_DECKS;
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterable<PaperCard> legends = Iterables.filter(uniqueCards.toFlatList(), format.isLegalCardPredicate()
|
||||
.and(PaperCardPredicates.fromRules(CardRulesPredicates.CAN_BE_BRAWL_COMMANDER.and(canPlay))));
|
||||
final List<DeckProxy> decks = new ArrayList<>();
|
||||
for (PaperCard legend: legends) {
|
||||
decks.add(new CommanderDeckGenerator(legend, format, isForAi, isCardGen));
|
||||
}
|
||||
return decks;
|
||||
return uniqueCards.toFlatList().stream()
|
||||
.filter(format.isLegalCardPredicate())
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.CAN_BE_BRAWL_COMMANDER.and(canPlay)))
|
||||
.map(legend -> new CommanderDeckGenerator(legend, format, isForAi, isCardGen))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private final PaperCard legend;
|
||||
|
||||
@@ -841,7 +841,7 @@ public class DeckgenUtil {
|
||||
|
||||
// determine how many additional lands we need, but don't take lands already in deck into consideration,
|
||||
// or we risk incorrectly determining the target deck size
|
||||
int numLands = Iterables.size(Iterables.filter(cards, PaperCardPredicates.fromRules(CardRulesPredicates.IS_LAND)));
|
||||
int numLands = (int) cards.stream().filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_LAND)).count();
|
||||
int sizeNoLands = cards.size() - numLands;
|
||||
|
||||
// attempt to determine if building for sealed, constructed or EDH
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.gamemodes.limited;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -11,7 +12,6 @@ import forge.deck.generation.DeckGenPool;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.PaperCardPredicates;
|
||||
import forge.model.FModel;
|
||||
import forge.util.Iterables;
|
||||
|
||||
/**
|
||||
* Created by maustin on 28/02/2018.
|
||||
@@ -25,9 +25,9 @@ public class CardThemedCommanderDeckBuilder extends CardThemedDeckBuilder {
|
||||
secondKeyCard = partner0;
|
||||
// remove Unplayables
|
||||
if(isForAI) {
|
||||
final Iterable<PaperCard> playables = Iterables.filter(availableList,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS));
|
||||
this.aiPlayables = Lists.newArrayList(playables);
|
||||
this.aiPlayables = availableList.stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS))
|
||||
.collect(Collectors.toList());
|
||||
}else{
|
||||
this.aiPlayables = Lists.newArrayList(availableList);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.gamemodes.limited;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -29,9 +30,9 @@ public class CardThemedConquestDeckBuilder extends CardThemedDeckBuilder {
|
||||
secondKeyCard = null;
|
||||
// remove Unplayables
|
||||
if(isForAI) {
|
||||
final Iterable<PaperCard> playables = Iterables.filter(availableList,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS));
|
||||
this.aiPlayables = Lists.newArrayList(playables);
|
||||
this.aiPlayables = availableList.stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS))
|
||||
.collect(Collectors.toList());
|
||||
}else{
|
||||
this.aiPlayables = Lists.newArrayList(availableList);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -104,9 +105,9 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
||||
this.isForAI = isForAI;
|
||||
// remove Unplayables
|
||||
if(isForAI) {
|
||||
final Iterable<PaperCard> playables = Iterables.filter(availableList,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS));
|
||||
this.aiPlayables = Lists.newArrayList(playables);
|
||||
this.aiPlayables = availableList.stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_DECKS))
|
||||
.collect(Collectors.toList());
|
||||
}else{
|
||||
this.aiPlayables = Lists.newArrayList(availableList);
|
||||
}
|
||||
@@ -188,9 +189,9 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
||||
System.out.println(keyCard.getName());
|
||||
System.out.println("Colors: " + colors.toEnumSet().toString());
|
||||
}
|
||||
Iterable<PaperCard> colorList = Iterables.filter(aiPlayables,
|
||||
PaperCardPredicates.fromRules(hasColor));
|
||||
rankedColorList = Lists.newArrayList(colorList);
|
||||
rankedColorList = aiPlayables.stream()
|
||||
.filter(PaperCardPredicates.fromRules(hasColor))
|
||||
.collect(Collectors.toList());
|
||||
onColorCreaturesAndSpells = Iterables.filter(rankedColorList,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_CREATURE
|
||||
.or(CardRulesPredicates.IS_NON_CREATURE_SPELL)));
|
||||
@@ -318,11 +319,11 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
||||
|
||||
//Add remaining non-land colour matching cards to sideboard
|
||||
final CardPool cp = result.getOrCreate(DeckSection.Sideboard);
|
||||
Iterable<PaperCard> potentialSideboard = Iterables.filter(aiPlayables,
|
||||
PaperCardPredicates.fromRules(hasColor.and(CardRulesPredicates.IS_NON_LAND)));
|
||||
Iterator<PaperCard> potentialSideboard = aiPlayables.stream()
|
||||
.filter(PaperCardPredicates.fromRules(hasColor.and(CardRulesPredicates.IS_NON_LAND))).iterator();
|
||||
int i=0;
|
||||
while(i<15 && potentialSideboard.iterator().hasNext()){
|
||||
PaperCard sbCard = potentialSideboard.iterator().next();
|
||||
while(i<15 && potentialSideboard.hasNext()){
|
||||
PaperCard sbCard = potentialSideboard.next();
|
||||
cp.add(sbCard);
|
||||
aiPlayables.remove(sbCard);
|
||||
rankedColorList.remove(sbCard);
|
||||
@@ -398,8 +399,9 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
||||
}
|
||||
// Add the second keycard if not land
|
||||
if(secondKeyCard!=null && !secondKeyCard.getRules().getMainPart().getType().isLand()) {
|
||||
Iterable<PaperCard> secondKeyCards = Iterables.filter(aiPlayables, PaperCardPredicates.name(secondKeyCard.getName()));
|
||||
final List<PaperCard> keyCardList = Lists.newArrayList(secondKeyCards);
|
||||
final List<PaperCard> keyCardList = aiPlayables.stream()
|
||||
.filter(PaperCardPredicates.name(secondKeyCard.getName()))
|
||||
.collect(Collectors.toList());
|
||||
deckList.addAll(keyCardList);
|
||||
aiPlayables.removeAll(keyCardList);
|
||||
rankedColorList.removeAll(keyCardList);
|
||||
@@ -418,8 +420,9 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
||||
}
|
||||
// Add the deck card
|
||||
if(secondKeyCard!=null && secondKeyCard.getRules().getMainPart().getType().isLand()) {
|
||||
Iterable<PaperCard> secondKeyCards = Iterables.filter(aiPlayables, PaperCardPredicates.name(secondKeyCard.getName()));
|
||||
final List<PaperCard> keyCardList = Lists.newArrayList(secondKeyCards);
|
||||
final List<PaperCard> keyCardList = aiPlayables.stream()
|
||||
.filter(PaperCardPredicates.name(secondKeyCard.getName()))
|
||||
.collect(Collectors.toList());
|
||||
deckList.addAll(keyCardList);
|
||||
aiPlayables.removeAll(keyCardList);
|
||||
rankedColorList.removeAll(keyCardList);
|
||||
@@ -444,7 +447,7 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
||||
* If evolving wilds is in the deck and there are fewer than 4 spaces for basic lands - remove evolving wilds
|
||||
*/
|
||||
protected void checkEvolvingWilds(){
|
||||
List<PaperCard> evolvingWilds = Lists.newArrayList(Iterables.filter(deckList, PaperCardPredicates.name("Evolving Wilds")));
|
||||
List<PaperCard> evolvingWilds = deckList.stream().filter(PaperCardPredicates.name("Evolving Wilds")).collect(Collectors.toList());
|
||||
if((evolvingWilds.size()>0 && landsNeeded<4 ) || colors.countColors()<2){
|
||||
deckList.removeAll(evolvingWilds);
|
||||
landsNeeded=landsNeeded+evolvingWilds.size();
|
||||
@@ -497,9 +500,9 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
||||
}
|
||||
|
||||
protected void addLowCMCCard(){
|
||||
final Iterable<PaperCard> nonLands = Iterables.filter(rankedColorList,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_NON_LAND));
|
||||
final PaperCard card = Iterables.getFirst(nonLands, null);
|
||||
final PaperCard card = rankedColorList.stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_NON_LAND))
|
||||
.findFirst().orElse(null);
|
||||
if (card != null) {
|
||||
deckList.add(card);
|
||||
aiPlayables.remove(card);
|
||||
@@ -665,17 +668,10 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
||||
* counts of lands needed, by color
|
||||
*/
|
||||
private void addLands(final int[] clrCnts) {
|
||||
// basic lands that are available in the deck
|
||||
final Iterable<PaperCard> basicLands = Iterables.filter(aiPlayables, PaperCardPredicates.fromRules(CardRulesPredicates.IS_BASIC_LAND));
|
||||
|
||||
// total of all ClrCnts
|
||||
int totalColor = 0;
|
||||
int numColors = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
totalColor += clrCnts[i];
|
||||
if (clrCnts[i] > 0) {
|
||||
numColors++;
|
||||
}
|
||||
}
|
||||
// add one of each land required first so that any rounding errors do not remove the only land of a colour
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@@ -821,9 +817,6 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
||||
minBasics=Math.round((MyRandom.getRandom().nextInt(8)+6)*((float) targetSize) / 60);
|
||||
}
|
||||
|
||||
lands = Iterables.filter(aiPlayables,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_NONBASIC_LAND));
|
||||
|
||||
for (final PaperCard card : lands) {
|
||||
if (landsNeeded > minBasics) {
|
||||
// Use only lands that are within our colors
|
||||
@@ -922,16 +915,10 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
creatureCosts.put(i, 0);
|
||||
}
|
||||
final Predicate<PaperCard> filter = PaperCardPredicates.fromRules(CardRulesPredicates.IS_CREATURE);
|
||||
for (final IPaperCard creature : Iterables.filter(deckList, filter)) {
|
||||
int cmc = creature.getRules().getManaCost().getCMC();
|
||||
if (cmc < 1) {
|
||||
cmc = 1;
|
||||
} else if (cmc > 6) {
|
||||
cmc = 6;
|
||||
}
|
||||
creatureCosts.put(cmc, creatureCosts.get(cmc) + 1);
|
||||
}
|
||||
deckList.stream().filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_CREATURE))
|
||||
.mapToInt(c -> c.getRules().getManaCost().getCMC())
|
||||
.map(cmc -> Math.min(Math.max(cmc, 1), 6))
|
||||
.forEach(cmc -> creatureCosts.put(cmc, creatureCosts.get(cmc) + 1));
|
||||
|
||||
List<PaperCard> creaturesToAdd = new ArrayList<>();
|
||||
for (final PaperCard card : creatures) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package forge.gamemodes.limited;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -76,15 +77,15 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
|
||||
this.colors = pClrs.getChosenColors();
|
||||
|
||||
// remove Unplayables
|
||||
final Iterable<PaperCard> playables = Iterables.filter(availableList,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_LIMITED_DECKS));
|
||||
this.aiPlayables = Lists.newArrayList(playables);
|
||||
this.aiPlayables = availableList.stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_KEPT_IN_AI_LIMITED_DECKS))
|
||||
.collect(Collectors.toList());
|
||||
this.availableList.removeAll(aiPlayables);
|
||||
|
||||
// keep Conspiracies in a separate list
|
||||
final Iterable<PaperCard> conspiracies = Iterables.filter(aiPlayables,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.coreType(true, "Conspiracy")));
|
||||
this.draftedConspiracies = Lists.newArrayList(conspiracies);
|
||||
this.draftedConspiracies = aiPlayables.stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.coreType(true, "Conspiracy")))
|
||||
.collect(Collectors.toList());
|
||||
this.aiPlayables.removeAll(draftedConspiracies);
|
||||
|
||||
findBasicLandSets();
|
||||
@@ -164,9 +165,9 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
|
||||
// 6. If there are still on-color cards, and the average cmc is low, add
|
||||
// an extra.
|
||||
if (deckList.size() == numSpellsNeeded && getAverageCMC(deckList) < 4) {
|
||||
final Iterable<PaperCard> nonLands = Iterables.filter(rankedColorList,
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.IS_NON_LAND));
|
||||
final PaperCard card = Iterables.getFirst(nonLands, null);
|
||||
final PaperCard card = rankedColorList.stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_NON_LAND))
|
||||
.findFirst().orElse(null);
|
||||
if (card != null) {
|
||||
deckList.add(card);
|
||||
aiPlayables.remove(card);
|
||||
@@ -665,15 +666,10 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
|
||||
creatureCosts.put(i, 0);
|
||||
}
|
||||
final Predicate<PaperCard> filter = PaperCardPredicates.fromRules(CardRulesPredicates.IS_CREATURE);
|
||||
for (final IPaperCard creature : Iterables.filter(deckList, filter)) {
|
||||
int cmc = creature.getRules().getManaCost().getCMC();
|
||||
if (cmc < 1) {
|
||||
cmc = 1;
|
||||
} else if (cmc > 6) {
|
||||
cmc = 6;
|
||||
}
|
||||
creatureCosts.put(cmc, creatureCosts.get(cmc) + 1);
|
||||
}
|
||||
deckList.stream().filter(filter)
|
||||
.mapToInt(creature -> creature.getRules().getManaCost().getCMC())
|
||||
.map(cmc -> Math.max(1, Math.min(cmc, 6)))
|
||||
.forEach(cmc -> creatureCosts.put(cmc, creatureCosts.get(cmc) + 1));
|
||||
|
||||
List<PaperCard> creaturesToAdd = new ArrayList<>();
|
||||
for (final PaperCard card : creatures) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import forge.util.Iterables;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LimitedPlayer {
|
||||
// A Player class for inside some type of limited environment, like Draft.
|
||||
@@ -731,7 +732,9 @@ public class LimitedPlayer {
|
||||
public void addSingleBoosterPack() {
|
||||
// if this is just a normal draft, allow picking a pack from any set
|
||||
// If this is adventure or quest or whatever then we should limit it to something
|
||||
List<CardEdition> possibleEditions = Lists.newArrayList(Iterables.filter(FModel.getMagicDb().getEditions(), CardEdition.Predicates.CAN_MAKE_BOOSTER));
|
||||
List<CardEdition> possibleEditions = FModel.getMagicDb().getEditions().stream()
|
||||
.filter(CardEdition.Predicates.CAN_MAKE_BOOSTER)
|
||||
.collect(Collectors.toList());
|
||||
CardEdition edition = chooseEdition(possibleEditions);
|
||||
if (edition == null) {
|
||||
addLog(name() + " chose not to add a booster pack to the draft.");
|
||||
|
||||
@@ -10,7 +10,6 @@ import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.PaperCardPredicates;
|
||||
import forge.util.Iterables;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
public class WinstonDraft extends BoosterDraft {
|
||||
@@ -41,9 +40,9 @@ public class WinstonDraft extends BoosterDraft {
|
||||
for (final Supplier<List<PaperCard>> supply : this.product) {
|
||||
for (int j = 0; j < NUM_PLAYERS; j++) {
|
||||
// Remove Basic Lands from draft for simplicity
|
||||
for (final PaperCard paperCard : Iterables.filter(supply.get(), PaperCardPredicates.IS_BASIC_LAND.negate())) {
|
||||
this.deck.add(paperCard);
|
||||
}
|
||||
supply.get().stream()
|
||||
.filter(PaperCardPredicates.IS_BASIC_LAND.negate())
|
||||
.forEach(this.deck::add);
|
||||
}
|
||||
}
|
||||
Collections.shuffle(this.deck, MyRandom.getRandom());
|
||||
|
||||
@@ -156,7 +156,7 @@ public class ConquestUtil {
|
||||
if (colorIdentity != MagicColor.ALL_COLORS) {
|
||||
Predicate<PaperCard> pred = DeckFormat.Commander.isLegalCardForCommanderPredicate(deck.getCommanders());
|
||||
|
||||
availableCards.retainAll(Lists.newArrayList(Iterables.filter(availableCards, pred)));
|
||||
availableCards.removeIf(pred.negate());
|
||||
}
|
||||
|
||||
//create pool from available cards
|
||||
|
||||
@@ -21,14 +21,13 @@ import static forge.gamemodes.quest.QuestUtilCards.isLegalInQuestFormat;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import forge.item.*;
|
||||
import forge.util.Iterables;
|
||||
import forge.util.Predicates;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardRulesPredicates;
|
||||
@@ -121,7 +120,7 @@ public final class BoosterUtils {
|
||||
filter = formatStartingPool.getFilterPrinted();
|
||||
}
|
||||
|
||||
final List<PaperCard> cardPool = Lists.newArrayList(Iterables.filter(FModel.getMagicDb().getCommonCards().getAllNonPromoCards(), filter));
|
||||
final List<PaperCard> cardPool = FModel.getMagicDb().getCommonCards().streamAllNonPromoCards().filter(filter).collect(Collectors.toList());
|
||||
|
||||
if (userPrefs != null && userPrefs.grantCompleteSet()) {
|
||||
for (PaperCard card : cardPool) {
|
||||
@@ -304,7 +303,7 @@ public final class BoosterUtils {
|
||||
Predicate<CardRules> predicateRules = CardRulesPredicates.cost(StringOp.CONTAINS_IC, "p/");
|
||||
Predicate<PaperCard> predicateCard = PaperCardPredicates.fromRules(predicateRules);
|
||||
|
||||
int size = Iterables.size(Iterables.filter(cardPool, predicateCard));
|
||||
int size = (int) cardPool.stream().filter(predicateCard).count();
|
||||
int totalSize = cardPool.size();
|
||||
|
||||
double phyrexianAmount = (double) size / totalSize;
|
||||
@@ -326,7 +325,7 @@ public final class BoosterUtils {
|
||||
//Adjust for the number of multicolored possibilities. This prevents flooding of non-selected
|
||||
//colors if multicolored cards aren't in the selected sets. The more multi-colored cards in the
|
||||
//sets, the more that will be selected.
|
||||
if (usedMulticolor / 8 < Iterables.size(Iterables.filter(cardPool, predicateCard))) {
|
||||
if (usedMulticolor / 8 < cardPool.stream().filter(predicateCard).count()) {
|
||||
colorFilters.add(predicateRules);
|
||||
usedMulticolor++;
|
||||
} else {
|
||||
@@ -490,7 +489,7 @@ public final class BoosterUtils {
|
||||
|
||||
PrintSheet ps = new PrintSheet("Quest rewards");
|
||||
Predicate<PaperCard> predicate = preds.size() == 1 ? preds.get(0) : Predicates.and(preds);
|
||||
ps.addAll(Iterables.filter(FModel.getMagicDb().getCommonCards().getAllNonPromoCards(), predicate));
|
||||
FModel.getMagicDb().getCommonCards().streamAllNonPromoCards().filter(predicate).forEach(ps::add);
|
||||
rewards.addAll(ps.random(qty, true));
|
||||
} else if (temp.length == 2 && temp[0].equalsIgnoreCase("duplicate") && temp[1].equalsIgnoreCase("card")) {
|
||||
// Type 2: a duplicate card of the players choice
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.util.function.Predicate;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.Iterables;
|
||||
|
||||
/**
|
||||
* Resolves a card chooser InventoryItem into a CardPrinted.
|
||||
@@ -109,10 +108,8 @@ public class QuestRewardCardChooser extends QuestRewardCard {
|
||||
} else if (type == poolType.predicateFilter) {
|
||||
List<PaperCard> cardChoices = new ArrayList<>();
|
||||
|
||||
for (final PaperCard card : Iterables.filter(FModel.getMagicDb().getCommonCards().getAllCards(), predicates)) {
|
||||
cardChoices.add(card);
|
||||
}
|
||||
Collections.sort(cardChoices);
|
||||
FModel.getMagicDb().getCommonCards().streamAllCards().filter(predicates)
|
||||
.sorted().forEach(cardChoices::add); //TODO: Once java is at 10+, can use Collectors.toUnmodifiableList
|
||||
|
||||
return Collections.unmodifiableList(cardChoices);
|
||||
} else {
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.util.function.Predicate;
|
||||
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.util.Iterables;
|
||||
|
||||
/**
|
||||
* Allows the player to choose a card from a predicate-filtered list of cards.
|
||||
@@ -60,10 +59,8 @@ public class QuestRewardCardFiltered extends QuestRewardCard {
|
||||
@Override
|
||||
public final List<PaperCard> getChoices() {
|
||||
List<PaperCard> cardChoices = new ArrayList<>();
|
||||
for (final PaperCard card : Iterables.filter(FModel.getMagicDb().getCommonCards().getAllCards(), predicates)) {
|
||||
cardChoices.add(card);
|
||||
}
|
||||
Collections.sort(cardChoices);
|
||||
FModel.getMagicDb().getCommonCards().streamAllCards().filter(predicates)
|
||||
.sorted().forEach(cardChoices::add); //TODO: Once java is at 10+, can use Collectors.toUnmodifiableList
|
||||
return Collections.unmodifiableList(cardChoices);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* This is a helper class to execute operations on QuestData. It has been
|
||||
@@ -111,10 +112,10 @@ public final class QuestUtilCards {
|
||||
wastesCodes.add("OGW");
|
||||
}
|
||||
} else {
|
||||
Iterable<CardEdition> allEditions = FModel.getMagicDb().getEditions();
|
||||
for (CardEdition edition : Iterables.filter(allEditions, CardEdition.Predicates.hasBasicLands)) {
|
||||
landCodes.add(edition.getCode());
|
||||
}
|
||||
FModel.getMagicDb().getEditions().stream()
|
||||
.filter(CardEdition.Predicates.hasBasicLands)
|
||||
.map(CardEdition::getCode)
|
||||
.forEach(landCodes::add);
|
||||
snowLandCodes.add("ICE");
|
||||
snowLandCodes.add("CSP");
|
||||
snowLandCodes.add("KHM");
|
||||
@@ -667,12 +668,9 @@ public final class QuestUtilCards {
|
||||
if (questController.getFormat() != null) {
|
||||
formatFilter = formatFilter.and(isLegalInQuestFormat(questController.getFormat()));
|
||||
}
|
||||
Iterable<CardEdition> rightEditions = Iterables.filter(FModel.getMagicDb().getEditions(), formatFilter);
|
||||
|
||||
List<CardEdition> editions = new ArrayList<>();
|
||||
for (CardEdition e : rightEditions) {
|
||||
editions.add(e);
|
||||
}
|
||||
List<CardEdition> editions = FModel.getMagicDb().getEditions().stream()
|
||||
.filter(formatFilter).collect(Collectors.toList());
|
||||
|
||||
Collections.shuffle(editions);
|
||||
|
||||
|
||||
@@ -1805,16 +1805,12 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
||||
@Override
|
||||
public ICardFace chooseSingleCardFace(final SpellAbility sa, final String message, final Predicate<ICardFace> cpp,
|
||||
final String name) {
|
||||
final Iterable<ICardFace> cardsFromDb = FModel.getMagicDb().getCommonCards().getAllFaces();
|
||||
final List<ICardFace> cards = Lists.newArrayList(Iterables.filter(cardsFromDb, cpp));
|
||||
CardFaceView cardFaceView;
|
||||
List<CardFaceView> choices = new ArrayList<>();
|
||||
for (ICardFace cardFace : cards) {
|
||||
cardFaceView = new CardFaceView(CardTranslation.getTranslatedName(cardFace.getName()), cardFace.getName());
|
||||
choices.add(cardFaceView);
|
||||
}
|
||||
Collections.sort(choices);
|
||||
cardFaceView = getGui().one(message, choices);
|
||||
List<CardFaceView> choices = FModel.getMagicDb().getCommonCards().streamAllFaces()
|
||||
.filter(cpp)
|
||||
.map(cardFace -> new CardFaceView(CardTranslation.getTranslatedName(cardFace.getName()), cardFace.getName()))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
CardFaceView cardFaceView = getGui().one(message, choices);
|
||||
return StaticData.instance().getCommonCards().getFaceByName(cardFaceView.getOracleName());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package forge.lda;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.GuiDesktop;
|
||||
import forge.StaticData;
|
||||
import forge.card.CardRulesPredicates;
|
||||
@@ -19,7 +17,6 @@ import forge.item.PaperCard;
|
||||
import forge.localinstance.properties.ForgeConstants;
|
||||
import forge.localinstance.properties.ForgePreferences;
|
||||
import forge.model.FModel;
|
||||
import forge.util.Iterables;
|
||||
import forge.util.storage.IStorage;
|
||||
import forge.util.storage.StorageImmediatelySerialized;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
@@ -27,6 +24,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static forge.lda.lda.inference.InferenceMethod.CGS;
|
||||
|
||||
@@ -290,9 +288,9 @@ public final class LDAModelGenetrator {
|
||||
true);
|
||||
|
||||
//get all cards
|
||||
final Iterable<PaperCard> cards = Iterables.filter(FModel.getMagicDb().getCommonCards().getUniqueCards(),
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND));
|
||||
List<PaperCard> cardList = Lists.newArrayList(cards);
|
||||
List<PaperCard> cardList = FModel.getMagicDb().getCommonCards().streamUniqueCards()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND))
|
||||
.collect(Collectors.toList());
|
||||
cardList.add(FModel.getMagicDb().getCommonCards().getCard("Wastes"));
|
||||
Map<String, Integer> cardIntegerMap = new HashMap<>();
|
||||
Map<Integer, PaperCard> integerCardMap = new HashMap<>();
|
||||
@@ -305,9 +303,9 @@ public final class LDAModelGenetrator {
|
||||
}
|
||||
|
||||
//filter to just legal commanders
|
||||
List<PaperCard> legends = Lists.newArrayList(Iterables.filter(cardList, PaperCardPredicates.fromRules(
|
||||
DeckFormat.Commander::isLegalCommander))
|
||||
);
|
||||
List<PaperCard> legends = cardList.stream()
|
||||
.filter(PaperCardPredicates.fromRules(DeckFormat.Commander::isLegalCommander))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//generate lookups for legends to link commander names to matrix rows
|
||||
for (int i=0; i<legends.size(); ++i){
|
||||
@@ -349,25 +347,25 @@ public final class LDAModelGenetrator {
|
||||
//update the matrix by incrementing the connectivity count for each card in the deck
|
||||
public static void updateLegendMatrix(Deck deck, PaperCard legend, Map<String, Integer> cardIntegerMap,
|
||||
Map<String, Integer> legendIntegerMap, int[][] matrix){
|
||||
for (PaperCard pairCard:Iterables.filter(deck.getMain().toFlatList(),
|
||||
PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND))){
|
||||
if (!pairCard.getName().equals(legend.getName())){
|
||||
String cardName = legend.getName();
|
||||
deck.getMain().toFlatList().stream()
|
||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.NOT_TRUE_BASIC_LAND))
|
||||
.filter(PaperCardPredicates.name(cardName).negate())
|
||||
.forEach(pairCard -> {
|
||||
try {
|
||||
int old = matrix[legendIntegerMap.get(legend.getName())][cardIntegerMap.get(pairCard.getName())];
|
||||
matrix[legendIntegerMap.get(legend.getName())][cardIntegerMap.get(pairCard.getName())] = old + 1;
|
||||
int old = matrix[legendIntegerMap.get(cardName)][cardIntegerMap.get(pairCard.getName())];
|
||||
matrix[legendIntegerMap.get(cardName)][cardIntegerMap.get(pairCard.getName())] = old + 1;
|
||||
}catch (NullPointerException ne){
|
||||
//TODO: Not sure what was failing here
|
||||
ne.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
//add partner commanders to matrix
|
||||
if(deck.getCommanders().size()>1){
|
||||
for(PaperCard partner:deck.getCommanders()){
|
||||
if(!partner.equals(legend)){
|
||||
int old = matrix[legendIntegerMap.get(legend.getName())][cardIntegerMap.get(partner.getName())];
|
||||
matrix[legendIntegerMap.get(legend.getName())][cardIntegerMap.get(partner.getName())] = old + 1;
|
||||
int old = matrix[legendIntegerMap.get(cardName)][cardIntegerMap.get(partner.getName())];
|
||||
matrix[legendIntegerMap.get(cardName)][cardIntegerMap.get(partner.getName())] = old + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user