Random brawl deck generator working on Desktop

This commit is contained in:
austinio7116
2018-03-28 23:41:57 +01:00
committed by maustin
parent b9aef9b317
commit ed564b904f
7 changed files with 104 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
package forge;
import com.google.common.base.Predicate;
import forge.card.CardDb;
import forge.card.CardEdition;
import forge.card.CardRules;
@@ -32,6 +33,16 @@ public class StaticData {
private final TokenDb allTokens;
private final CardEdition.Collection editions;
public Predicate<PaperCard> getStandardPredicate() {
return standardPredicate;
}
public void setStandardPredicate(Predicate<PaperCard> standardPredicate) {
this.standardPredicate = standardPredicate;
}
private Predicate<PaperCard> standardPredicate;
// Loaded lazily:
private IStorage<SealedProduct.Template> boosters;
private IStorage<SealedProduct.Template> specialBoosters;

View File

@@ -35,6 +35,7 @@ import forge.util.TextUtil;
import org.apache.commons.lang3.Range;
import org.apache.commons.lang3.tuple.ImmutablePair;
import java.awt.print.Paper;
import java.util.*;
import java.util.Map.Entry;
@@ -69,15 +70,7 @@ public enum DeckFormat {
}
}),
Pauper ( Range.is(60), Range.between(0, 10), 1),
Brawl ( Range.is(59), Range.between(0, 15), 1, new Predicate<CardRules>() {
@Override
public boolean apply(CardRules rules) {
//must be standard legal
//FModel.getFormats().getStandard();
return true;
}
}),
Brawl ( Range.is(59), Range.between(0, 15), 1, StaticData.instance().getStandardPredicate(), null),
TinyLeaders ( Range.is(49), Range.between(0, 10), 1, new Predicate<CardRules>() {
private final Set<String> bannedCards = new HashSet<String>(Arrays.asList(
"Ancestral Recall", "Balance", "Black Lotus", "Black Vise", "Channel", "Chaos Orb", "Contract From Below", "Counterbalance", "Darkpact", "Demonic Attorney", "Demonic Tutor", "Earthcraft", "Edric, Spymaster of Trest", "Falling Star",
@@ -127,17 +120,32 @@ public enum DeckFormat {
private final Range<Integer> sideRange; // null => no check
private final int maxCardCopies;
private final Predicate<CardRules> cardPoolFilter;
private final Predicate<PaperCard> paperCardPoolFilter;
private final static String ADVPROCLAMATION = "Advantageous Proclamation";
private final static String SOVREALM = "Sovereign's Realm";
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0) {
this(mainRange0, sideRange0, maxCardCopies0, null);
}
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0, Predicate<CardRules> cardPoolFilter0) {
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0, Predicate<PaperCard> paperCardPoolFilter0, Predicate<CardRules> cardPoolFilter0) {
mainRange = mainRange0;
sideRange = sideRange0;
maxCardCopies = maxCardCopies0;
cardPoolFilter = cardPoolFilter0;
paperCardPoolFilter = paperCardPoolFilter0;
}
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0, Predicate<CardRules> cardPoolFilter0) {
mainRange = mainRange0;
sideRange = sideRange0;
maxCardCopies = maxCardCopies0;
paperCardPoolFilter = null;
cardPoolFilter = cardPoolFilter0;
}
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0) {
mainRange = mainRange0;
sideRange = sideRange0;
maxCardCopies = maxCardCopies0;
paperCardPoolFilter = null;
cardPoolFilter = null;
}
private boolean hasCommander() {
@@ -374,7 +382,16 @@ public enum DeckFormat {
public IDeckGenPool getCardPool(IDeckGenPool basePool) {
if (cardPoolFilter == null) {
return basePool;
if (paperCardPoolFilter == null) {
return basePool;
}
DeckGenPool filteredPool = new DeckGenPool();
for (PaperCard pc : basePool.getAllCards()) {
if (paperCardPoolFilter.apply(pc)) {
filteredPool.add(pc);
}
}
return filteredPool;
}
DeckGenPool filteredPool = new DeckGenPool();
for (PaperCard pc : basePool.getAllCards()) {
@@ -391,7 +408,10 @@ public enum DeckFormat {
public boolean isLegalCard(PaperCard pc) {
if (cardPoolFilter == null) {
return true;
if (paperCardPoolFilter == null) {
return true;
}
return paperCardPoolFilter.apply(pc);
}
return cardPoolFilter.apply(pc.getRules());
}
@@ -426,6 +446,13 @@ public enum DeckFormat {
}
}
}
if (paperCardPoolFilter != null) {
for (final Entry<PaperCard, Integer> cp : deck.getAllCardsInASinglePool()) {
if (!paperCardPoolFilter.apply(cp.getKey())) {
return false;
}
}
}
return true;
}
};

View File

@@ -180,8 +180,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
}
private void updateRandomCommander() {
if((!lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Commander)&&
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.TinyLeaders)))){
if((!lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Commander))&&
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.TinyLeaders))&&
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Brawl))){
return;
}
lstDecks.setAllowMultipleSelections(false);
@@ -202,8 +203,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
}
private void updateRandomCardGenCommander() {
if((!lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Commander)&&
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.TinyLeaders)))){
if((!lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Commander))&&
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.TinyLeaders))&&
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Brawl))){
return;
}
lstDecks.setAllowMultipleSelections(false);

View File

@@ -23,6 +23,9 @@ import java.util.Map;
*/
public class CommanderDeckGenerator extends DeckProxy implements Comparable<CommanderDeckGenerator> {
public static List<DeckProxy> getCommanderDecks(final DeckFormat format, boolean isForAi, boolean isCardGen){
if(format.equals(DeckFormat.Brawl)){
return getBrawlDecks(format, isForAi, isCardGen);
}
ItemPool uniqueCards;
if(isCardGen){
uniqueCards = new ItemPool<PaperCard>(PaperCard.class);
@@ -50,6 +53,31 @@ public class CommanderDeckGenerator extends DeckProxy implements Comparable<Comm
return decks;
}
public static List<DeckProxy> getBrawlDecks(final DeckFormat format, boolean isForAi, boolean isCardGen){
ItemPool uniqueCards;
if(isCardGen){
uniqueCards = new ItemPool<PaperCard>(PaperCard.class);
//TODO: upate to actual Brawl model from real Brawl decks
Iterable<String> legendNames=CardRelationMatrixGenerator.cardPools.get(FModel.getFormats().getStandard().getName()).keySet();
for(String legendName:legendNames) {
uniqueCards.add(FModel.getMagicDb().getCommonCards().getUniqueByName(legendName));
}
}else {
uniqueCards = ItemPool.createFrom(FModel.getMagicDb().getCommonCards().getUniqueCards(), PaperCard.class);
}
Predicate<CardRules> canPlay = isForAi ? DeckGeneratorBase.AI_CAN_PLAY : DeckGeneratorBase.HUMAN_CAN_PLAY;
@SuppressWarnings("unchecked")
Iterable<PaperCard> legends = Iterables.filter(uniqueCards.toFlatList(), Predicates.and(format.isLegalCardPredicate(),
Predicates.compose(Predicates.and(
CardRulesPredicates.Presets.CAN_BE_BRAWL_COMMANDER,
canPlay), PaperCard.FN_GET_RULES)));
final List<DeckProxy> decks = new ArrayList<DeckProxy>();
for(PaperCard legend: legends) {
decks.add(new CommanderDeckGenerator(legend, format, isForAi, isCardGen));
}
return decks;
}
private final PaperCard legend;
private final int index;
private final DeckFormat format;

View File

@@ -387,7 +387,7 @@ public class DeckProxy implements InventoryItem {
return FModel.getFormats().getStandard().isDeckLegal(input);
}
}, filter);
addDecksRecursivelly("Tiny Leaders", GameType.Brawl, result, "", FModel.getDecks().getBrawl(), filter);
addDecksRecursivelly("Brawl", GameType.Brawl, result, "", FModel.getDecks().getBrawl(), filter);
return result;
}

View File

@@ -542,7 +542,11 @@ public class DeckgenUtil {
PaperCard selectedPartner=null;
if(isCardGen){
List<Map.Entry<PaperCard,Integer>> potentialCards = new ArrayList<>();
potentialCards.addAll(CardRelationMatrixGenerator.cardPools.get(DeckFormat.Commander.toString()).get(commander.getName()));
if(format.equals(DeckFormat.Brawl)){
potentialCards.addAll(CardRelationMatrixGenerator.cardPools.get(FModel.getFormats().getStandard().getName()).get(commander.getName()));
}else {
potentialCards.addAll(CardRelationMatrixGenerator.cardPools.get(DeckFormat.Commander.toString()).get(commander.getName()));
}
Random r = new Random();
//Collections.shuffle(potentialCards, r);
List<PaperCard> preSelectedCards = new ArrayList<>();
@@ -590,9 +594,17 @@ public class DeckgenUtil {
Iterable<PaperCard> colorList = Iterables.filter(format.getCardPool(cardDb).getAllCards(),
Predicates.compose(Predicates.or(new CardThemedDeckBuilder.MatchColorIdentity(commander.getRules().getColorIdentity()),
DeckGeneratorBase.COLORLESS_CARDS), PaperCard.FN_GET_RULES));
if(format.equals(DeckFormat.Brawl)){
Iterable<PaperCard> colorListFiltered = Iterables.filter(colorList,FModel.getFormats().getStandard().getFilterPrinted());
colorList=colorListFiltered;
}
List<PaperCard> cardList = Lists.newArrayList(colorList);
Collections.shuffle(cardList, new Random());
List<PaperCard> shortList = cardList.subList(1, 400);
int shortlistlength=400;
if(cardList.size()<400){
shortlistlength=cardList.size();
}
List<PaperCard> shortList = cardList.subList(1, shortlistlength);
gen = new CardThemedCommanderDeckBuilder(commander, selectedPartner,shortList,forAi,format);
}

View File

@@ -173,6 +173,8 @@ public final class FModel {
formats.add(format);
}
magicDb.setStandardPredicate(formats.getStandard().getFilterPrinted());
blocks = new StorageBase<>("Block definitions", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "blocks.txt", magicDb.getEditions()));
questPreferences = new QuestPreferences();
conquestPreferences = new ConquestPreferences();