* Renamed "Historical Standard" format to "Historical Type 2" and "Super Standard" to "Super Type 2". Added Chronicles to the set lists.

This commit is contained in:
LevelX2 2015-11-25 17:29:23 +01:00
parent b9e9907bc0
commit 8957128b13
5 changed files with 63 additions and 43 deletions

View file

@ -27,14 +27,17 @@
*/
package mage.client.deck.generator;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import mage.cards.Card;
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.dialog.PreferencesDialog;
import mage.client.util.sets.ConstructedFormats;
@ -43,7 +46,6 @@ import mage.constants.ColoredManaSymbol;
import mage.constants.Rarity;
import mage.util.TournamentUtil;
/**
* Generates random card pool and builds a deck.
*
@ -58,6 +60,7 @@ public class DeckGenerator {
/**
* Builds a deck out of the selected block/set/format.
*
* @return a path to the generated deck.
*/
public static String generateDeck() {
@ -71,7 +74,6 @@ public class DeckGenerator {
return PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_DECK_FILE, null);
}
protected static Deck buildDeck() {
String selectedColors = genDialog.getSelectedColors();
@ -101,6 +103,7 @@ public class DeckGenerator {
/**
* If the user has selected random colors, pick them randomly for the user.
*
* @param selectedColors a string of the colors selected.
* @return a String representation of the new colors chosen.
*/
@ -131,9 +134,10 @@ public class DeckGenerator {
}
/**
* Generates all the cards to use in the deck.
* Adds creatures, non-creatures, lands (including non-basic).
* Fixes the deck, adjusting for size and color of the cards retrieved.
* Generates all the cards to use in the deck. Adds creatures,
* non-creatures, lands (including non-basic). Fixes the deck, adjusting for
* size and color of the cards retrieved.
*
* @param deckSize how big the deck is to generate.
* @param allowedColors which colors are allowed in the deck.
* @param setsToUse which sets to use to retrieve cards for this deck.
@ -149,16 +153,18 @@ public class DeckGenerator {
creatureCriteria.setCodes(sets);
creatureCriteria.notTypes(CardType.LAND);
creatureCriteria.types(CardType.CREATURE);
if (!(genDialog.useArtifacts()))
if (!(genDialog.useArtifacts())) {
creatureCriteria.notTypes(CardType.ARTIFACT);
}
// Non-creatures (sorcery, instant, enchantment, artifact etc.)
final CardCriteria nonCreatureCriteria = new CardCriteria();
nonCreatureCriteria.setCodes(sets);
nonCreatureCriteria.notTypes(CardType.LAND);
nonCreatureCriteria.notTypes(CardType.CREATURE);
if (!(genDialog.useArtifacts()))
if (!(genDialog.useArtifacts())) {
nonCreatureCriteria.notTypes(CardType.ARTIFACT);
}
// Non-basic land
final CardCriteria nonBasicLandCriteria = new CardCriteria();
@ -177,15 +183,18 @@ public class DeckGenerator {
return genPool.getDeck();
}
/**
* Generates all spells for the deck.
* Each card is retrieved from the database and checked against the converted mana cost (CMC) needed for the current card pool.
* If a card's CMC matches the CMC range required by the pool, it is added to the deck.
* This ensures that the majority of cards fit a fixed mana curve for the deck, and it is playable.
* Creatures and non-creatures are retrieved separately to ensure the deck contains a reasonable mix of both.
* Generates all spells for the deck. Each card is retrieved from the
* database and checked against the converted mana cost (CMC) needed for the
* current card pool. If a card's CMC matches the CMC range required by the
* pool, it is added to the deck. This ensures that the majority of cards
* fit a fixed mana curve for the deck, and it is playable. Creatures and
* non-creatures are retrieved separately to ensure the deck contains a
* reasonable mix of both.
*
* @param criteria the criteria to search for in the database.
* @param spellCount the number of spells that match the criteria needed in the deck.
* @param spellCount the number of spells that match the criteria needed in
* the deck.
*/
private static void generateSpells(CardCriteria criteria, int spellCount) {
List<CardInfo> cardPool = CardRepository.instance.findCards(criteria);
@ -212,8 +221,9 @@ public class DeckGenerator {
} else {
if (reservesAdded < (genPool.getDeckSize() / 2)) {
added = genPool.tryAddReserve(card, cardCMC);
if(added)
if (added) {
reservesAdded++;
}
}
}
}
@ -231,11 +241,13 @@ public class DeckGenerator {
}
/**
* Generates all the lands for the deck.
* Generates non-basic if selected by the user and if the deck isn't monocolored.
* Will fetch non-basic lands if required and then fill up the remaining space with basic lands.
* Basic lands are adjusted according to the mana symbols seen in the cards used in this deck.
* Usually the lands will be well balanced relative to the color of cards.
* Generates all the lands for the deck. Generates non-basic if selected by
* the user and if the deck isn't monocolored. Will fetch non-basic lands if
* required and then fill up the remaining space with basic lands. Basic
* lands are adjusted according to the mana symbols seen in the cards used
* in this deck. Usually the lands will be well balanced relative to the
* color of cards.
*
* @param criteria the criteria of the lands to search for in the database.
* @param landsCount the amount of lands required for this deck.
* @param basicLands information about the basic lands from the sets used.
@ -281,6 +293,7 @@ public class DeckGenerator {
/**
* Returns a map of colored mana symbol to basic land cards of that color.
*
* @param setsToUse which sets to retrieve basic lands from.
* @return a map of color to basic lands.
*/
@ -295,7 +308,7 @@ public class DeckGenerator {
Map<String, List<CardInfo>> basicLandMap = new HashMap<>();
for(ColoredManaSymbol c: ColoredManaSymbol.values()) {
for (ColoredManaSymbol c : ColoredManaSymbol.values()) {
String landName = DeckGeneratorPool.getBasicLandName(c.toString());
criteria.rarities(Rarity.LAND).name(landName);
List<CardInfo> cards = CardRepository.instance.findCards(criteria);
@ -305,11 +318,14 @@ public class DeckGenerator {
}
/**
* Once any non-basic lands are added, add basic lands until the deck is filled.
* Once any non-basic lands are added, add basic lands until the deck is
* filled.
*
* @param landsNeeded how many remaining lands are needed.
* @param percentage the percentage needed for each color in the final deck.
* @param count how many of each color can be produced by non-basic lands.
* @param basicLands list of information about basic lands from the database.
* @param basicLands list of information about basic lands from the
* database.
*/
private static void addBasicLands(int landsNeeded, Map<String, Double> percentage, Map<String, Integer> count, Map<String, List<CardInfo>> basicLands) {
int colorTotal = 0;
@ -335,8 +351,9 @@ public class DeckGenerator {
int currentCount = count.get(color.toString());
double thisPercentage = 0.0;
// Calculate the percentage of lands so far that produce this color
if (currentCount > 0)
if (currentCount > 0) {
thisPercentage = (currentCount / (double) colorTotal) * 100.0;
}
// Check if the color is the most "needed" (highest percentage) we have seen so far
if (neededPercentage - thisPercentage > minPercentage) {
// Put this color land forward to be added
@ -344,7 +361,7 @@ public class DeckGenerator {
minPercentage = (neededPercentage - thisPercentage);
}
}
if(colorToAdd != null) {
if (colorToAdd != null) {
genPool.addCard(getBasicLand(colorToAdd, basicLands));
count.put(colorToAdd.toString(), count.get(colorToAdd.toString()) + 1);
colorTotal++;
@ -355,8 +372,10 @@ public class DeckGenerator {
/**
* Return a random basic land of the chosen color.
*
* @param color the color the basic land should produce.
* @param basicLands list of information about basic lands from the database.
* @param basicLands list of information about basic lands from the
* database.
* @return a single basic land that produces the color needed.
*/
private static Card getBasicLand(ColoredManaSymbol color, Map<String, List<CardInfo>> basicLands) {
@ -366,5 +385,4 @@ public class DeckGenerator {
return basicLandsInfo.get(random.nextInt(basicLandsInfo.size() - 1)).getMockCard().copy();
}
}