added mono tribal deck generator. removed goblin deck generator (too weak). made deck generators create new instance for every get so tribal deck is reset

master
wait321 2011-10-21 22:35:25 -07:00
parent 69f26427e7
commit f9b3b24983
4 changed files with 139 additions and 62 deletions

View File

@ -1,5 +1,5 @@
White Knights
Goblin
Tribal Mono
Saint & Hero
Human Law
Fairy Horde

View File

@ -20,18 +20,18 @@ public class DeckGenerators {
private static final String FILENAME = "deckgenerators.txt";
private final Map<String, DefaultDeckGenerator> generatorsMap;
private final Map<String, Class> generatorsMap;
private DeckGenerators() {
generatorsMap = new TreeMap<String, DefaultDeckGenerator>();
generatorsMap = new TreeMap<String, Class>();
}
public Set<String> getGeneratorNames() {
return generatorsMap.keySet();
}
public void addDeckGenerator(final String name, final DefaultDeckGenerator generator) {
generatorsMap.put(name, generator);
private void addDeckGenerator(final String name, final Class c) {
generatorsMap.put(name, c);
}
private void addDeckGenerator(final String name) {
@ -39,29 +39,41 @@ public class DeckGenerators {
final String cname = name.replaceAll("[^A-Za-z]", "_");
try { // reflection
final Class c = Class.forName("magic.generator." + cname + "_DeckGenerator");
final DefaultDeckGenerator generator = (DefaultDeckGenerator) c.newInstance();
addDeckGenerator(name, generator);
addDeckGenerator(name, c);
System.err.println("added deck generator " + name);
} catch (final ClassNotFoundException ex) {
// no class found
} catch (final ClassCastException ex) {
throw new RuntimeException(ex);
} catch (final InstantiationException ex) {
throw new RuntimeException(ex);
} catch (final IllegalAccessException ex) {
throw new RuntimeException(ex);
}
}
public DefaultDeckGenerator getDeckGenerator(final String name) {
return generatorsMap.get(name);
return getDeckGenerator(generatorsMap.get(name));
}
private DefaultDeckGenerator getDeckGenerator(final Class c) {
DefaultDeckGenerator gen = null;
if(c != null) {
try {
gen = (DefaultDeckGenerator) c.newInstance();
} catch (final ClassCastException ex) {
throw new RuntimeException(ex);
} catch (final InstantiationException ex) {
throw new RuntimeException(ex);
} catch (final IllegalAccessException ex) {
throw new RuntimeException(ex);
}
}
return gen;
}
private void loadDeckGenerators(final String filename) {
final InputStream stream = this.getClass().getResourceAsStream(filename);
String content = null;
try { // load file

View File

@ -1,49 +0,0 @@
package magic.generator;
import magic.data.CardDefinitions;
import magic.data.CubeDefinitions;
import magic.model.MagicCardDefinition;
import magic.model.MagicColoredType;
import magic.model.MagicCondensedDeck;
import magic.model.MagicCubeDefinition;
import magic.model.MagicPlayerProfile;
import magic.model.MagicRandom;
import java.util.ArrayList;
import java.util.List;
public class Goblin_DeckGenerator extends DefaultDeckGenerator {
private final String colorText = "r";
public Goblin_DeckGenerator() {
super(null);
setCubeDefinition(CubeDefinitions.getInstance().getCubeDefinition(getColorText()));
}
public String getColorText() {
return colorText;
}
public int getMinRarity() {
return 2;
}
public boolean acceptPossibleSpellCard(MagicCardDefinition card) {
return (!card.isCreature()) || card.hasSubType(magic.model.MagicSubType.Goblin);
}
public void addRequiredSpells(MagicCondensedDeck deck) {
String[] cards = {"Wort, Boggart Auntie", "Siege-Gang Commander", "Siege-Gang Commander", "Frenzied Goblin", "Frenzied Goblin", "Goblin Piledriver"};
addRequiredCards(deck, cards);
}
public void setColors(MagicPlayerProfile profile) {
profile.setColors(getColorText());
}
public boolean ignoreMaxCost() {
return true;
}
}

View File

@ -0,0 +1,114 @@
package magic.generator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import magic.data.CardDefinitions;
import magic.data.CubeDefinitions;
import magic.model.MagicCardDefinition;
import magic.model.MagicColor;
import magic.model.MagicCondensedDeck;
import magic.model.MagicPlayerProfile;
import magic.model.MagicSubType;
public class Tribal_Mono_DeckGenerator extends DefaultDeckGenerator {
private static final int MIN_NUM_CARDS_WITH_SUBTYPE = 20;
// all possible tribes - calculated once
private static final ArrayList<MagicSubType> possibleTribes = new ArrayList<MagicSubType>();
private static final ArrayList<ArrayList<String>> possibleColors = new ArrayList<ArrayList<String>>();
// random tribe from all possible for each instance
private final MagicSubType tribe;
private final String colorText;
public Tribal_Mono_DeckGenerator() {
super(null);
if(!hasChoice()) {
getPossibleTribes();
}
if(hasChoice()) {
Random randGen = new Random();
int i = randGen.nextInt(possibleTribes.size());
tribe = possibleTribes.get(i);
colorText = possibleColors.get(i).get(randGen.nextInt(possibleColors.get(i).size()));
} else {
tribe = null;
colorText = "";
}
setCubeDefinition(CubeDefinitions.getInstance().getCubeDefinition(getColorText()));
}
private boolean hasChoice() {
return possibleTribes.size() > 0 && possibleColors.size() == possibleTribes.size();
}
private void getPossibleTribes() {
for(MagicSubType s : MagicSubType.ALL_CREATURES) {
HashMap<MagicColor, Integer> countColors = new HashMap<MagicColor, Integer>();
countColors.put(MagicColor.Black, new Integer(0));
countColors.put(MagicColor.White, new Integer(0));
countColors.put(MagicColor.Green, new Integer(0));
countColors.put(MagicColor.Red, new Integer(0));
countColors.put(MagicColor.Blue, new Integer(0));
// count colors
for(MagicCardDefinition card : CardDefinitions.getInstance().getCards()) {
if(card.hasSubType(s)) {
int colorFlags = card.getColorFlags();
for(MagicColor c : countColors.keySet()) {
if (c.hasColor(colorFlags)) {
countColors.put(c, new Integer(countColors.get(c).intValue() + 1));
}
}
}
}
ArrayList<String> choiceColors = getPossibleColors(countColors);
if(choiceColors.size() > 0) {
possibleTribes.add(s);
possibleColors.add(choiceColors);
}
}
}
private ArrayList<String> getPossibleColors(HashMap<MagicColor, Integer> countColors) {
// monocolor
ArrayList<String> a = new ArrayList<String>();
for(MagicColor c : countColors.keySet()) {
if(countColors.get(c).intValue() > MIN_NUM_CARDS_WITH_SUBTYPE) {
a.add("" + c.getSymbol());
}
}
return a;
}
public String getColorText() {
return colorText;
}
public boolean acceptPossibleSpellCard(MagicCardDefinition card) {
if(hasChoice()) {
return (!card.isCreature()) || card.hasSubType(tribe);
} else {
return true;
}
}
public void setColors(MagicPlayerProfile profile) {
profile.setColors(getColorText());
}
public boolean ignoreMaxCost() {
return true;
}
}