mirror of
https://github.com/correl/mage.git
synced 2025-04-10 17:00:08 -09:00
Now random decks contain non basic lands.
This commit is contained in:
parent
d5d3a1a77e
commit
770e5673f5
4 changed files with 81 additions and 10 deletions
Mage.Client/src/main/java/mage/client
Mage.Common/src/mage/utils
Mage/src/mage
|
@ -6,17 +6,29 @@ import java.util.Set;
|
|||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.sets.Sets;
|
||||
import mage.utils.CardUtil;
|
||||
|
||||
public class CardsStorage {
|
||||
private static Set<Card> allCards = new LinkedHashSet<Card>();
|
||||
private static Set<Card> landCards = new LinkedHashSet<Card>();
|
||||
|
||||
static {
|
||||
for (ExpansionSet set: Sets.getInstance().values()) {
|
||||
allCards.addAll(set.createCards());
|
||||
Set<Card> cards = set.createCards();
|
||||
allCards.addAll(cards);
|
||||
for (Card card : cards) {
|
||||
if (CardUtil.isLand(card)) {
|
||||
landCards.add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<Card> getAllCards() {
|
||||
return allCards;
|
||||
}
|
||||
|
||||
public static Set<Card> getLandCards() {
|
||||
return landCards;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package mage.client.deck.generator;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
|
@ -21,10 +20,12 @@ import javax.swing.JPanel;
|
|||
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.ColoredManaSymbol;
|
||||
import mage.Mana;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.cards.CardsStorage;
|
||||
import mage.client.util.gui.ColorsChooser;
|
||||
import mage.sets.Sets;
|
||||
import mage.utils.CardUtil;
|
||||
|
@ -118,11 +119,17 @@ public class DeckGenerator {
|
|||
} else {
|
||||
if (!CardUtil.isBasicLand(card)) {
|
||||
if (nonBasicLandCount < MAX_NON_BASIC_SOURCE) {
|
||||
nonBasicLandCount++;
|
||||
landCardPool.add(card);
|
||||
int score = 0;
|
||||
for (Mana mana : card.getMana()) {
|
||||
for (ColoredManaSymbol color : allowedColors) {
|
||||
score += mana.getColor(color);
|
||||
}
|
||||
}
|
||||
if (score > 1) {
|
||||
nonBasicLandCount++;
|
||||
landCardPool.add(card);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
landCardPool.add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +137,24 @@ public class DeckGenerator {
|
|||
//ignore
|
||||
}
|
||||
}
|
||||
out:
|
||||
while (nonBasicLandCount < MAX_NON_BASIC_SOURCE) {
|
||||
for (Card card : CardsStorage.getLandCards()) {
|
||||
int score = 0;
|
||||
for (Mana mana : card.getMana()) {
|
||||
for (ColoredManaSymbol color : allowedColors) {
|
||||
score += mana.getColor(color);
|
||||
}
|
||||
}
|
||||
if (score > 1) {
|
||||
nonBasicLandCount++;
|
||||
landCardPool.add(card);
|
||||
}
|
||||
if (nonBasicLandCount > MAX_NON_BASIC_SOURCE) {
|
||||
break out;
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("deck generator card pool: spells=" + spellCardPool.size() + ", lands=" + landCardPool.size());
|
||||
|
||||
final Collection<MageScoredCard> remainingCards = new ArrayList<MageScoredCard>();
|
||||
|
@ -200,15 +225,24 @@ public class DeckGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Add suitable non basic lands to deck in order of pack.
|
||||
final Map<String, Integer> colorSource = new HashMap<String, Integer>();
|
||||
for (final ColoredManaSymbol color : ColoredManaSymbol.values()) {
|
||||
colorSource.put(color.toString(), 0);
|
||||
}
|
||||
for (final Card card : landCardPool) {
|
||||
//TODO: add non basic lands: need to get know what mana a land can produce
|
||||
for (final Card landCard : landCardPool) {
|
||||
deck.getCards().add(landCard);
|
||||
for (Mana mana : landCard.getMana()) {
|
||||
for (ColoredManaSymbol color : allowedColors) {
|
||||
int amount = mana.getColor(color);
|
||||
if (amount > 0) {
|
||||
Integer count = colorSource.get(color.toString());
|
||||
count += amount;
|
||||
colorSource.put(color.toString(), count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Add optimal basic lands to deck.
|
||||
|
|
|
@ -44,4 +44,8 @@ public class CardUtil {
|
|||
public static boolean isBasicLand(Card card) {
|
||||
return card.getSupertype().contains("Basic");
|
||||
}
|
||||
|
||||
public static boolean isLand(Card card) {
|
||||
return card.getCardType().contains(CardType.LAND);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
package mage;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import mage.Constants.ColoredManaSymbol;
|
||||
import mage.util.Copyable;
|
||||
|
||||
/**
|
||||
|
@ -361,5 +363,24 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getColor(ColoredManaSymbol color) {
|
||||
if (color.equals(ColoredManaSymbol.G)) {
|
||||
return getGreen();
|
||||
}
|
||||
if (color.equals(ColoredManaSymbol.R)) {
|
||||
return getRed();
|
||||
}
|
||||
if (color.equals(ColoredManaSymbol.B)) {
|
||||
return getBlack();
|
||||
}
|
||||
if (color.equals(ColoredManaSymbol.U)) {
|
||||
return getBlue();
|
||||
}
|
||||
if (color.equals(ColoredManaSymbol.W)) {
|
||||
return getWhite();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue