forked from External/mage
Updated selected sets for "Standard" and "Selected". Added blocks to selectable Formats. Made all formats selectable in card selector, mage book and automated deck generation.
This commit is contained in:
parent
6619c21d6b
commit
cf88bb5ac3
5 changed files with 380 additions and 88 deletions
|
|
@ -1,5 +1,5 @@
|
|||
package mage.client.deck.generator;
|
||||
|
||||
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.ColoredManaSymbol;
|
||||
import mage.Mana;
|
||||
|
|
@ -13,7 +13,7 @@ import mage.interfaces.rate.RateCallback;
|
|||
import mage.sets.Sets;
|
||||
import mage.utils.CardUtil;
|
||||
import mage.utils.DeckBuilder;
|
||||
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
|
@ -21,31 +21,31 @@ import java.awt.event.ActionListener;
|
|||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Generates random card pool and builds a deck.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class DeckGenerator {
|
||||
|
||||
|
||||
private static JDialog dlg;
|
||||
private static String selectedColors;
|
||||
private static JComboBox formats;
|
||||
|
||||
|
||||
private static final int SPELL_CARD_POOL_SIZE = 180;
|
||||
|
||||
|
||||
private static final int DECK_LANDS = 16;
|
||||
private static final int MAX_NON_BASIC_SOURCE = DECK_LANDS / 2;
|
||||
|
||||
|
||||
private static final boolean GENERATE_RANDOM_BASIC_LAND = true;
|
||||
private static final int MAX_TRIES = 4096;
|
||||
|
||||
|
||||
private static Deck deck = new Deck();
|
||||
private static final int ADDITIONAL_CARDS_FOR_3_COLOR_DECKS = 20;
|
||||
|
||||
|
||||
private static String colors = "GWUBR";
|
||||
|
||||
|
||||
/**
|
||||
* Opens color chooser dialog. Generates deck.
|
||||
* Saves generated deck and use it as selected deck to play.
|
||||
|
|
@ -55,33 +55,33 @@ public class DeckGenerator {
|
|||
public static String generateDeck() {
|
||||
JPanel p0 = new JPanel();
|
||||
p0.setLayout(new BoxLayout(p0, BoxLayout.Y_AXIS));
|
||||
|
||||
|
||||
JLabel text = new JLabel("Choose color for your deck: ");
|
||||
text.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
p0.add(text);
|
||||
|
||||
|
||||
p0.add(Box.createVerticalStrut(5));
|
||||
String chosen = MageFrame.getPreferences().get("genDeckColor", "u");
|
||||
final ColorsChooser colorsChooser = new ColorsChooser(chosen);
|
||||
p0.add(colorsChooser);
|
||||
|
||||
|
||||
p0.add(Box.createVerticalStrut(5));
|
||||
JLabel text2 = new JLabel("(X - random color)");
|
||||
text2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
p0.add(text2);
|
||||
|
||||
|
||||
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(100, 25));
|
||||
formats.setMaximumSize(new Dimension(100, 25));
|
||||
formats.setPreferredSize(new Dimension(300, 25));
|
||||
formats.setMaximumSize(new Dimension(300, 25));
|
||||
formats.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
jPanel.add(text3);
|
||||
jPanel.add(formats);
|
||||
p0.add(jPanel);
|
||||
|
||||
|
||||
final JButton btnGenerate = new JButton("Ok");
|
||||
btnGenerate.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
|
@ -104,7 +104,7 @@ public class DeckGenerator {
|
|||
dlg = optionPane.createDialog("Generating deck");
|
||||
dlg.setVisible(true);
|
||||
dlg.dispose();
|
||||
|
||||
|
||||
if (selectedColors != null) {
|
||||
buildDeck();
|
||||
try {
|
||||
|
|
@ -119,44 +119,44 @@ public class DeckGenerator {
|
|||
JOptionPane.showMessageDialog(null, "Couldn't generate deck. Try once again.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return selectedColors;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates card pool
|
||||
*/
|
||||
protected static void buildDeck() {
|
||||
List<ColoredManaSymbol> allowedColors = new ArrayList<ColoredManaSymbol>();
|
||||
selectedColors = selectedColors.toUpperCase();
|
||||
|
||||
|
||||
String format = (String)formats.getSelectedItem();
|
||||
List<String> setsToUse = ConstructedFormats.getSetsByFormat(format);
|
||||
if (setsToUse.isEmpty()) {
|
||||
// use all
|
||||
setsToUse = CardsStorage.getSetCodes();
|
||||
}
|
||||
|
||||
|
||||
if (selectedColors.contains("X")) {
|
||||
selectedColors = getRandomColors(selectedColors);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < selectedColors.length(); i++) {
|
||||
char c = selectedColors.charAt(i);
|
||||
allowedColors.add(ColoredManaSymbol.lookup(c));
|
||||
}
|
||||
|
||||
|
||||
int cardPoolSize = SPELL_CARD_POOL_SIZE;
|
||||
if (selectedColors.length() > 2) {
|
||||
cardPoolSize += ADDITIONAL_CARDS_FOR_3_COLOR_DECKS;
|
||||
}
|
||||
List<Card> spellCardPool = generateSpellCardPool(cardPoolSize, allowedColors, setsToUse);
|
||||
List<Card> landCardPool = generateNonBasicLandCardPool(MAX_NON_BASIC_SOURCE, allowedColors, setsToUse);
|
||||
|
||||
|
||||
System.out.println("deck generator card pool: spells=" + spellCardPool.size() + ", lands=" + landCardPool.size());
|
||||
|
||||
|
||||
final List<String> setsToUseFinal = setsToUse;
|
||||
|
||||
|
||||
deck = DeckBuilder.buildDeck(spellCardPool, allowedColors, landCardPool, new RateCallback() {
|
||||
@Override
|
||||
public int rateCard(Card card) {
|
||||
|
|
@ -175,7 +175,7 @@ public class DeckGenerator {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static String getRandomColors(String _selectedColors) {
|
||||
StringBuilder generatedColors = new StringBuilder();
|
||||
Set<String> colors = new HashSet<String>();
|
||||
|
|
@ -192,12 +192,12 @@ public class DeckGenerator {
|
|||
}
|
||||
return generatedColors.toString();
|
||||
}
|
||||
|
||||
|
||||
private static char getRandomColor() {
|
||||
Random r = new Random();
|
||||
return colors.charAt(r.nextInt(colors.length()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates card pool of cardsCount cards that have manacost of allowed colors.
|
||||
*
|
||||
|
|
@ -207,7 +207,7 @@ public class DeckGenerator {
|
|||
*/
|
||||
private static List<Card> generateSpellCardPool(int cardsCount, List<ColoredManaSymbol> allowedColors, List<String> setsToUse) {
|
||||
List<Card> spellCardPool = new ArrayList<Card>();
|
||||
|
||||
|
||||
int count = 0;
|
||||
List<Card> cardPool = new ArrayList<Card>();
|
||||
for (Card card : CardsStorage.getAllCards()) {
|
||||
|
|
@ -235,10 +235,10 @@ public class DeckGenerator {
|
|||
} else {
|
||||
throw new IllegalStateException("Not enough cards to generate deck.");
|
||||
}
|
||||
|
||||
|
||||
return spellCardPool;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check that card can be played using chosen (allowed) colors.
|
||||
*
|
||||
|
|
@ -264,7 +264,7 @@ public class DeckGenerator {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates card pool of land cards that can produce allowed colors.
|
||||
*
|
||||
|
|
@ -274,7 +274,7 @@ public class DeckGenerator {
|
|||
*/
|
||||
private static List<Card> generateNonBasicLandCardPool(int landsCount, List<ColoredManaSymbol> allowedColors, List<String> setsToUse) {
|
||||
List<Card> nonBasicLandCardPool = new ArrayList<Card>();
|
||||
|
||||
|
||||
int count = 0;
|
||||
List<Card> landCards = new ArrayList<Card>();
|
||||
for (Card land : CardsStorage.getNonBasicLandCards()) {
|
||||
|
|
@ -301,10 +301,10 @@ public class DeckGenerator {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nonBasicLandCardPool;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks that chosen card can produce mana of specific color.
|
||||
*
|
||||
|
|
@ -324,7 +324,7 @@ public class DeckGenerator {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get random basic land that can produce specified color mana.
|
||||
* Random here means random set and collector id for the same mana producing land.
|
||||
|
|
@ -348,14 +348,14 @@ public class DeckGenerator {
|
|||
if (color.equals(ColoredManaSymbol.W)) {
|
||||
return Sets.findCard("Plains", GENERATE_RANDOM_BASIC_LAND);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected static boolean isColoredMana(String symbol) {
|
||||
return symbol.equals("W") || symbol.equals("G") || symbol.equals("U") || symbol.equals("B") || symbol.equals("R") || symbol.contains("/");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Card selesnyaGuildMage = null;
|
||||
for (Card card : CardsStorage.getAllCards()) {
|
||||
|
|
@ -371,15 +371,15 @@ public class DeckGenerator {
|
|||
allowedColors.add(ColoredManaSymbol.lookup('B'));
|
||||
allowedColors.add(ColoredManaSymbol.lookup('R'));
|
||||
System.out.println(DeckGenerator.cardFitsChosenColors(selesnyaGuildMage, allowedColors));
|
||||
|
||||
|
||||
allowedColors.clear();
|
||||
allowedColors = new ArrayList<ColoredManaSymbol>();
|
||||
allowedColors.add(ColoredManaSymbol.lookup('G'));
|
||||
System.out.println(DeckGenerator.cardFitsChosenColors(selesnyaGuildMage, allowedColors));
|
||||
|
||||
|
||||
allowedColors.clear();
|
||||
allowedColors = new ArrayList<ColoredManaSymbol>();
|
||||
allowedColors.add(ColoredManaSymbol.lookup('W'));
|
||||
System.out.println(DeckGenerator.cardFitsChosenColors(selesnyaGuildMage, allowedColors));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue