From 76cad4ae7e587b8057128e320a579917a309f283 Mon Sep 17 00:00:00 2001 From: austinio7116 Date: Thu, 19 Apr 2018 12:58:15 +0100 Subject: [PATCH] Fixed repeated cards in brawl and improved quality of randomly added cards --- .../forge/limited/CardThemedDeckBuilder.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/forge-gui/src/main/java/forge/limited/CardThemedDeckBuilder.java b/forge-gui/src/main/java/forge/limited/CardThemedDeckBuilder.java index 520e998ec30..de75375989b 100644 --- a/forge-gui/src/main/java/forge/limited/CardThemedDeckBuilder.java +++ b/forge-gui/src/main/java/forge/limited/CardThemedDeckBuilder.java @@ -479,6 +479,14 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase { } } + private Set getDeckListNames(){ + Set deckListNames = new HashSet<>(); + for(PaperCard card:deckList){ + deckListNames.add(card.getName()); + } + return deckListNames; + } + /** * If the deck does not have 40 cards, fix it. This method should not be * called if the stuff above it is working correctly. @@ -501,25 +509,27 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase { } Predicate possibleFromFullPool = new Predicate() { + Set deckListNames = getDeckListNames(); @Override public boolean apply(PaperCard card) { return format.isLegalCard(card) && !card.getRules().getManaCost().isPureGeneric() && colors.containsAllColorsFrom(card.getRules().getColorIdentity().getColor()) - && !deckList.contains(card) + && !deckListNames.contains(card.getName()) && !card.getRules().getAiHints().getRemAIDecks() && !card.getRules().getAiHints().getRemRandomDecks() && !card.getRules().getMainPart().getType().isLand(); } }; - List randomPool = Lists.newArrayList(pool.getAllCards(possibleFromFullPool)); + List possibleList = Lists.newArrayList(pool.getAllCards(possibleFromFullPool)); //ensure we do not add more keycards in case they are commanders if (keyCard != null) { - randomPool.removeAll(StaticData.instance().getCommonCards().getAllCards(keyCard.getName())); + possibleList.removeAll(StaticData.instance().getCommonCards().getAllCards(keyCard.getName())); } if (secondKeyCard != null) { - randomPool.removeAll(StaticData.instance().getCommonCards().getAllCards(secondKeyCard.getName())); + possibleList.removeAll(StaticData.instance().getCommonCards().getAllCards(secondKeyCard.getName())); } + List randomPool = CardRanker.rankCardsInDeck(possibleList).subList(0,new Float(possibleList.size()*0.25).intValue()); Collections.shuffle(randomPool, MyRandom.getRandom()); Iterator iRandomPool=randomPool.iterator(); while (deckList.size() < targetSize) { @@ -734,20 +744,29 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase { * number to add */ private void addRandomCards(int num) { + Set deckListNames = getDeckListNames(); Predicate possibleFromFullPool = new Predicate() { @Override public boolean apply(PaperCard card) { return format.isLegalCard(card) &&!card.getRules().getManaCost().isPureGeneric() && colors.containsAllColorsFrom(card.getRules().getColorIdentity().getColor()) - && !deckList.contains(card) + && !deckListNames.contains(card.getName()) &&!card.getRules().getAiHints().getRemAIDecks() &&!card.getRules().getAiHints().getRemRandomDecks() &&!card.getRules().getMainPart().getType().isLand(); } }; - List randomPool = Lists.newArrayList(pool.getAllCards(possibleFromFullPool)); - Collections.shuffle(randomPool, MyRandom.getRandom()); + List possibleList = Lists.newArrayList(pool.getAllCards(possibleFromFullPool)); + //ensure we do not add more keycards in case they are commanders + if (keyCard != null) { + possibleList.removeAll(StaticData.instance().getCommonCards().getAllCards(keyCard.getName())); + } + if (secondKeyCard != null) { + possibleList.removeAll(StaticData.instance().getCommonCards().getAllCards(secondKeyCard.getName())); + } + List randomPool = CardRanker.rankCardsInDeck(possibleList).subList(0,new Float(possibleList.size()*0.25).intValue()); + Collections.shuffle(randomPool); Iterator iRandomPool=randomPool.iterator(); for(int i=0;i