diff --git a/Mage.Common/src/mage/utils/DeckBuilder.java b/Mage.Common/src/mage/utils/DeckBuilder.java index 94fdde0fe3..7ae206b953 100644 --- a/Mage.Common/src/mage/utils/DeckBuilder.java +++ b/Mage.Common/src/mage/utils/DeckBuilder.java @@ -7,6 +7,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Random; import mage.Mana; import mage.cards.Card; import mage.cards.decks.Deck; @@ -202,6 +203,10 @@ public class DeckBuilder { // Add optimal basic lands to deck. while (deck.getCards().size() < deckSize) { ColoredManaSymbol bestColor = null; + //Default to a color in the allowed colors + if (allowedColors != null && !allowedColors.isEmpty()) { + bestColor = allowedColors.get(new Random().nextInt(allowedColors.size())); + } int lowestRatio = Integer.MAX_VALUE; for (final ColoredManaSymbol color : ColoredManaSymbol.values()) { diff --git a/Mage.Tests/src/test/java/org/mage/test/utils/DeckBuilderTest.java b/Mage.Tests/src/test/java/org/mage/test/utils/DeckBuilderTest.java new file mode 100644 index 0000000000..87632699e5 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/utils/DeckBuilderTest.java @@ -0,0 +1,72 @@ +package org.mage.test.utils; + +import mage.MageInt; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.ColoredManaSymbol; +import mage.constants.Rarity; +import mage.interfaces.rate.RateCallback; +import mage.sets.guru.Island; +import mage.utils.DeckBuilder; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +/** + * @author dustinconrad + */ +public class DeckBuilderTest { + + @Test + public void testAllArtifacts() { + final List spellCardPool = new ArrayList<>(); + final UUID owner = UUID.randomUUID(); + final List allowedColors = Arrays.asList(ColoredManaSymbol.U); + final List setsToUse = new ArrayList<>(); + final List landCardPool = null; + final RateCallback rateCallback = new RateCallback() { + @Override + public int rateCard(Card card) { + return 6; + } + + @Override + public Card getBestBasicLand(ColoredManaSymbol color, List setsToUse) { + Assert.assertNotNull(color); + return new Island(owner); + } + }; + + for(int i = 0; i < 24; i++) { + Card c = new RandomArtifactCreature(owner, i, "Random Artifact " + i); + spellCardPool.add(c); + } + + DeckBuilder.buildDeck(spellCardPool, allowedColors, setsToUse, landCardPool, 40, rateCallback); + } + + private static class RandomArtifactCreature extends CardImpl { + + public RandomArtifactCreature(UUID ownerId, int cardNumber, String name) { + super(ownerId, cardNumber, name, Rarity.COMMON, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{1}"); + this.expansionSetCode = "MRD"; + this.power = new MageInt(1); + this.toughness = new MageInt(1); + } + + public RandomArtifactCreature(final RandomArtifactCreature card) { + super(card); + } + + @Override + public RandomArtifactCreature copy() { + return new RandomArtifactCreature(this); + } + } + +}