forked from External/mage
Allow to generate 40 or 60 cars decks.
This commit is contained in:
parent
3d2f262ff4
commit
78dc712944
2 changed files with 95 additions and 48 deletions
|
|
@ -1,24 +1,5 @@
|
|||
package mage.client.deck.generator;
|
||||
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.Mana;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.util.gui.ColorsChooser;
|
||||
import mage.client.util.sets.ConstructedFormats;
|
||||
import mage.constants.Rarity;
|
||||
import mage.interfaces.rate.RateCallback;
|
||||
import mage.cards.Sets;
|
||||
import mage.utils.DeckBuilder;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
|
@ -29,7 +10,32 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import mage.Mana;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Sets;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.util.gui.ColorsChooser;
|
||||
import mage.client.util.sets.ConstructedFormats;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.constants.Rarity;
|
||||
import mage.interfaces.rate.RateCallback;
|
||||
import mage.utils.DeckBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* Generates random card pool and builds a deck.
|
||||
|
|
@ -40,7 +46,8 @@ public class DeckGenerator {
|
|||
|
||||
private static JDialog dlg;
|
||||
private static String selectedColors;
|
||||
private static JComboBox formats;
|
||||
private static JComboBox cbSets;
|
||||
private static JComboBox cbDeckSize;
|
||||
|
||||
private static final int SPELL_CARD_POOL_SIZE = 180;
|
||||
|
||||
|
|
@ -78,16 +85,30 @@ public class DeckGenerator {
|
|||
|
||||
p0.add(Box.createVerticalStrut(5));
|
||||
JPanel jPanel = new JPanel();
|
||||
JLabel text3 = new JLabel("Choose format:");
|
||||
formats = new JComboBox(ConstructedFormats.getTypes());
|
||||
formats.setSelectedIndex(0);
|
||||
formats.setPreferredSize(new Dimension(300, 25));
|
||||
formats.setMaximumSize(new Dimension(300, 25));
|
||||
formats.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
JLabel text3 = new JLabel("Choose sets:");
|
||||
cbSets = new JComboBox(ConstructedFormats.getTypes());
|
||||
cbSets.setSelectedIndex(0);
|
||||
cbSets.setPreferredSize(new Dimension(300, 25));
|
||||
cbSets.setMaximumSize(new Dimension(300, 25));
|
||||
cbSets.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
jPanel.add(text3);
|
||||
jPanel.add(formats);
|
||||
jPanel.add(cbSets);
|
||||
|
||||
p0.add(jPanel);
|
||||
|
||||
p0.add(Box.createVerticalStrut(5));
|
||||
JPanel jPanel2 = new JPanel();
|
||||
JLabel textDeckSize = new JLabel("Deck size:");
|
||||
cbDeckSize = new JComboBox(new String[]{"40","60"});
|
||||
cbDeckSize.setSelectedIndex(0);
|
||||
cbDeckSize.setPreferredSize(new Dimension(300, 25));
|
||||
cbDeckSize.setMaximumSize(new Dimension(300, 25));
|
||||
cbDeckSize.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
jPanel2.add(textDeckSize);
|
||||
jPanel2.add(cbDeckSize);
|
||||
|
||||
p0.add(jPanel2);
|
||||
|
||||
final JButton btnGenerate = new JButton("Ok");
|
||||
btnGenerate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
|
|
@ -137,13 +158,17 @@ public class DeckGenerator {
|
|||
List<ColoredManaSymbol> allowedColors = new ArrayList<ColoredManaSymbol>();
|
||||
selectedColors = selectedColors != null ? selectedColors.toUpperCase() : getRandomColors("X");
|
||||
|
||||
String format = (String) formats.getSelectedItem();
|
||||
String format = (String) cbSets.getSelectedItem();
|
||||
List<String> setsToUse = ConstructedFormats.getSetsByFormat(format);
|
||||
if (setsToUse.isEmpty()) {
|
||||
// use all
|
||||
setsToUse = ExpansionRepository.instance.getSetCodes();
|
||||
}
|
||||
|
||||
int deckSize = Integer.parseInt(cbDeckSize.getSelectedItem().toString());
|
||||
if (deckSize < 40) {
|
||||
deckSize = 40;
|
||||
}
|
||||
if (selectedColors.contains("X")) {
|
||||
selectedColors = getRandomColors(selectedColors);
|
||||
}
|
||||
|
|
@ -164,7 +189,7 @@ public class DeckGenerator {
|
|||
|
||||
final List<String> setsToUseFinal = setsToUse;
|
||||
|
||||
deck = DeckBuilder.buildDeck(spellCardPool, allowedColors, setsToUseFinal, landCardPool, new RateCallback() {
|
||||
deck = DeckBuilder.buildDeck(spellCardPool, allowedColors, setsToUseFinal, landCardPool, deckSize, new RateCallback() {
|
||||
@Override
|
||||
public int rateCard(Card card) {
|
||||
return 6;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
package mage.utils;
|
||||
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import mage.Mana;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.interfaces.rate.RateCallback;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Builds deck from provided card pool.
|
||||
*
|
||||
|
|
@ -16,26 +21,33 @@ import java.util.*;
|
|||
*/
|
||||
public class DeckBuilder {
|
||||
|
||||
private static String selectedColors;
|
||||
// private static String selectedColors;
|
||||
//
|
||||
// private static final int SPELL_CARD_POOL_SIZE = 60;
|
||||
|
||||
private static final int SPELL_CARD_POOL_SIZE = 60;
|
||||
|
||||
private static final int DECK_COUNT[] = {3, 6, 6, 4, 3, 2};
|
||||
private static final int DECK_COUNT40[] = {3, 6, 6, 4, 3, 2};
|
||||
private static final int DECK_COUNT60[] = {4, 9, 9, 5, 5, 3};
|
||||
private static final int DECK_COST[] = {1, 2, 3, 4, 6, 10};
|
||||
private static final int DECK_SPELLS = 23;
|
||||
private static final int DECK_LANDS = 17;
|
||||
private static final int DECK_SIZE = DECK_SPELLS + DECK_LANDS;
|
||||
// private static final int DECK_SPELLS = 23;
|
||||
// private static final int DECK_LANDS = 17;
|
||||
// private static final int DECK_SIZE = DECK_SPELLS + DECK_LANDS;
|
||||
private static final int MIN_CARD_SCORE = 25;
|
||||
private static final int MIN_SOURCE = 16;
|
||||
private static Deck deck = new Deck();
|
||||
|
||||
private static int deckCount[];
|
||||
private static int deckSize;
|
||||
private static int deckSpells;
|
||||
private static int deckLands;
|
||||
|
||||
/**
|
||||
* Hide constructor.
|
||||
*/
|
||||
private DeckBuilder() {
|
||||
}
|
||||
|
||||
public synchronized static Deck buildDeck(List<Card> spellCardPool, List<ColoredManaSymbol> allowedColors, List<String> setsToUse, List<Card> landCardPool, RateCallback callback) {
|
||||
public synchronized static Deck buildDeck(List<Card> spellCardPool, List<ColoredManaSymbol> allowedColors, List<String> setsToUse, List<Card> landCardPool, int deckCardSize, RateCallback callback) {
|
||||
deckSize = deckCardSize;
|
||||
deck = new Deck();
|
||||
|
||||
final Collection<MageScoredCard> remainingCards = new ArrayList<MageScoredCard>();
|
||||
|
|
@ -48,13 +60,23 @@ public class DeckBuilder {
|
|||
names.add(card.getName());
|
||||
}
|
||||
int min = 0;
|
||||
for (int index = 0; index < DECK_COUNT.length; index++) {
|
||||
if (deckSize == 40) {
|
||||
deckCount = DECK_COUNT40;
|
||||
deckSpells = 23;
|
||||
deckLands = 17;
|
||||
} else {
|
||||
deckCount = DECK_COUNT60;
|
||||
deckSpells = 35;
|
||||
deckLands = 25;
|
||||
}
|
||||
|
||||
for (int index = 0; index < deckCount.length; index++) {
|
||||
final int max = DECK_COST[index];
|
||||
addCardsToDeck(remainingCards, min, max, DECK_COUNT[index]);
|
||||
addCardsToDeck(remainingCards, min, max, deckCount[index]);
|
||||
min = max + 1;
|
||||
}
|
||||
addCardsToDeck(remainingCards, 0, 4, DECK_SPELLS - deck.getCards().size());
|
||||
addCardsToDeck(remainingCards, 5, 10, DECK_SPELLS - deck.getCards().size());
|
||||
addCardsToDeck(remainingCards, 0, 4, deckSpells - deck.getCards().size());
|
||||
addCardsToDeck(remainingCards, 5, 10, deckSpells - deck.getCards().size());
|
||||
addLandsToDeck(allowedColors, setsToUse, landCardPool, callback);
|
||||
|
||||
return deck;
|
||||
|
|
@ -170,7 +192,7 @@ public class DeckBuilder {
|
|||
}
|
||||
|
||||
// Add optimal basic lands to deck.
|
||||
while (deck.getCards().size() < DECK_SIZE) {
|
||||
while (deck.getCards().size() < deckSize) {
|
||||
ColoredManaSymbol bestColor = null;
|
||||
int lowestRatio = Integer.MAX_VALUE;
|
||||
for (final ColoredManaSymbol color : ColoredManaSymbol.values()) {
|
||||
|
|
@ -209,7 +231,7 @@ public class DeckBuilder {
|
|||
public MageScoredCard(Card card, List<ColoredManaSymbol> allowedColors, RateCallback cardRater) {
|
||||
this.card = card;
|
||||
|
||||
int type = 0;
|
||||
int type;
|
||||
if (card.getCardType().contains(CardType.CREATURE)) {
|
||||
type = 10;
|
||||
} else if (card.getSubtype().contains("Equipment")) {
|
||||
|
|
@ -281,4 +303,4 @@ public class DeckBuilder {
|
|||
return symbol.equals("W") || symbol.equals("G") || symbol.equals("U") || symbol.equals("B") || symbol.equals("R");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue