mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Random brawl deck generator working on Desktop
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package forge;
|
package forge;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import forge.card.CardDb;
|
import forge.card.CardDb;
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
import forge.card.CardRules;
|
import forge.card.CardRules;
|
||||||
@@ -32,6 +33,16 @@ public class StaticData {
|
|||||||
private final TokenDb allTokens;
|
private final TokenDb allTokens;
|
||||||
private final CardEdition.Collection editions;
|
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:
|
// Loaded lazily:
|
||||||
private IStorage<SealedProduct.Template> boosters;
|
private IStorage<SealedProduct.Template> boosters;
|
||||||
private IStorage<SealedProduct.Template> specialBoosters;
|
private IStorage<SealedProduct.Template> specialBoosters;
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import forge.util.TextUtil;
|
|||||||
import org.apache.commons.lang3.Range;
|
import org.apache.commons.lang3.Range;
|
||||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||||
|
|
||||||
|
import java.awt.print.Paper;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@@ -69,15 +70,7 @@ public enum DeckFormat {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Pauper ( Range.is(60), Range.between(0, 10), 1),
|
Pauper ( Range.is(60), Range.between(0, 10), 1),
|
||||||
Brawl ( Range.is(59), Range.between(0, 15), 1, new Predicate<CardRules>() {
|
Brawl ( Range.is(59), Range.between(0, 15), 1, StaticData.instance().getStandardPredicate(), null),
|
||||||
@Override
|
|
||||||
public boolean apply(CardRules rules) {
|
|
||||||
//must be standard legal
|
|
||||||
//FModel.getFormats().getStandard();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
TinyLeaders ( Range.is(49), Range.between(0, 10), 1, new Predicate<CardRules>() {
|
TinyLeaders ( Range.is(49), Range.between(0, 10), 1, new Predicate<CardRules>() {
|
||||||
private final Set<String> bannedCards = new HashSet<String>(Arrays.asList(
|
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",
|
"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 Range<Integer> sideRange; // null => no check
|
||||||
private final int maxCardCopies;
|
private final int maxCardCopies;
|
||||||
private final Predicate<CardRules> cardPoolFilter;
|
private final Predicate<CardRules> cardPoolFilter;
|
||||||
|
private final Predicate<PaperCard> paperCardPoolFilter;
|
||||||
private final static String ADVPROCLAMATION = "Advantageous Proclamation";
|
private final static String ADVPROCLAMATION = "Advantageous Proclamation";
|
||||||
private final static String SOVREALM = "Sovereign's Realm";
|
private final static String SOVREALM = "Sovereign's Realm";
|
||||||
|
|
||||||
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0) {
|
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0, Predicate<PaperCard> paperCardPoolFilter0, Predicate<CardRules> cardPoolFilter0) {
|
||||||
this(mainRange0, sideRange0, maxCardCopies0, null);
|
|
||||||
}
|
|
||||||
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0, Predicate<CardRules> cardPoolFilter0) {
|
|
||||||
mainRange = mainRange0;
|
mainRange = mainRange0;
|
||||||
sideRange = sideRange0;
|
sideRange = sideRange0;
|
||||||
maxCardCopies = maxCardCopies0;
|
maxCardCopies = maxCardCopies0;
|
||||||
cardPoolFilter = cardPoolFilter0;
|
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() {
|
private boolean hasCommander() {
|
||||||
@@ -374,9 +382,18 @@ public enum DeckFormat {
|
|||||||
|
|
||||||
public IDeckGenPool getCardPool(IDeckGenPool basePool) {
|
public IDeckGenPool getCardPool(IDeckGenPool basePool) {
|
||||||
if (cardPoolFilter == null) {
|
if (cardPoolFilter == null) {
|
||||||
|
if (paperCardPoolFilter == null) {
|
||||||
return basePool;
|
return basePool;
|
||||||
}
|
}
|
||||||
DeckGenPool filteredPool = new DeckGenPool();
|
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()) {
|
for (PaperCard pc : basePool.getAllCards()) {
|
||||||
if (cardPoolFilter.apply(pc.getRules())) {
|
if (cardPoolFilter.apply(pc.getRules())) {
|
||||||
filteredPool.add(pc);
|
filteredPool.add(pc);
|
||||||
@@ -391,8 +408,11 @@ public enum DeckFormat {
|
|||||||
|
|
||||||
public boolean isLegalCard(PaperCard pc) {
|
public boolean isLegalCard(PaperCard pc) {
|
||||||
if (cardPoolFilter == null) {
|
if (cardPoolFilter == null) {
|
||||||
|
if (paperCardPoolFilter == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return paperCardPoolFilter.apply(pc);
|
||||||
|
}
|
||||||
return cardPoolFilter.apply(pc.getRules());
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -180,8 +180,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateRandomCommander() {
|
private void updateRandomCommander() {
|
||||||
if((!lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Commander)&&
|
if((!lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Commander))&&
|
||||||
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.TinyLeaders)))){
|
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.TinyLeaders))&&
|
||||||
|
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Brawl))){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lstDecks.setAllowMultipleSelections(false);
|
lstDecks.setAllowMultipleSelections(false);
|
||||||
@@ -202,8 +203,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateRandomCardGenCommander() {
|
private void updateRandomCardGenCommander() {
|
||||||
if((!lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Commander)&&
|
if((!lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Commander))&&
|
||||||
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.TinyLeaders)))){
|
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.TinyLeaders))&&
|
||||||
|
!(lstDecks.getGameType().getDeckFormat().equals(DeckFormat.Brawl))){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lstDecks.setAllowMultipleSelections(false);
|
lstDecks.setAllowMultipleSelections(false);
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class CommanderDeckGenerator extends DeckProxy implements Comparable<CommanderDeckGenerator> {
|
public class CommanderDeckGenerator extends DeckProxy implements Comparable<CommanderDeckGenerator> {
|
||||||
public static List<DeckProxy> getCommanderDecks(final DeckFormat format, boolean isForAi, boolean isCardGen){
|
public static List<DeckProxy> getCommanderDecks(final DeckFormat format, boolean isForAi, boolean isCardGen){
|
||||||
|
if(format.equals(DeckFormat.Brawl)){
|
||||||
|
return getBrawlDecks(format, isForAi, isCardGen);
|
||||||
|
}
|
||||||
ItemPool uniqueCards;
|
ItemPool uniqueCards;
|
||||||
if(isCardGen){
|
if(isCardGen){
|
||||||
uniqueCards = new ItemPool<PaperCard>(PaperCard.class);
|
uniqueCards = new ItemPool<PaperCard>(PaperCard.class);
|
||||||
@@ -50,6 +53,31 @@ public class CommanderDeckGenerator extends DeckProxy implements Comparable<Comm
|
|||||||
return decks;
|
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 PaperCard legend;
|
||||||
private final int index;
|
private final int index;
|
||||||
private final DeckFormat format;
|
private final DeckFormat format;
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ public class DeckProxy implements InventoryItem {
|
|||||||
return FModel.getFormats().getStandard().isDeckLegal(input);
|
return FModel.getFormats().getStandard().isDeckLegal(input);
|
||||||
}
|
}
|
||||||
}, filter);
|
}, filter);
|
||||||
addDecksRecursivelly("Tiny Leaders", GameType.Brawl, result, "", FModel.getDecks().getBrawl(), filter);
|
addDecksRecursivelly("Brawl", GameType.Brawl, result, "", FModel.getDecks().getBrawl(), filter);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -542,7 +542,11 @@ public class DeckgenUtil {
|
|||||||
PaperCard selectedPartner=null;
|
PaperCard selectedPartner=null;
|
||||||
if(isCardGen){
|
if(isCardGen){
|
||||||
List<Map.Entry<PaperCard,Integer>> potentialCards = new ArrayList<>();
|
List<Map.Entry<PaperCard,Integer>> potentialCards = new ArrayList<>();
|
||||||
|
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()));
|
potentialCards.addAll(CardRelationMatrixGenerator.cardPools.get(DeckFormat.Commander.toString()).get(commander.getName()));
|
||||||
|
}
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
//Collections.shuffle(potentialCards, r);
|
//Collections.shuffle(potentialCards, r);
|
||||||
List<PaperCard> preSelectedCards = new ArrayList<>();
|
List<PaperCard> preSelectedCards = new ArrayList<>();
|
||||||
@@ -590,9 +594,17 @@ public class DeckgenUtil {
|
|||||||
Iterable<PaperCard> colorList = Iterables.filter(format.getCardPool(cardDb).getAllCards(),
|
Iterable<PaperCard> colorList = Iterables.filter(format.getCardPool(cardDb).getAllCards(),
|
||||||
Predicates.compose(Predicates.or(new CardThemedDeckBuilder.MatchColorIdentity(commander.getRules().getColorIdentity()),
|
Predicates.compose(Predicates.or(new CardThemedDeckBuilder.MatchColorIdentity(commander.getRules().getColorIdentity()),
|
||||||
DeckGeneratorBase.COLORLESS_CARDS), PaperCard.FN_GET_RULES));
|
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);
|
List<PaperCard> cardList = Lists.newArrayList(colorList);
|
||||||
Collections.shuffle(cardList, new Random());
|
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);
|
gen = new CardThemedCommanderDeckBuilder(commander, selectedPartner,shortList,forAi,format);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,6 +173,8 @@ public final class FModel {
|
|||||||
formats.add(format);
|
formats.add(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
magicDb.setStandardPredicate(formats.getStandard().getFilterPrinted());
|
||||||
|
|
||||||
blocks = new StorageBase<>("Block definitions", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "blocks.txt", magicDb.getEditions()));
|
blocks = new StorageBase<>("Block definitions", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "blocks.txt", magicDb.getEditions()));
|
||||||
questPreferences = new QuestPreferences();
|
questPreferences = new QuestPreferences();
|
||||||
conquestPreferences = new ConquestPreferences();
|
conquestPreferences = new ConquestPreferences();
|
||||||
|
|||||||
Reference in New Issue
Block a user