delete obselete deck generators

This commit is contained in:
jendave
2012-02-24 08:00:26 +00:00
parent 3a30d29235
commit 23164a9219
7 changed files with 5 additions and 1131 deletions

5
.gitattributes vendored
View File

@@ -11251,12 +11251,9 @@ src/main/java/forge/deck/DeckBase.java -text
src/main/java/forge/deck/DeckGroup.java -text
src/main/java/forge/deck/DeckRecognizer.java -text
src/main/java/forge/deck/DeckSection.java -text
src/main/java/forge/deck/generate/DeckGenerator.java -text
src/main/java/forge/deck/generate/Generate2ColorDeck.java svneol=native#text/plain
src/main/java/forge/deck/generate/Generate3ColorDeck.java svneol=native#text/plain
src/main/java/forge/deck/generate/Generate5ColorDeck.java svneol=native#text/plain
src/main/java/forge/deck/generate/GenerateConstructedDeck.java svneol=native#text/plain
src/main/java/forge/deck/generate/GenerateConstructedMultiColorDeck.java svneol=native#text/plain
src/main/java/forge/deck/generate/GenerateDeckUtil.java -text
src/main/java/forge/deck/generate/GenerateThemeDeck.java svneol=native#text/plain
src/main/java/forge/deck/generate/package-info.java svneol=native#text/plain
@@ -11531,8 +11528,6 @@ src/test/java/forge/card/mana/ManaPartTest.java svneol=native#text/plain
src/test/java/forge/deck/generate/Generate2ColorDeckTest.java svneol=native#text/plain
src/test/java/forge/deck/generate/Generate3ColorDeckTest.java svneol=native#text/plain
src/test/java/forge/deck/generate/Generate5ColorDeckTest.java svneol=native#text/plain
src/test/java/forge/deck/generate/GenerateConstructedDeckTest.java svneol=native#text/plain
src/test/java/forge/deck/generate/GenerateConstructedMultiColorDeckTest.java svneol=native#text/plain
src/test/java/forge/gui/ListChooserTest.java svneol=native#text/plain
src/test/java/forge/gui/game/CardDetailPanelTest.java svneol=native#text/plain
src/test/java/forge/model/BuildInfoTest.java -text

View File

@@ -1,289 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.deck.generate;
import java.util.ArrayList;
import java.util.Random;
import forge.Constant;
import forge.PlayerType;
import forge.deck.Deck;
import forge.gui.GuiUtils;
import forge.util.MyRandom;
/**
* Utility class to hold add deck generation routines, methods moved from
* OldGuiNewGame.
*
*/
public abstract class DeckGenerator {
/**
* <p>
* genDecks.
* </p>
*
* @param playerType
* the player type {@link java.lang.String} object.
*/
public static void genDecks(final PlayerType playerType) {
// TODO jendave to refactor deck generation
Deck d = null;
final ArrayList<String> decks = new ArrayList<String>();
decks.add("2-Color Deck");
decks.add("3-Color Deck");
decks.add("5-Color Deck");
decks.add("2-Color Deck (original)");
decks.add("3-Color Deck (original)");
decks.add("5-Color Deck (original)");
decks.add("Semi-Random Theme Deck");
final String playerName = playerType.equals(PlayerType.HUMAN) ? "Human" : "Computer";
final String prompt = String.format("Generate %s Deck", playerName);
final Object o = GuiUtils.getChoice(prompt, decks.toArray());
if (o.toString().equals(decks.get(0))) {
d = DeckGenerator.generate2ColorDeck(playerType);
} else if (o.toString().equals(decks.get(1))) {
d = DeckGenerator.generate3ColorDeck(playerType);
} else if (o.toString().equals(decks.get(2))) {
d = DeckGenerator.generate5ColorDeck(playerType);
} else if (o.toString().equals(decks.get(3))) {
d = DeckGenerator.generateConstructedDeck();
} else if (o.toString().equals(decks.get(4))) {
d = DeckGenerator.generateConstructed3ColorDeck();
} else if (o.toString().equals(decks.get(5))) {
d = DeckGenerator.generateConstructed5ColorDeck();
} else if (o.toString().equals(decks.get(6))) {
d = DeckGenerator.generateConstructedThemeDeck();
}
if (playerType.equals(PlayerType.HUMAN)) {
Constant.Runtime.HUMAN_DECK[0] = d;
} else if (playerType.equals(PlayerType.COMPUTER)) {
Constant.Runtime.COMPUTER_DECK[0] = d;
}
}
/**
* <p>
* generateConstructedDeck.
* </p>
*
* @return a {@link forge.deck.Deck} object.
*/
private static Deck generateConstructedDeck() {
final GenerateConstructedDeck gen = new GenerateConstructedDeck();
final Deck deck = new Deck();
deck.getMain().add(gen.generateDeck());
return deck;
}
/**
* <p>
* generateConstructed3ColorDeck.
* </p>
*
* @return a {@link forge.deck.Deck} object.
*/
private static Deck generateConstructed3ColorDeck() {
final GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
final Deck deck = new Deck();
deck.getMain().add(gen.generate3ColorDeck());
return deck;
}
/**
* <p>
* generateConstructed5ColorDeck.
* </p>
*
* @return a {@link forge.deck.Deck} object.
*/
private static Deck generateConstructed5ColorDeck() {
final GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
final Deck deck = new Deck();
deck.getMain().add(gen.generate5ColorDeck());
return deck;
}
/**
* <p>
* generateConstructedThemeDeck.
* </p>
*
* @return a {@link forge.deck.Deck} object.
*/
private static Deck generateConstructedThemeDeck() {
final GenerateThemeDeck gen = new GenerateThemeDeck();
final ArrayList<String> tNames = GenerateThemeDeck.getThemeNames();
tNames.add(0, "Random");
final Object o = GuiUtils.getChoice("Select a theme.", tNames.toArray());
String stDeck;
if (o.toString().equals("Random")) {
final Random r = MyRandom.getRandom();
stDeck = tNames.get(r.nextInt(tNames.size() - 1) + 1);
} else {
stDeck = o.toString();
}
final Deck deck = new Deck();
deck.getMain().add(gen.getThemeDeck(stDeck, 60));
return deck;
}
/**
* <p>
* generate2ColorDeck.
* </p>
*
* @param p
* a {@link java.lang.String} object.
* @return a {@link forge.deck.Deck} object.
*/
private static Deck generate2ColorDeck(final PlayerType p) {
final Random r = MyRandom.getRandom();
final ArrayList<String> colors = new ArrayList<String>();
colors.add("Random");
colors.add("white");
colors.add("blue");
colors.add("black");
colors.add("red");
colors.add("green");
String c1;
String c2;
if (p.equals(PlayerType.HUMAN)) {
c1 = GuiUtils.getChoice("Select first color.", colors.toArray()).toString();
if (c1.equals("Random")) {
c1 = colors.get(r.nextInt(colors.size() - 1) + 1);
}
colors.remove(c1);
c2 = GuiUtils.getChoice("Select second color.", colors.toArray()).toString();
if (c2.equals("Random")) {
c2 = colors.get(r.nextInt(colors.size() - 1) + 1);
}
} else {
// if (p.equals("C"))
c1 = colors.get(r.nextInt(colors.size() - 1) + 1);
colors.remove(c1);
c2 = colors.get(r.nextInt(colors.size() - 1) + 1);
}
final Generate2ColorDeck gen = new Generate2ColorDeck(c1, c2);
final Deck deck = new Deck();
deck.getMain().add(gen.get2ColorDeck(60, p));
return deck;
}
/**
* <p>
* generate3ColorDeck.
* </p>
*
* @param p
* a {@link java.lang.String} object.
* @return a {@link forge.deck.Deck} object.
*/
private static Deck generate3ColorDeck(final PlayerType p) {
final Random r = MyRandom.getRandom();
final ArrayList<String> colors = new ArrayList<String>();
colors.add("Random");
colors.add("white");
colors.add("blue");
colors.add("black");
colors.add("red");
colors.add("green");
String c1;
String c2;
String c3;
if (p.equals(PlayerType.HUMAN)) {
c1 = GuiUtils.getChoice("Select first color.", colors.toArray()).toString();
if (c1.equals("Random")) {
c1 = colors.get(r.nextInt(colors.size() - 1) + 1);
}
colors.remove(c1);
c2 = GuiUtils.getChoice("Select second color.", colors.toArray()).toString();
if (c2.equals("Random")) {
c2 = colors.get(r.nextInt(colors.size() - 1) + 1);
}
colors.remove(c2);
c3 = GuiUtils.getChoice("Select third color.", colors.toArray()).toString();
if (c3.equals("Random")) {
c3 = colors.get(r.nextInt(colors.size() - 1) + 1);
}
} else {
// if (p.equals("C"))
c1 = colors.get(r.nextInt(colors.size() - 1) + 1);
colors.remove(c1);
c2 = colors.get(r.nextInt(colors.size() - 1) + 1);
colors.remove(c2);
c3 = colors.get(r.nextInt(colors.size() - 1) + 1);
}
final Generate3ColorDeck gen = new Generate3ColorDeck(c1, c2, c3);
final Deck deck = new Deck();
deck.getMain().add(gen.get3ColorDeck(60, p));
return deck;
}
/**
* <p>
* generate5ColorDeck.
* </p>
*
* @param p
* a {@link java.lang.String} object.
* @return a {@link forge.deck.Deck} object.
*/
private static Deck generate5ColorDeck(final PlayerType p) {
// Random r = MyRandom.random;
// ArrayList<String> colors = new ArrayList<String>();
// colors.add("Random");
// colors.add("white");
// colors.add("blue");
// colors.add("black");
// colors.add("red");
// colors.add("green");
final Generate5ColorDeck gen = new Generate5ColorDeck("white", "blue", "black", "red", "green");
final Deck deck = new Deck();
deck.getMain().add(gen.get5ColorDeck(60, p));
return deck;
}
}

View File

@@ -1,243 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.deck.generate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import forge.AllZone;
import forge.Card;
import forge.CardFilter;
import forge.CardList;
import forge.CardListFilter;
import forge.CardListUtil;
import forge.CardUtil;
import forge.Constant;
import forge.Singletons;
import forge.properties.ForgePreferences.FPref;
/**
* <p>
* GenerateConstructedDeck class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class GenerateConstructedDeck {
private String color1;
private String color2;
private final Map<String, String> map = new HashMap<String, String>();
/**
* <p>
* Constructor for GenerateConstructedDeck.
* </p>
*/
public GenerateConstructedDeck() {
this.setupMap();
}
/**
* <p>
* setupMap.
* </p>
*/
private void setupMap() {
this.map.put(Constant.Color.BLACK, "Swamp");
this.map.put(Constant.Color.BLUE, "Island");
this.map.put(Constant.Color.GREEN, "Forest");
this.map.put(Constant.Color.RED, "Mountain");
this.map.put(Constant.Color.WHITE, "Plains");
}
/**
* <p>
* generateDeck.
* </p>
*
* @return a {@link forge.CardList} object.
*/
public final CardList generateDeck() {
CardList deck;
int check;
do {
deck = this.get2ColorDeck();
check = deck.getType("Creature").size();
} while ((check < 16) || (24 < check));
this.addLand(deck);
if (deck.size() != 60) {
throw new RuntimeException(
"GenerateConstructedDeck() : generateDeck() error, deck size it not 60, deck size is "
+ deck.size());
}
return deck;
}
// 25 lands
/**
* <p>
* addLand.
* </p>
*
* @param list
* a {@link forge.CardList} object.
*/
private void addLand(final CardList list) {
Card land;
for (int i = 0; i < 13; i++) {
land = AllZone.getCardFactory().getCard(this.map.get(this.color1).toString(), AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.map.get(this.color2).toString(), AllZone.getComputerPlayer());
list.add(land);
}
} // addLand()
/**
* Creates a CardList from the set of all cards that meets the criteria for
* color(s), type, whether the card is suitable for placement in random
* decks and in AI decks, etc.
*
* @see #filterBadCards(Iterable)
*
* @return a subset of cards <= the set of all cards; might be empty, but
* never null
*/
private CardList getCards() {
return this.filterBadCards(AllZone.getCardFactory());
} // getCards()
/**
* <p>
* get2ColorDeck.
* </p>
*
* @return a {@link forge.CardList} object.
*/
private CardList get2ColorDeck() {
final CardList deck = this.get2Colors(this.getCards());
final CardList out = new CardList();
deck.shuffle();
// trim deck size down to 34 cards, presumes 26 land, for a total of 60
// cards
for (int i = 0; (i < 34) && (i < deck.size()); i++) {
out.add(deck.get(i));
}
return out;
}
/**
* <p>
* get2Colors.
* </p>
*
* @param in
* a {@link forge.CardList} object.
* @return a {@link forge.CardList} object.
*/
private CardList get2Colors(final CardList in) {
int a;
int b;
do {
a = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS);
b = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS);
} while (a == b); // do not want to get the same color twice
this.color1 = Constant.Color.ONLY_COLORS[a];
this.color2 = Constant.Color.ONLY_COLORS[b];
CardList out = new CardList();
out.addAll(CardListUtil.getColor(in, this.color1));
out.addAll(CardListUtil.getColor(in, this.color2));
out.shuffle();
final CardList artifact = in.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
// is this really a colorless artifact and not something
// weird like Sarcomite Myr which is a colored artifact
return c.isArtifact() && CardUtil.getColors(c).contains(Constant.Color.COLORLESS)
&& !Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS);
}
});
out.addAll(artifact);
out = out.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
if (c.isCreature() && (c.getNetAttack() <= 1)
&& Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_NOSMALL)) {
return false;
}
return true;
}
});
out = this.filterBadCards(out);
return out;
}
/**
* Creates a CardList from the given sequence that meets the criteria for
* color(s), type, whether the card is suitable for placement in random
* decks and in AI decks, etc.
*
* @param sequence
* an iterable over Card instances
*
* @return a subset of sequence <= sequence; might be empty, but never null
*/
private CardList filterBadCards(final Iterable<Card> sequence) {
final ArrayList<Card> goodLand = new ArrayList<Card>();
final CardList out = CardFilter.filter(sequence, new CardListFilter() {
@Override
public boolean addCard(final Card c) {
final ArrayList<String> list = CardUtil.getColors(c);
if (list.size() == 2) {
if (!(list.contains(GenerateConstructedDeck.this.color1) && list
.contains(GenerateConstructedDeck.this.color2))) {
return false;
}
}
return ((CardUtil.getColors(c).size() <= 2 // only dual colored
)
// gold cards
&& !c.isLand() // no land
&& !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True"))
// OR very important
|| goodLand.contains(c.getName());
}
});
return out;
} // filterBadCards()
}

View File

@@ -1,531 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.deck.generate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import forge.AllZone;
import forge.Card;
import forge.CardFilter;
import forge.CardList;
import forge.CardListFilter;
import forge.CardListUtil;
import forge.CardUtil;
import forge.Constant;
import forge.Singletons;
import forge.properties.ForgePreferences.FPref;
/**
* <p>
* GenerateConstructedMultiColorDeck class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class GenerateConstructedMultiColorDeck {
private String color1;
private String color2;
private String color3;
private String color4;
private String color5;
private final Map<String, String> map = new HashMap<String, String>();
private final Map<String, String[]> multiMap = new HashMap<String, String[]>();
/**
* <p>
* Constructor for GenerateConstructedMultiColorDeck.
* </p>
*/
public GenerateConstructedMultiColorDeck() {
this.setupBasicLandMap();
this.setupMultiMap();
}
/**
* <p>
* setupBasicLandMap.
* </p>
*/
private void setupBasicLandMap() {
this.map.put(Constant.Color.BLACK, "Swamp");
this.map.put(Constant.Color.BLUE, "Island");
this.map.put(Constant.Color.GREEN, "Forest");
this.map.put(Constant.Color.RED, "Mountain");
this.map.put(Constant.Color.WHITE, "Plains");
}
/**
* <p>
* setupMultiMap.
* </p>
*/
private void setupMultiMap() {
this.multiMap.put(Constant.Color.BLACK + Constant.Color.BLUE,
new String[] { "Underground Sea", "Watery Grave" });
this.multiMap.put(Constant.Color.BLACK + Constant.Color.GREEN, new String[] { "Bayou", "Overgrown Tomb" });
this.multiMap.put(Constant.Color.BLACK + Constant.Color.RED, new String[] { "Badlands", "Blood Crypt" });
this.multiMap.put(Constant.Color.BLACK + Constant.Color.WHITE, new String[] { "Scrubland", "Godless Shrine" });
this.multiMap.put(Constant.Color.BLUE + Constant.Color.BLACK,
new String[] { "Underground Sea", "Watery Grave" });
this.multiMap.put(Constant.Color.BLUE + Constant.Color.GREEN,
new String[] { "Tropical Island", "Breeding Pool" });
this.multiMap.put(Constant.Color.BLUE + Constant.Color.RED, new String[] { "Volcanic Island", "Steam Vents" });
this.multiMap.put(Constant.Color.BLUE + Constant.Color.WHITE, new String[] { "Tundra", "Hallowed Fountain" });
this.multiMap.put(Constant.Color.GREEN + Constant.Color.BLACK, new String[] { "Bayou", "Overgrown Tomb" });
this.multiMap.put(Constant.Color.GREEN + Constant.Color.BLUE,
new String[] { "Tropical Island", "Breeding Pool" });
this.multiMap.put(Constant.Color.GREEN + Constant.Color.RED, new String[] { "Taiga", "Stomping Ground" });
this.multiMap.put(Constant.Color.GREEN + Constant.Color.WHITE, new String[] { "Savannah", "Temple Garden" });
this.multiMap.put(Constant.Color.RED + Constant.Color.BLACK, new String[] { "Badlands", "Blood Crypt" });
this.multiMap.put(Constant.Color.RED + Constant.Color.BLUE, new String[] { "Volcanic Island", "Steam Vents" });
this.multiMap.put(Constant.Color.RED + Constant.Color.GREEN, new String[] { "Taiga", "Stomping Ground" });
this.multiMap.put(Constant.Color.RED + Constant.Color.WHITE, new String[] { "Plateau", "Sacred Foundry" });
this.multiMap.put(Constant.Color.WHITE + Constant.Color.BLACK, new String[] { "Scrubland", "Godless Shrine" });
this.multiMap.put(Constant.Color.WHITE + Constant.Color.BLUE, new String[] { "Tundra", "Hallowed Fountain" });
this.multiMap.put(Constant.Color.WHITE + Constant.Color.GREEN, new String[] { "Savannah", "Temple Garden" });
this.multiMap.put(Constant.Color.WHITE + Constant.Color.RED, new String[] { "Plateau", "Sacred Foundry" });
}
/**
* <p>
* generate3ColorDeck.
* </p>
*
* @return a {@link forge.CardList} object.
*/
public final CardList generate3ColorDeck() {
CardList deck;
int check;
do {
deck = this.get3ColorDeck();
check = deck.getType("Creature").size();
} while ((check < 16) || (24 < check));
this.addLand(deck, 3);
if (deck.size() != 60) {
throw new RuntimeException(
"GenerateConstructedDeck() : generateDeck() error, deck size it not 60, deck size is "
+ deck.size());
}
return deck;
}
/**
* <p>
* generate5ColorDeck.
* </p>
*
* @return a {@link forge.CardList} object.
*/
public final CardList generate5ColorDeck() {
CardList deck;
deck = this.get5ColorDeck();
this.addLand(deck, 5);
if (deck.size() != 60) {
throw new RuntimeException(
"GenerateConstructedDeck() : generateDeck() error, deck size it not 60, deck size is "
+ deck.size());
}
return deck;
}
/**
* <p>
* addLand.
* </p>
*
* @param list
* a {@link forge.CardList} object.
* @param colors
* a int.
*/
private void addLand(final CardList list, final int colors) {
if (colors == 3) {
final int numberBasic = 2;
Card land;
for (int i = 0; i < numberBasic; i++) {
land = AllZone.getCardFactory().getCard(this.map.get(this.color1).toString(),
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.map.get(this.color2).toString(),
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.map.get(this.color3).toString(),
AllZone.getComputerPlayer());
list.add(land);
}
final int numberDual = 4;
for (int i = 0; i < numberDual; i++) {
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color2)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color3)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color3)[0],
AllZone.getComputerPlayer());
list.add(land);
}
for (int i = 0; i < 2; i++) {
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color2)[1],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color3)[1],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color3)[1],
AllZone.getComputerPlayer());
list.add(land);
}
} else if (colors == 5) {
final int numberBasic = 1;
Card land;
for (int i = 0; i < numberBasic; i++) {
land = AllZone.getCardFactory().getCard(this.map.get(this.color1).toString(),
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.map.get(this.color2).toString(),
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.map.get(this.color3).toString(),
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.map.get(this.color4).toString(),
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.map.get(this.color5).toString(),
AllZone.getComputerPlayer());
list.add(land);
}
final int numberDual = 2;
for (int i = 0; i < numberDual; i++) {
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color2)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color3)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color4)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color5)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color3)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color4)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color5)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color3 + this.color4)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color3 + this.color5)[0],
AllZone.getComputerPlayer());
list.add(land);
land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color4 + this.color5)[0],
AllZone.getComputerPlayer());
list.add(land);
}
}
} // addLand()
/**
* Filters out cards by color and their suitability for being placed in a
* randomly created deck.
*
* @param colors
* the number of different colors the deck should have; if this
* is a number other than 3 or 5, we return an empty list.
*
* @return a subset of all cards in the CardFactory database which might be
* empty, but never null
*/
private CardList getCards(final int colors) {
return this.filterBadCards(AllZone.getCardFactory(), colors);
} // getCards()
/**
* <p>
* get3ColorDeck.
* </p>
*
* @return a {@link forge.CardList} object.
*/
private CardList get3ColorDeck() {
final CardList deck = this.get3Colors(this.getCards(3));
final CardList out = new CardList();
deck.shuffle();
// trim deck size down to 36 cards, presumes 24 land, for a total of 60
// cards
for (int i = 0; (i < 36) && (i < deck.size()); i++) {
out.add(deck.get(i));
}
return out;
}
/**
* <p>
* get5ColorDeck.
* </p>
*
* @return a {@link forge.CardList} object.
*/
private CardList get5ColorDeck() {
final CardList deck = this.get5Colors(this.getCards(5));
final CardList out = new CardList();
deck.shuffle();
// trim deck size down to 36 cards, presumes 24 land, for a total of 60
// cards
for (int i = 0; (i < 36) && (i < deck.size()); i++) {
out.add(deck.get(i));
}
return out;
}
/**
* <p>
* get3Colors.
* </p>
*
* @param in
* a {@link forge.CardList} object.
* @return a {@link forge.CardList} object.
*/
private CardList get3Colors(final CardList in) {
int a;
int b;
int c;
a = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS);
do {
b = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS);
c = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS);
} while ((a == b) || (a == c) || (b == c)); // do not want to get the
// same
// color thrice
this.color1 = Constant.Color.ONLY_COLORS[a];
this.color2 = Constant.Color.ONLY_COLORS[b];
this.color3 = Constant.Color.ONLY_COLORS[c];
CardList out = new CardList();
out.addAll(CardListUtil.getColor(in, this.color1));
out.addAll(CardListUtil.getColor(in, this.color2));
out.addAll(CardListUtil.getColor(in, this.color3));
out.shuffle();
final CardList artifact = in.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
// is this really a colorless artifact and not something
// wierd like Sarcomite Myr which is a colored artifact
return c.isArtifact() && CardUtil.getColors(c).contains(Constant.Color.COLORLESS)
&& !Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS);
}
});
out.addAll(artifact);
out = out.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
if (c.isCreature() && (c.getNetAttack() <= 1)
&& Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_NOSMALL)) {
return false;
}
return true;
}
});
out = this.filterBadCards(out, 3);
return out;
}
/**
* <p>
* get5Colors.
* </p>
*
* @param in
* a {@link forge.CardList} object.
* @return a {@link forge.CardList} object.
*/
private CardList get5Colors(final CardList in) {
this.color1 = Constant.Color.BLACK;
this.color2 = Constant.Color.BLUE;
this.color3 = Constant.Color.GREEN;
this.color4 = Constant.Color.RED;
this.color5 = Constant.Color.WHITE;
CardList out = new CardList();
/*
* out.addAll(CardListUtil.getColor(in, color1));
* out.addAll(CardListUtil.getColor(in, color2));
* out.addAll(CardListUtil.getColor(in, color3));
* out.addAll(CardListUtil.getColor(in, color4));
* out.addAll(CardListUtil.getColor(in, color5));
*/
out.addAll(CardListUtil.getGoldCards(in));
out.shuffle();
final CardList artifact = in.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
// is this really a colorless artifact and not something
// wierd like Sarcomite Myr which is a colored artifact
return c.isArtifact() && CardUtil.getColors(c).contains(Constant.Color.COLORLESS)
&& !Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS);
}
});
out.addAll(artifact);
out = out.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
if (c.isCreature() && (c.getNetAttack() <= 1)
&& Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_NOSMALL)) {
return false;
}
return true;
}
});
out = this.filterBadCards(out, 3);
return out;
}
/**
* Filters out cards by color and their suitability for being placed in a
* randomly created deck.
*
* @param sequence
* an Iterable of Card instances
*
* @param colors
* the number of different colors the deck should have; if this
* is a number other than 3 or 5, we return an empty list.
*
* @return a subset of sequence <= sequence which might be empty, but never
* null
*/
private CardList filterBadCards(final Iterable<Card> sequence, final int colors) {
final ArrayList<Card> goodLand = new ArrayList<Card>();
// goodLand.add("Faerie Conclave");
// goodLand.add("Forbidding Watchtower");
// goodLand.add("Treetop Village");
CardList out = new CardList();
if (colors == 3) {
out = CardFilter.filter(sequence, new CardListFilter() {
@Override
public boolean addCard(final Card c) {
final ArrayList<String> list = CardUtil.getColors(c);
if (list.size() == 3) {
if (!list.contains(GenerateConstructedMultiColorDeck.this.color1)
|| !list.contains(GenerateConstructedMultiColorDeck.this.color2)
|| !list.contains(GenerateConstructedMultiColorDeck.this.color3)) {
return false;
}
} else if (list.size() == 2) {
if (!(list.contains(GenerateConstructedMultiColorDeck.this.color1) && list
.contains(GenerateConstructedMultiColorDeck.this.color2))
&& !(list.contains(GenerateConstructedMultiColorDeck.this.color1) && list
.contains(GenerateConstructedMultiColorDeck.this.color3))
&& !(list.contains(GenerateConstructedMultiColorDeck.this.color2) && list
.contains(GenerateConstructedMultiColorDeck.this.color3))) {
return false;
}
}
return ((CardUtil.getColors(c).size() <= 3) && !c.isLand() && // no
// land
!c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True"))
|| goodLand.contains(c.getName()); // OR very
// important
}
});
} else if (colors == 5) {
out = CardFilter.filter(sequence, new CardListFilter() {
@Override
public boolean addCard(final Card c) {
return ((CardUtil.getColors(c).size() >= 2) && // only get
// multicolored
// cards
!c.isLand() && // no land
!c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True"))
|| goodLand.contains(c.getName()); // OR very
// important
}
});
}
return out;
} // filterBadCards()
}

View File

@@ -28,8 +28,9 @@ import javax.swing.SwingUtilities;
import forge.CardList;
import forge.Command;
import forge.PlayerType;
import forge.deck.Deck;
import forge.deck.generate.GenerateConstructedDeck;
import forge.deck.generate.Generate2ColorDeck;
import forge.deck.io.DeckSerializer;
import forge.error.ErrorViewer;
@@ -95,11 +96,11 @@ public final class MenuCommon extends MenuBase<Deck> {
}
Deck genConstructed = new Deck();
genConstructed.getMain().add((new GenerateConstructedDeck()).generateDeck());
genConstructed.getMain().add((new Generate2ColorDeck("AI", "AI")).get2ColorDeck(60, PlayerType.HUMAN));
getController().setModel(genConstructed);
}
private final File getImportFilename() {
private File getImportFilename() {
final JFileChooser chooser = new JFileChooser(MenuCommon.previousDirectory);
chooser.addChoosableFileFilter(DeckSerializer.DCK_FILTER);
@@ -113,7 +114,7 @@ public final class MenuCommon extends MenuBase<Deck> {
return null;
} // openFileDialog()
private final void importDeck() {
private void importDeck() {
final File file = this.getImportFilename();
if (file == null) {
} else if (file.getName().endsWith(".dck")) {

View File

@@ -1,27 +0,0 @@
package forge.deck.generate;
import org.testng.annotations.Test;
import forge.CardList;
/**
* Created by IntelliJ IDEA. User: dhudson
*/
@Test(groups = { "UnitTest" }, timeOut = 1000)
public class GenerateConstructedDeckTest {
/**
* Generate constructed deck test1.
*/
@Test(enabled = false, timeOut = 1000)
public void generateConstructedDeckTest1() {
final GenerateConstructedDeck g = new GenerateConstructedDeck();
for (int i = 0; i < 50; i++) {
final CardList c = g.generateDeck();
System.out.println(c.getType("Creature").size() + " - " + c.size());
}
System.exit(1);
} // main
}

View File

@@ -1,32 +0,0 @@
package forge.deck.generate;
import org.testng.annotations.Test;
import forge.CardList;
/**
* Created by IntelliJ IDEA. User: dhudson
*/
@Test(groups = { "UnitTest" }, timeOut = 1000, enabled = false)
public class GenerateConstructedMultiColorDeckTest {
/**
* Generate constructed multi color deck test1.
*/
@Test(enabled = false, timeOut = 1000)
public void generateConstructedMultiColorDeckTest1() {
final GenerateConstructedMultiColorDeck g = new GenerateConstructedMultiColorDeck();
for (int i = 0; i < 10; i++) {
System.out.println("***GENERATING DECK***");
final CardList c = g.generate3ColorDeck();
System.out.println(c.getType("Creature").size() + " - " + c.size());
for (int j = 0; j < c.size(); j++) {
System.out.println(c.get(j).getName());
}
System.out.println("***DECK GENERATED***");
}
System.exit(1);
} // main
}