merged with changes to generated decks

master
beholder 2011-10-08 11:09:53 +02:00
commit f942a9419b
6 changed files with 86 additions and 29 deletions

View File

@ -107,7 +107,7 @@ public class DeckGenerator {
countNonlandNoncreature++;
}
if(card.getColoredType()==MagicColoredType.Colorless) {
if(card.getColoredType() == MagicColoredType.Colorless) {
countColorless++;
}
@ -123,8 +123,13 @@ public class DeckGenerator {
spellCards.remove(index);
if (cardDefinition.isPlayable(profile)) {
final boolean creature=cardDefinition.isCreature();
if (!creature && !cardDefinition.isLand() && countNonlandNoncreature >= maxNonlandNoncreature) {
final boolean creature = cardDefinition.isCreature();
if(creature && countCreatures >= maxCreatures) {
continue;
}
if (!creature && countNonlandNoncreature >= maxNonlandNoncreature) {
continue;
}
@ -134,14 +139,16 @@ public class DeckGenerator {
}
final int bucket=cardDefinition.getCostBucket();
if (countCost[bucket]>=maxCost[bucket]) {
if (!ignoreMaxCost() && countCost[bucket]>=maxCost[bucket]) {
continue;
}
deck.add(cardDefinition);
countCost[bucket]++;
if (!creature) {
if(creature) {
countCreatures++;
} else {
countNonlandNoncreature++;
}
if (colorless) {
@ -152,7 +159,7 @@ public class DeckGenerator {
if (spellCards.size() == 0) {
genSpells();
}
}
}
// Add non basic lands to deck.
while (deck.size() < spells+lands && landCards.size() > 0) {
@ -166,7 +173,11 @@ public class DeckGenerator {
}
}
public void addRequiredCards(MagicDeck deck) { }
public void setColors(MagicPlayerProfile profile) { }
public void addRequiredCards(MagicDeck deck) { }
public boolean ignoreMaxCost() {
return false;
}
}

View File

@ -103,6 +103,8 @@ public class TournamentConfig {
return new MagicPlayerProfile(MagicColor.getRandomColors(2));
} else if (ANY_ONE.equals(colorText)) {
return new MagicPlayerProfile(MagicColor.getRandomColors(1));
} else if (colorText.equals("Knight")) {
return new MagicPlayerProfile("", "KnightDeckGenerator");
}
return new MagicPlayerProfile(colorText);
}

View File

@ -20,7 +20,11 @@ public class KnightDeckGenerator extends DeckGenerator {
public KnightDeckGenerator() {
super(null);
setCubeDefinition(CubeDefinitions.getInstance().getCubeDefinition(colorText));
setCubeDefinition(CubeDefinitions.getInstance().getCubeDefinition(getColorText()));
}
public String getColorText() {
return colorText;
}
public int getMinRarity() {
@ -28,7 +32,7 @@ public class KnightDeckGenerator extends DeckGenerator {
}
public boolean acceptPossibleSpellCard(MagicCardDefinition card) {
return !card.isCreature() || card.hasSubType(magic.model.MagicSubType.Knight);
return (!card.isCreature()) || card.hasSubType(magic.model.MagicSubType.Knight);
}
public void addRequiredCards(MagicDeck deck) {
@ -45,6 +49,10 @@ public class KnightDeckGenerator extends DeckGenerator {
}
public void setColors(MagicPlayerProfile profile) {
profile.setColors(colorText);
profile.setColors(getColorText());
}
public boolean ignoreMaxCost() {
return true;
}
}

View File

@ -2,11 +2,17 @@ package magic.model;
public class MagicPlayerProfile {
private String deckGeneratorName;
private String colorText;
private MagicColor[] colors;
public MagicPlayerProfile(final String colorText) {
this(colorText, null);
}
public MagicPlayerProfile(final String colorText, final String deckGeneratorName) {
setColors(colorText);
setDeckGeneratorName(deckGeneratorName);
}
public void setColors(final String colorText) {
@ -19,6 +25,14 @@ public class MagicPlayerProfile {
}
}
public void setDeckGeneratorName(final String name) {
this.deckGeneratorName = name;
}
public String getDeckGeneratorName() {
return deckGeneratorName;
}
String getColorText() {
return colorText;

View File

@ -211,11 +211,14 @@ public class MagicTournament {
private void buildDecks() {
final MagicCubeDefinition cubeDefinition=CubeDefinitions.getInstance().getCubeDefinition(configuration.getCube());
final DeckGenerator generator=new DeckGenerator(cubeDefinition);
// final DeckGenerator generator=new magic.data.generator.KnightDeckGenerator();
final DeckGenerator generator = new DeckGenerator(cubeDefinition);
for (final MagicPlayerDefinition player : playerDefinitions) {
if (player.getProfile().getNrOfColors()==0) {
DeckUtils.loadRandomDeck(player);
if (player.getProfile().getNrOfColors() == 0) {
if(player.getProfile().getDeckGeneratorName() != null) {
player.generateDeck(new magic.data.generator.KnightDeckGenerator());
} else {
DeckUtils.loadRandomDeck(player);
}
} else {
player.generateDeck(generator);
}

View File

@ -264,6 +264,8 @@ public class TournamentDialog extends JDialog implements ActionListener {
model.addElement("w");
model.addElement("*");
model.addElement("@");
model.addElement("---");
model.addElement("Knight");
setModel(model);
setSelectedItem(colors);
this.setFocusable(false);
@ -277,23 +279,40 @@ public class TournamentDialog extends JDialog implements ActionListener {
final boolean isSelected,
final boolean cellHasFocus) {
final String colors=(String)value;
final JPanel panel=new JPanel(new GridLayout(1,3));
for (int i=0;i<colors.length();i++) {
final char ch=colors.charAt(i);
final ImageIcon icon;
switch (ch) {
case '*': icon=IconImages.ANY; break;
case '@': icon=IconImages.FOLDER; break;
default: icon=MagicColor.getColor(ch).getIcon(); break;
if(colors == "---") {
return new javax.swing.JSeparator(javax.swing.JSeparator.HORIZONTAL);
} else if(colors == "Knight") {
final JPanel panel=new JPanel(new GridLayout(1,1));
panel.setBorder(FontsAndBorders.EMPTY_BORDER);
if (isSelected) {
panel.setBackground(Color.LIGHT_GRAY);
}
panel.add(new JLabel(icon));
JLabel label = new JLabel(colors, JLabel.CENTER);
label.setFont(FontsAndBorders.FONT2);
panel.add(label);
return panel;
} else {
final JPanel panel=new JPanel(new GridLayout(1,3));
for (int i=0;i<colors.length();i++) {
final char ch=colors.charAt(i);
final ImageIcon icon;
switch (ch) {
case '*': icon=IconImages.ANY; break;
case '@': icon=IconImages.FOLDER; break;
default: icon=MagicColor.getColor(ch).getIcon(); break;
}
panel.add(new JLabel(icon));
}
panel.setBorder(FontsAndBorders.EMPTY_BORDER);
if (isSelected) {
panel.setBackground(Color.LIGHT_GRAY);
}
return panel;
}
panel.setBorder(FontsAndBorders.EMPTY_BORDER);
if (isSelected) {
panel.setBackground(Color.LIGHT_GRAY);
}
return panel;
}
}
}