use of mage.constants.ColoredManaSymbol in project mage by magefree.
the class DeckGenerator method generateBasicLands.
/**
* 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.
*/
private static Map<String, List<CardInfo>> generateBasicLands(List<String> setsToUse) {
Set<String> landSets = TournamentUtil.getLandSetCodeForDeckSets(setsToUse);
CardCriteria criteria = new CardCriteria();
if (!landSets.isEmpty()) {
criteria.setCodes(landSets.toArray(new String[landSets.size()]));
}
criteria.ignoreSetsWithSnowLands();
Map<String, List<CardInfo>> basicLandMap = new HashMap<>();
for (ColoredManaSymbol c : ColoredManaSymbol.values()) {
String landName = DeckGeneratorPool.getBasicLandName(c.toString());
criteria.rarities(Rarity.LAND).name(landName);
List<CardInfo> cards = CardRepository.instance.findCards(criteria);
if (cards.isEmpty()) {
// Workaround to get basic lands if lands are not available for the given sets
criteria.setCodes("M15");
cards = CardRepository.instance.findCards(criteria);
}
basicLandMap.put(landName, cards);
}
return basicLandMap;
}
use of mage.constants.ColoredManaSymbol in project mage by magefree.
the class DeckGenerator method addBasicLands.
/**
* 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.
*/
private static void addBasicLands(int landsNeeded, Map<String, Double> percentage, Map<String, Integer> count, Map<String, List<CardInfo>> basicLands) {
int colorTotal = 0;
ColoredManaSymbol colorToAdd = ColoredManaSymbol.U;
// Add up the totals for all colors, to keep track of the percentage a color is.
for (Map.Entry<String, Integer> c : count.entrySet()) {
colorTotal += c.getValue();
}
// Keep adding basic lands until we fill the deck
while (landsNeeded > 0) {
double minPercentage = Integer.MIN_VALUE;
for (ColoredManaSymbol color : ColoredManaSymbol.values()) {
// What percentage of this color is requested
double neededPercentage = percentage.get(color.toString());
// If there is a 0% need for basic lands of this color, skip it
if (neededPercentage <= 0) {
continue;
}
int currentCount = count.get(color.toString());
double thisPercentage = 0.0;
// Calculate the percentage of lands so far that produce this color
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
colorToAdd = color;
minPercentage = (neededPercentage - thisPercentage);
}
}
genPool.addCard(getBasicLand(colorToAdd, basicLands));
count.put(colorToAdd.toString(), count.get(colorToAdd.toString()) + 1);
colorTotal++;
landsNeeded--;
}
}
use of mage.constants.ColoredManaSymbol in project mage by magefree.
the class DeckGenerator method getRandomColors.
/**
* 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.
*/
private static String getRandomColors(String selectedColors) {
List<Character> availableColors = new ArrayList<>();
for (ColoredManaSymbol cms : ColoredManaSymbol.values()) {
availableColors.add(cms.toString().charAt(0));
}
StringBuilder generatedColors = new StringBuilder();
int randomColors = 0;
for (int i = 0; i < selectedColors.length(); i++) {
char currentColor = selectedColors.charAt(i);
if (currentColor != 'X') {
generatedColors.append(currentColor);
availableColors.remove(new Character(currentColor));
} else {
randomColors++;
}
}
for (int i = 0; i < randomColors && !availableColors.isEmpty(); i++) {
int index = RandomUtil.nextInt(availableColors.size());
generatedColors.append(availableColors.remove(index));
}
return generatedColors.toString();
}
use of mage.constants.ColoredManaSymbol in project mage by magefree.
the class DeckGeneratorPool method cardFitsChosenColors.
/**
* Checks if the mana symbols in the card all match the allowed colors for this pool.
* @param card the spell card to check.
* @return if all the mana symbols fit the chosen colors.
*/
private boolean cardFitsChosenColors(Card card) {
for (String symbol : card.getManaCostSymbols()) {
boolean found = false;
symbol = symbol.replace("{", "").replace("}", "");
if (isColoredManaSymbol(symbol)) {
for (ColoredManaSymbol allowed : allowedColors) {
if (symbol.contains(allowed.toString())) {
found = true;
break;
}
}
if (!found) {
return false;
}
}
if (symbol.equals("C") && !colorlessAllowed) {
return false;
}
}
return true;
}
use of mage.constants.ColoredManaSymbol in project mage by magefree.
the class DeckGeneratorPool method calculateSpellColorPercentages.
/**
* Calculates the percentage of colored mana symbols over all spell cards in the deck.
* Used to balance the generation of basic lands so the amount of lands matches the
* cards mana costs.
* @return a list of colored mana symbols and the percentage of symbols seen in cards mana costs.
*/
public Map<String, Double> calculateSpellColorPercentages() {
final Map<String, Integer> colorCount = new HashMap<>();
for (final ColoredManaSymbol color : ColoredManaSymbol.values()) {
colorCount.put(color.toString(), 0);
}
// Counts how many colored mana symbols we've seen in total so we can get the percentage of each color
int totalCount = 0;
List<Card> fixedSpells = getFixedSpells();
for (Card spell : fixedSpells) {
for (String symbol : spell.getManaCostSymbols()) {
symbol = symbol.replace("{", "").replace("}", "");
if (isColoredManaSymbol(symbol)) {
for (ColoredManaSymbol allowed : allowedColors) {
if (symbol.contains(allowed.toString())) {
int cnt = colorCount.get(allowed.toString());
colorCount.put(allowed.toString(), cnt + 1);
totalCount++;
}
}
}
}
}
final Map<String, Double> percentages = new HashMap<>();
for (Map.Entry<String, Integer> singleCount : colorCount.entrySet()) {
String color = singleCount.getKey();
int count = singleCount.getValue();
// Calculate the percentage this color has out of the total color counts
double percentage = (count / (double) totalCount) * 100;
percentages.put(color, percentage);
}
return percentages;
}
Aggregations