Check for Snow lands and Wastes when generating random decks

This commit is contained in:
Eradev
2025-10-08 12:05:11 -04:00
committed by Chris H
parent 3847080221
commit 0ee3dc4e67
3 changed files with 71 additions and 55 deletions

View File

@@ -63,7 +63,6 @@ public enum ManaCostShard {
S(ManaAtom.IS_SNOW, "S"), S(ManaAtom.IS_SNOW, "S"),
GENERIC(ManaAtom.GENERIC, "1"), GENERIC(ManaAtom.GENERIC, "1"),
/* Phyrexian */ /* Phyrexian */
WP(ManaAtom.WHITE | ManaAtom.OR_2_LIFE, "W/P", "WP"), WP(ManaAtom.WHITE | ManaAtom.OR_2_LIFE, "W/P", "WP"),
UP(ManaAtom.BLUE | ManaAtom.OR_2_LIFE, "U/P", "UP"), UP(ManaAtom.BLUE | ManaAtom.OR_2_LIFE, "U/P", "UP"),

View File

@@ -9,6 +9,7 @@ import forge.adventure.data.GeneratedDeckData;
import forge.adventure.data.GeneratedDeckTemplateData; import forge.adventure.data.GeneratedDeckTemplateData;
import forge.adventure.data.RewardData; import forge.adventure.data.RewardData;
import forge.card.*; import forge.card.*;
import forge.card.mana.ManaCost;
import forge.card.mana.ManaCostShard; import forge.card.mana.ManaCostShard;
import forge.deck.Deck; import forge.deck.Deck;
import forge.deck.DeckSection; import forge.deck.DeckSection;
@@ -499,67 +500,83 @@ public class CardUtil {
} }
private static List<PaperCard> fillWithLands(List<PaperCard> nonLands, GeneratedDeckTemplateData template) { private static List<PaperCard> fillWithLands(List<PaperCard> nonLands, GeneratedDeckTemplateData template) {
int red=0; int red = 0, blue = 0, green = 0, white = 0, black = 0, colorless = 0;
int blue=0; int cardCount = nonLands.size();
int green=0; List<PaperCard> cards = new ArrayList<>();
int white=0; boolean allCardVariants = Config.instance().getSettingData().useAllCardVariants;
int black=0; boolean useSnowLands = false;
int colorLess=0;
int cardCount=nonLands.size();
List<PaperCard> cards=new ArrayList<>();
boolean allCardVariants=Config.instance().getSettingData().useAllCardVariants;
for(PaperCard nonLand:nonLands) for (PaperCard nonLand : nonLands) {
{ CardRules rules = nonLand.getRules();
red+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.RED); ManaCost manaCost = rules.getManaCost();
green+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.GREEN);
white+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.WHITE); red += manaCost.getShardCount(ManaCostShard.RED);
blue+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.BLUE); green += manaCost.getShardCount(ManaCostShard.GREEN);
black+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.BLACK); white += manaCost.getShardCount(ManaCostShard.WHITE);
colorLess+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.GENERIC); blue += manaCost.getShardCount(ManaCostShard.BLUE);
black += manaCost.getShardCount(ManaCostShard.BLACK);
colorless += manaCost.getShardCount(ManaCostShard.COLORLESS);
// Check for Snow lands requirement
if (!useSnowLands) {
if (manaCost.getShardCount(ManaCostShard.S) > 0) {
useSnowLands = true;
continue;
} }
float sum= red+ blue+ green+ white+ black;
int neededLands=template.count-cardCount; if (rules.getAiHints() != null && rules.getAiHints().getDeckHints() != null) {
int neededDualLands= Math.round (neededLands*template.rares); useSnowLands = rules.getAiHints().getDeckHints().contains(Type.TYPE, "Snow");
int neededBase=neededLands-neededDualLands; }
}
}
float sumColoredCost = red + blue + green + white + black;
int neededLands = template.count - cardCount;
int neededDualLands = Math.round(neededLands * template.rares);
int neededBase = neededLands - neededDualLands;
String edition = ""; String edition = "";
if (allCardVariants) { if (allCardVariants) {
PaperCard templateLand = CardUtil.getCardByName("Plains"); PaperCard templateLand = CardUtil.getCardByName("Plains");
edition = templateLand.getEdition(); edition = templateLand.getEdition();
} }
if(sum==0.)
{
cards.addAll(generateLands("Wastes",neededLands));
}
else
{
int mount=Math.round(neededBase*(red/sum));
int island=Math.round(neededBase*(blue/sum));
int forest=Math.round(neededBase*(green/sum));
int plains=Math.round(neededBase*(white/sum));
int swamp=Math.round(neededBase*(black/sum));
cards.addAll(generateLands("Plains",plains,edition));
cards.addAll(generateLands("Island",island,edition));
cards.addAll(generateLands("Forest",forest,edition));
cards.addAll(generateLands("Mountain",mount,edition));
cards.addAll(generateLands("Swamp",swamp,edition));
List<String> landTypes=new ArrayList<>();
if(mount>0)
landTypes.add("Mountain");
if(island>0)
landTypes.add("Island");
if(plains>0)
landTypes.add("Plains");
if(swamp>0)
landTypes.add("Swamp");
if(forest>0)
landTypes.add("Forest");
cards.addAll(generateDualLands(landTypes,neededDualLands));
if (sumColoredCost == 0) {
cards.addAll(generateLands("Wastes", neededLands));
} else {
float sumTotalCost = sumColoredCost + colorless;
int mountain = Math.round(neededBase * (red / sumTotalCost));
int island = Math.round(neededBase * (blue / sumTotalCost));
int forest = Math.round(neededBase * (green / sumTotalCost));
int plains = Math.round(neededBase * (white / sumTotalCost));
int swamp = Math.round(neededBase * (black / sumTotalCost));
int wastes = Math.round(neededBase * (colorless / sumTotalCost));
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Plains" : "Plains", plains, edition));
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Island" : "Island", island, edition));
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Forest" : "Forest", forest, edition));
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Mountain" : "Mountain", mountain, edition));
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Swamp" : "Swamp", swamp, edition));
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Wastes" : "Wastes", wastes, edition));
List<String> landTypes = new ArrayList<>();
if (mountain > 0)
landTypes.add("Mountain");
if (island > 0)
landTypes.add("Island");
if (plains > 0)
landTypes.add("Plains");
if (swamp > 0)
landTypes.add("Swamp");
if (forest > 0)
landTypes.add("Forest");
cards.addAll(generateDualLands(landTypes, neededDualLands));
} }
return cards; return cards;
} }
private static Collection<PaperCard> generateDualLands(List<String> landName, int count) { private static Collection<PaperCard> generateDualLands(List<String> landName, int count) {
ArrayList<RewardData> rewards=new ArrayList<>(); ArrayList<RewardData> rewards=new ArrayList<>();
RewardData base= new RewardData(); RewardData base= new RewardData();
@@ -737,14 +754,14 @@ public class CardUtil {
if (deck != null) if (deck != null)
return deck; return deck;
} }
Json json = new Json(); Json json = new Json();
FileHandle handle = Config.instance().getFile(path); FileHandle handle = Config.instance().getFile(path);
if (handle.exists()) if (handle.exists())
return generateDeck(json.fromJson(GeneratedDeckData.class, handle), starterEdition, discourageDuplicates); return generateDeck(json.fromJson(GeneratedDeckData.class, handle), starterEdition, discourageDuplicates);
Deck deck = DeckgenUtil.getRandomOrPreconOrThemeDeck(colors, true, false, true); Deck deck = DeckgenUtil.getRandomOrPreconOrThemeDeck(colors, true, false, true);
System.err.println("Error loading JSON: " + handle.path() + "\nGenerating random deck: "+deck.getName()); System.err.println("Error loading JSON: " + handle.path() + "\nGenerating random deck: " + deck.getName());
return deck; return deck;
} }
private static final GameFormat.Collection formats = FModel.getFormats(); private static final GameFormat.Collection formats = FModel.getFormats();

View File

@@ -1,5 +1,5 @@
{ {
"name":"Crab", "name":"Crab",
"template": "template":
{ {
"count":60, "count":60,