mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
checkstyle
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package forge.deck;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import forge.PlayerType;
|
||||
import forge.game.GameType;
|
||||
import forge.item.CardDb;
|
||||
@@ -7,15 +9,16 @@ import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>Deck class.</p>
|
||||
* <p>
|
||||
* Deck class.
|
||||
* </p>
|
||||
*
|
||||
* The set of MTG legal cards that become player's library when the game starts.
|
||||
* Any other data is not part of a deck and should be stored elsewhere. Current
|
||||
* fields allowed for deck metadata are Name, Title, Description, Difficulty,
|
||||
* Icon, Deck Type.
|
||||
*
|
||||
* The set of MTG legal cards that become player's library when the game starts.
|
||||
* Any other data is not part of a deck and should be stored elsewhere.
|
||||
* Current fields allowed for deck metadata are Name, Title, Description, Difficulty, Icon, Deck Type.
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -25,22 +28,23 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
*/
|
||||
private static final long serialVersionUID = -7478025567887481994L;
|
||||
|
||||
//gameType is from Constant.GameType, like GameType.Regular
|
||||
// gameType is from Constant.GameType, like GameType.Regular
|
||||
|
||||
private String name;
|
||||
private GameType deckType;
|
||||
private String comment = null;
|
||||
private PlayerType playerType = null;
|
||||
|
||||
|
||||
private boolean customPool = false;
|
||||
|
||||
|
||||
private ItemPool<CardPrinted> main;
|
||||
private ItemPool<CardPrinted> sideboard;
|
||||
|
||||
|
||||
//gameType is from Constant.GameType, like GameType.Regular
|
||||
// gameType is from Constant.GameType, like GameType.Regular
|
||||
/**
|
||||
* <p>Constructor for Deck.</p>
|
||||
* <p>
|
||||
* Constructor for Deck.
|
||||
* </p>
|
||||
*/
|
||||
public Deck() {
|
||||
main = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
@@ -48,9 +52,12 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Constructor for Deck.</p>
|
||||
*
|
||||
* @param type a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* Constructor for Deck.
|
||||
* </p>
|
||||
*
|
||||
* @param type
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public Deck(final GameType type) {
|
||||
this();
|
||||
@@ -58,8 +65,10 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Getter for the field <code>main</code>.</p>
|
||||
*
|
||||
* <p>
|
||||
* Getter for the field <code>main</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.List} object.
|
||||
*/
|
||||
public ItemPoolView<CardPrinted> getMain() {
|
||||
@@ -67,8 +76,10 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Getter for the field <code>sideboard</code>.</p>
|
||||
*
|
||||
* <p>
|
||||
* Getter for the field <code>sideboard</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.List} object.
|
||||
*/
|
||||
public ItemPoolView<CardPrinted> getSideboard() {
|
||||
@@ -76,41 +87,50 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getDeckType.</p>
|
||||
*
|
||||
* <p>
|
||||
* getDeckType.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public GameType getDeckType() {
|
||||
return deckType;
|
||||
}
|
||||
|
||||
//can only call this method ONCE
|
||||
// can only call this method ONCE
|
||||
/**
|
||||
* <p>setDeckType.</p>
|
||||
*
|
||||
* @param deckType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* setDeckType.
|
||||
* </p>
|
||||
*
|
||||
* @param deckType
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
void setDeckType(GameType deckType) {
|
||||
void setDeckType(final GameType deckType) {
|
||||
if (this.getDeckType() != null) {
|
||||
throw new IllegalStateException(
|
||||
"Deck : setDeckType() error, deck type has already been set");
|
||||
throw new IllegalStateException("Deck : setDeckType() error, deck type has already been set");
|
||||
}
|
||||
|
||||
this.deckType = deckType;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setName.</p>
|
||||
*
|
||||
* @param s a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* setName.
|
||||
* </p>
|
||||
*
|
||||
* @param s
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public void setName(String s) {
|
||||
public void setName(final String s) {
|
||||
name = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getName.</p>
|
||||
*
|
||||
* <p>
|
||||
* getName.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public String getName() {
|
||||
@@ -118,17 +138,22 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setComment.</p>
|
||||
*
|
||||
* @param comment a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* setComment.
|
||||
* </p>
|
||||
*
|
||||
* @param comment
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public void setComment(String comment) {
|
||||
public void setComment(final String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getComment.</p>
|
||||
*
|
||||
* <p>
|
||||
* getComment.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public String getComment() {
|
||||
@@ -136,33 +161,149 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>addMain.</p>
|
||||
*
|
||||
* @param cardName a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* addMain.
|
||||
* </p>
|
||||
*
|
||||
* @param cardName
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public void addMain(final String cardName) { addMain(CardDb.instance().getCard(cardName)); }
|
||||
public void addMain(final CardPrinted card) { main.add(card); }
|
||||
public void addMain(final CardPrinted card, final int amount) { main.add(card, amount); }
|
||||
public void addMain(final ItemPoolView<CardPrinted> list) { main.addAll(list); }
|
||||
public void setMain(final Iterable<String> cards) { main = new ItemPool<CardPrinted>(cards, CardPrinted.class); }
|
||||
public void removeMain(final CardPrinted card) { main.remove(card); }
|
||||
public void removeMain(final CardPrinted card, final int amount) { main.remove(card, amount); }
|
||||
public int countMain() { return main.countAll(); }
|
||||
public void addMain(final String cardName) {
|
||||
addMain(CardDb.instance().getCard(cardName));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>addSideboard.</p>
|
||||
*
|
||||
* @param cardName a {@link java.lang.String} object.
|
||||
* Adds the main.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
*/
|
||||
public final void addSideboard(final String cardName) { addSideboard(CardDb.instance().getCard(cardName)); }
|
||||
public final void addSideboard(final CardPrinted card) { sideboard.add(card); }
|
||||
public final void addSideboard(final CardPrinted card, final int amount) { sideboard.add(card, amount); }
|
||||
public final void addSideboard(final ItemPoolView<CardPrinted> cards) { sideboard.addAll(cards); }
|
||||
public final void setSideboard(final Iterable<String> cards) { sideboard = new ItemPool<CardPrinted>(cards, CardPrinted.class); }
|
||||
public void addMain(final CardPrinted card) {
|
||||
main.add(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>countSideboard.</p>
|
||||
*
|
||||
* Adds the main.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
* @param amount
|
||||
* the amount
|
||||
*/
|
||||
public void addMain(final CardPrinted card, final int amount) {
|
||||
main.add(card, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the main.
|
||||
*
|
||||
* @param list
|
||||
* the list
|
||||
*/
|
||||
public void addMain(final ItemPoolView<CardPrinted> list) {
|
||||
main.addAll(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the main.
|
||||
*
|
||||
* @param cards
|
||||
* the new main
|
||||
*/
|
||||
public void setMain(final Iterable<String> cards) {
|
||||
main = new ItemPool<CardPrinted>(cards, CardPrinted.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the main.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
*/
|
||||
public void removeMain(final CardPrinted card) {
|
||||
main.remove(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the main.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
* @param amount
|
||||
* the amount
|
||||
*/
|
||||
public void removeMain(final CardPrinted card, final int amount) {
|
||||
main.remove(card, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count main.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
public int countMain() {
|
||||
return main.countAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addSideboard.
|
||||
* </p>
|
||||
*
|
||||
* @param cardName
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public void addSideboard(final String cardName) {
|
||||
addSideboard(CardDb.instance().getCard(cardName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the sideboard.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
*/
|
||||
public void addSideboard(final CardPrinted card) {
|
||||
sideboard.add(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the sideboard.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
* @param amount
|
||||
* the amount
|
||||
*/
|
||||
public void addSideboard(final CardPrinted card, final int amount) {
|
||||
sideboard.add(card, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the sideboard.
|
||||
*
|
||||
* @param cards
|
||||
* the cards
|
||||
*/
|
||||
public void addSideboard(final ItemPoolView<CardPrinted> cards) {
|
||||
sideboard.addAll(cards);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sideboard.
|
||||
*
|
||||
* @param cards
|
||||
* the new sideboard
|
||||
*/
|
||||
public void setSideboard(final Iterable<String> cards) {
|
||||
sideboard = new ItemPool<CardPrinted>(cards, CardPrinted.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* countSideboard.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public int countSideboard() {
|
||||
@@ -170,18 +311,23 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>removeSideboard.</p>
|
||||
* <p>
|
||||
* removeSideboard.
|
||||
* </p>
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
*
|
||||
* @param index a int.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public void removeFromSideboard(CardPrinted card) {
|
||||
public void removeFromSideboard(final CardPrinted card) {
|
||||
sideboard.remove(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isDraft.</p>
|
||||
*
|
||||
* <p>
|
||||
* isDraft.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public boolean isDraft() {
|
||||
@@ -189,8 +335,10 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isSealed.</p>
|
||||
*
|
||||
* <p>
|
||||
* isSealed.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public boolean isSealed() {
|
||||
@@ -198,8 +346,10 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isRegular.</p>
|
||||
*
|
||||
* <p>
|
||||
* isRegular.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public boolean isRegular() {
|
||||
@@ -207,8 +357,10 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>hashCode.</p>
|
||||
*
|
||||
* <p>
|
||||
* hashCode.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public int hashCode() {
|
||||
@@ -222,17 +374,20 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>compareTo.</p>
|
||||
*
|
||||
* @param d a {@link forge.deck.Deck} object.
|
||||
* <p>
|
||||
* compareTo.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @return a int.
|
||||
*/
|
||||
public int compareTo(Deck d) {
|
||||
public int compareTo(final Deck d) {
|
||||
return getName().compareTo(d.getName());
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(final Object o) {
|
||||
if (o instanceof Deck) {
|
||||
Deck d = (Deck) o;
|
||||
return getName().equals(d.getName());
|
||||
@@ -240,28 +395,56 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear sideboard.
|
||||
*/
|
||||
public void clearSideboard() {
|
||||
sideboard.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear main.
|
||||
*/
|
||||
public void clearMain() {
|
||||
main.clear();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public final PlayerType getPlayerType() {
|
||||
/**
|
||||
* Gets the player type.
|
||||
*
|
||||
* @return the player type
|
||||
*/
|
||||
public PlayerType getPlayerType() {
|
||||
return playerType;
|
||||
}
|
||||
|
||||
public final void setPlayerType(PlayerType recommendedPlayer0) {
|
||||
/**
|
||||
* Sets the player type.
|
||||
*
|
||||
* @param recommendedPlayer0
|
||||
* the new player type
|
||||
*/
|
||||
public void setPlayerType(final PlayerType recommendedPlayer0) {
|
||||
this.playerType = recommendedPlayer0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is custom pool.
|
||||
*
|
||||
* @return true, if is custom pool
|
||||
*/
|
||||
public boolean isCustomPool() {
|
||||
return customPool;
|
||||
}
|
||||
|
||||
public void setCustomPool(boolean cp) {
|
||||
|
||||
/**
|
||||
* Sets the custom pool.
|
||||
*
|
||||
* @param cp
|
||||
* the new custom pool
|
||||
*/
|
||||
public void setCustomPool(final boolean cp) {
|
||||
customPool = cp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,20 @@ import forge.deck.generate.GenerateThemeDeck;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.GuiUtils;
|
||||
|
||||
/**
|
||||
* Utility class to hold add deck generation routines, methods moved from OldGuiNewGame.
|
||||
*
|
||||
/**
|
||||
* Utility class to hold add deck generation routines, methods moved from
|
||||
* OldGuiNewGame.
|
||||
*
|
||||
*/
|
||||
public abstract class DeckGeneration {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* genDecks.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param playerType
|
||||
* {@link java.lang.String} object.
|
||||
* the player type {@link java.lang.String} object.
|
||||
*/
|
||||
public static void genDecks(final PlayerType playerType) {
|
||||
// TODO jendave to refactor deck generation
|
||||
@@ -45,7 +47,6 @@ public abstract class DeckGeneration {
|
||||
String playerName = playerType.equals(PlayerType.HUMAN) ? "Human" : "Computer";
|
||||
String prompt = String.format("Generate %s Deck", playerName);
|
||||
|
||||
|
||||
Object o = GuiUtils.getChoice(prompt, decks.toArray());
|
||||
|
||||
if (o.toString().equals(decks.get(0))) {
|
||||
@@ -75,7 +76,7 @@ public abstract class DeckGeneration {
|
||||
* <p>
|
||||
* generateConstructedDeck.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private static Deck generateConstructedDeck() {
|
||||
@@ -93,7 +94,7 @@ public abstract class DeckGeneration {
|
||||
* <p>
|
||||
* generateConstructed3ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private static Deck generateConstructed3ColorDeck() {
|
||||
@@ -111,7 +112,7 @@ public abstract class DeckGeneration {
|
||||
* <p>
|
||||
* generateConstructed5ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private static Deck generateConstructed5ColorDeck() {
|
||||
@@ -129,7 +130,7 @@ public abstract class DeckGeneration {
|
||||
* <p>
|
||||
* generateConstructedThemeDeck.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private static Deck generateConstructedThemeDeck() {
|
||||
@@ -160,7 +161,7 @@ public abstract class DeckGeneration {
|
||||
* <p>
|
||||
* generate2ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param p
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
@@ -215,7 +216,7 @@ public abstract class DeckGeneration {
|
||||
* <p>
|
||||
* generate3ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param p
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
@@ -281,22 +282,21 @@ public abstract class DeckGeneration {
|
||||
* <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");
|
||||
// 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");
|
||||
|
||||
Generate5ColorDeck gen = new Generate5ColorDeck("white", "blue", "black", "red", "green");
|
||||
CardList d = gen.get5ColorDeck(60, p);
|
||||
|
||||
@@ -26,11 +26,6 @@ import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.DefaultObjectWrapper;
|
||||
|
||||
import forge.Card;
|
||||
import forge.FileUtil;
|
||||
import forge.PlayerType;
|
||||
@@ -41,6 +36,10 @@ import forge.item.CardPrinted;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.DefaultObjectWrapper;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
|
||||
//reads and writeDeck Deck objects
|
||||
/**
|
||||
@@ -66,9 +65,7 @@ public class DeckManager {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/** The Constant DCK_FILTER. */
|
||||
public static final FileFilter DCK_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
@@ -81,9 +78,7 @@ public class DeckManager {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/** The Constant HTML_FILTER. */
|
||||
public static final FileFilter HTML_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
@@ -265,8 +260,7 @@ public class DeckManager {
|
||||
*/
|
||||
private void checkDraftDeck(final Deck[] deck) {
|
||||
if (deck == null || deck.length != 8 || deck[0].getName().equals("")
|
||||
|| (!deck[0].getDeckType().equals(GameType.Draft)))
|
||||
{
|
||||
|| (!deck[0].getDeckType().equals(GameType.Draft))) {
|
||||
throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck");
|
||||
}
|
||||
}
|
||||
@@ -641,37 +635,45 @@ public class DeckManager {
|
||||
int height = 319;
|
||||
int width = 222;
|
||||
|
||||
/* Create and adjust the configuration */
|
||||
/* Create and adjust the configuration */
|
||||
Configuration cfg = new Configuration();
|
||||
try {
|
||||
cfg.setClassForTemplateLoading(d.getClass(), "/");
|
||||
cfg.setObjectWrapper(new DefaultObjectWrapper());
|
||||
|
||||
/* ------------------------------------------------------------------- */
|
||||
/* You usually do these for many times in the application life-cycle: */
|
||||
/*
|
||||
* ------------------------------------------------------------------
|
||||
* -
|
||||
*/
|
||||
/*
|
||||
* You usually do these for many times in the application
|
||||
* life-cycle:
|
||||
*/
|
||||
|
||||
/* Get or create a template */
|
||||
temp = cfg.getTemplate("proxy-template.ftl");
|
||||
|
||||
|
||||
/* Create a data-model */
|
||||
Map<String, Object> root = new HashMap<String, Object>();
|
||||
root.put("title", d.getName());
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (Card card : d.getMain().toForgeCardList().toArray()) {
|
||||
//System.out.println(card.getSets().get(card.getSets().size() - 1).URL);
|
||||
// System.out.println(card.getSets().get(card.getSets().size() -
|
||||
// 1).URL);
|
||||
list.add(card.getSets().get(card.getSets().size() - 1).URL);
|
||||
}
|
||||
/* List<String> nameList = new ArrayList<String>();
|
||||
for (Card card : d.getMain().toForgeCardList().toArray()) {
|
||||
//System.out.println(card.getSets().get(card.getSets().size() - 1).URL);
|
||||
nameList.add(card.getName());
|
||||
}*/
|
||||
/*
|
||||
* List<String> nameList = new ArrayList<String>(); for (Card card :
|
||||
* d.getMain().toForgeCardList().toArray()) {
|
||||
* //System.out.println(card.getSets().get(card.getSets().size() -
|
||||
* 1).URL); nameList.add(card.getName()); }
|
||||
*/
|
||||
|
||||
TreeMap<String, Integer> map = new TreeMap<String, Integer>();
|
||||
for (Entry<CardPrinted, Integer> entry : d.getMain().getOrderedList()) {
|
||||
map.put(entry.getKey().getName(), entry.getValue());
|
||||
//System.out.println(entry.getValue() + " " + entry.getKey().getName());
|
||||
// System.out.println(entry.getValue() + " " +
|
||||
// entry.getKey().getName());
|
||||
}
|
||||
|
||||
root.put("urls", list);
|
||||
@@ -679,11 +681,11 @@ public class DeckManager {
|
||||
root.put("height", height);
|
||||
root.put("width", width);
|
||||
root.put("cardlistWidth", width - 11);
|
||||
//root.put("nameList", nameList);
|
||||
// root.put("nameList", nameList);
|
||||
root.put("cardList", map);
|
||||
|
||||
/* Merge data-model with template */
|
||||
//StringWriter sw = new StringWriter();
|
||||
// StringWriter sw = new StringWriter();
|
||||
temp.process(root, out);
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
@@ -693,8 +695,8 @@ public class DeckManager {
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeCardPool(final ItemPoolView<CardPrinted> pool,
|
||||
final BufferedWriter out) throws IOException {
|
||||
private static void writeCardPool(final ItemPoolView<CardPrinted> pool, final BufferedWriter out)
|
||||
throws IOException {
|
||||
List<Entry<CardPrinted, Integer>> main2sort = pool.getOrderedList();
|
||||
Collections.sort(main2sort, TableSorter.byNameThenSet);
|
||||
for (Entry<CardPrinted, Integer> e : main2sort) {
|
||||
|
||||
@@ -4,68 +4,156 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
|
||||
/**
|
||||
* <p>DeckRecognizer class.</p>
|
||||
*
|
||||
/**
|
||||
* <p>
|
||||
* DeckRecognizer class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: DeckRecognizer.java 10499 2011-09-17 15:08:47Z Max mtg $
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DeckRecognizer {
|
||||
|
||||
/**
|
||||
* The Enum TokenType.
|
||||
*/
|
||||
public enum TokenType {
|
||||
|
||||
/** The Known card. */
|
||||
KnownCard,
|
||||
|
||||
/** The Unknown card. */
|
||||
UnknownCard,
|
||||
|
||||
/** The Section name. */
|
||||
SectionName,
|
||||
|
||||
/** The Comment. */
|
||||
Comment,
|
||||
|
||||
/** The Unknown text. */
|
||||
UnknownText
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The Class Token.
|
||||
*/
|
||||
public static class Token {
|
||||
private final TokenType type;
|
||||
private final CardPrinted card;
|
||||
private final int number;
|
||||
private final String text;
|
||||
|
||||
public static Token knownCard(CardPrinted theCard, int count) {
|
||||
|
||||
/**
|
||||
* Known card.
|
||||
*
|
||||
* @param theCard
|
||||
* the the card
|
||||
* @param count
|
||||
* the count
|
||||
* @return the token
|
||||
*/
|
||||
public static Token knownCard(final CardPrinted theCard, final int count) {
|
||||
return new Token(theCard, TokenType.KnownCard, count, null);
|
||||
}
|
||||
public static Token unknownCard(String cardNme, int count) {
|
||||
|
||||
/**
|
||||
* Unknown card.
|
||||
*
|
||||
* @param cardNme
|
||||
* the card nme
|
||||
* @param count
|
||||
* the count
|
||||
* @return the token
|
||||
*/
|
||||
public static Token unknownCard(final String cardNme, final int count) {
|
||||
return new Token(null, TokenType.UnknownCard, count, cardNme);
|
||||
}
|
||||
|
||||
private Token(CardPrinted knownCard, TokenType type1, int count, String message)
|
||||
{
|
||||
private Token(final CardPrinted knownCard, final TokenType type1, final int count, final String message) {
|
||||
card = knownCard;
|
||||
number = count;
|
||||
type = type1;
|
||||
text = message;
|
||||
}
|
||||
|
||||
public Token(TokenType type1, int count, String message)
|
||||
{
|
||||
/**
|
||||
* Instantiates a new token.
|
||||
*
|
||||
* @param type1
|
||||
* the type1
|
||||
* @param count
|
||||
* the count
|
||||
* @param message
|
||||
* the message
|
||||
*/
|
||||
public Token(final TokenType type1, final int count, final String message) {
|
||||
this(null, type1, count, message);
|
||||
if (type1 == TokenType.KnownCard || type1 == TokenType.UnknownCard) {
|
||||
throw new IllegalArgumentException("Use factory methods for recognized card lines");
|
||||
}
|
||||
}
|
||||
|
||||
public String getText() { return text; }
|
||||
public CardPrinted getCard() { return card; }
|
||||
public TokenType getType() { return type; }
|
||||
public int getNumber() { return number; }
|
||||
/**
|
||||
* Gets the text.
|
||||
*
|
||||
* @return the text
|
||||
*/
|
||||
public final String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the card.
|
||||
*
|
||||
* @return the card
|
||||
*/
|
||||
public final CardPrinted getCard() {
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
public final TokenType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number.
|
||||
*
|
||||
* @return the number
|
||||
*/
|
||||
public final int getNumber() {
|
||||
return number;
|
||||
}
|
||||
}
|
||||
|
||||
// Let's think about it numbers in the back later
|
||||
// private static final Pattern searchNumbersInBack = Pattern.compile("(.*)[^A-Za-wyz]*\\s+([\\d]{1,2})");
|
||||
// Let's think about it numbers in the back later
|
||||
// private static final Pattern searchNumbersInBack =
|
||||
// Pattern.compile("(.*)[^A-Za-wyz]*\\s+([\\d]{1,2})");
|
||||
private static final Pattern searchNumbersInFront = Pattern.compile("([\\d]{1,2})[^A-Za-wyz]*\\s+(.*)");
|
||||
public static Token recognizeLine(String raw_line)
|
||||
{
|
||||
if (StringUtils.isBlank(raw_line)) { return new Token(TokenType.Comment, 0, raw_line); }
|
||||
|
||||
/**
|
||||
* Recognize line.
|
||||
*
|
||||
* @param raw_line
|
||||
* the raw_line
|
||||
* @return the token
|
||||
*/
|
||||
public static Token recognizeLine(final String raw_line) {
|
||||
if (StringUtils.isBlank(raw_line)) {
|
||||
return new Token(TokenType.Comment, 0, raw_line);
|
||||
}
|
||||
String line = raw_line.trim();
|
||||
|
||||
|
||||
Token result = null;
|
||||
Matcher foundNumbersInFront = searchNumbersInFront.matcher(line);
|
||||
// Matcher foundNumbersInBack = searchNumbersInBack.matcher(line);
|
||||
@@ -73,53 +161,67 @@ public class DeckRecognizer {
|
||||
String cardName = foundNumbersInFront.group(2);
|
||||
int amount = Integer.parseInt(foundNumbersInFront.group(1));
|
||||
result = recognizePossibleNameAndNumber(cardName, amount);
|
||||
} /* else if (foundNumbersInBack.matches()) {
|
||||
String cardName = foundNumbersInBack.group(1);
|
||||
int amount = Integer.parseInt(foundNumbersInBack.group(2));
|
||||
return new Token(cardName, amount);
|
||||
} */else {
|
||||
if ( CardDb.instance().isCardSupported(line)) {
|
||||
} /*
|
||||
* else if (foundNumbersInBack.matches()) { String cardName =
|
||||
* foundNumbersInBack.group(1); int amount =
|
||||
* Integer.parseInt(foundNumbersInBack.group(2)); return new
|
||||
* Token(cardName, amount); }
|
||||
*/
|
||||
else {
|
||||
if (CardDb.instance().isCardSupported(line)) {
|
||||
return Token.knownCard(CardDb.instance().getCard(line), 1);
|
||||
}
|
||||
result = recognizeNonCard(line, 1);
|
||||
}
|
||||
return result != null ? result : new Token(TokenType.UnknownText, 0, line);
|
||||
return result != null ? result : new Token(TokenType.UnknownText, 0, line);
|
||||
}
|
||||
|
||||
private static Token recognizePossibleNameAndNumber(String name, int n) {
|
||||
if ( CardDb.instance().isCardSupported(name))
|
||||
|
||||
private static Token recognizePossibleNameAndNumber(final String name, final int n) {
|
||||
if (CardDb.instance().isCardSupported(name)) {
|
||||
return Token.knownCard(CardDb.instance().getCard(name), n);
|
||||
|
||||
}
|
||||
|
||||
Token known = recognizeNonCard(name, n);
|
||||
return null == known ? Token.unknownCard(name, n) : known;
|
||||
}
|
||||
|
||||
private static Token recognizeNonCard(String text, int n) {
|
||||
if (isDecoration(text)) { return new Token(TokenType.Comment, n, text); }
|
||||
if (isSectionName(text)) { return new Token(TokenType.SectionName, n, text); }
|
||||
|
||||
private static Token recognizeNonCard(final String text, final int n) {
|
||||
if (isDecoration(text)) {
|
||||
return new Token(TokenType.Comment, n, text);
|
||||
}
|
||||
if (isSectionName(text)) {
|
||||
return new Token(TokenType.SectionName, n, text);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final static String[] knownComments = new String[] {
|
||||
"land", "lands", "creatures", "creature", "spells", "enchancements", "other spells", "artifacts" };
|
||||
private final static String[] knownCommentParts = new String[] { "card" };
|
||||
|
||||
private static boolean isDecoration(String lineAsIs) {
|
||||
private static final String[] knownComments = new String[] { "land", "lands", "creatures", "creature", "spells",
|
||||
"enchancements", "other spells", "artifacts" };
|
||||
private static final String[] knownCommentParts = new String[] { "card" };
|
||||
|
||||
private static boolean isDecoration(final String lineAsIs) {
|
||||
String line = lineAsIs.toLowerCase();
|
||||
for (String s : knownCommentParts) {
|
||||
if (line.contains(s)) { return true; }
|
||||
if (line.contains(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (String s : knownComments) {
|
||||
if (line.equalsIgnoreCase(s)) { return true; }
|
||||
if (line.equalsIgnoreCase(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isSectionName(String line) {
|
||||
if (line.toLowerCase().contains("side")) { return true; }
|
||||
if (line.toLowerCase().contains("main")) { return true; }
|
||||
private static boolean isSectionName(final String line) {
|
||||
if (line.toLowerCase().contains("side")) {
|
||||
return true;
|
||||
}
|
||||
if (line.toLowerCase().contains("main")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
package forge.deck.generate;
|
||||
|
||||
import forge.*;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardFilter;
|
||||
import forge.CardList;
|
||||
import forge.CardListFilter;
|
||||
import forge.Constant;
|
||||
import forge.MyRandom;
|
||||
import forge.PlayerType;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
|
||||
/**
|
||||
* <p>Generate2ColorDeck class.</p>
|
||||
*
|
||||
* <p>
|
||||
* Generate2ColorDeck class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -25,12 +34,16 @@ public class Generate2ColorDeck {
|
||||
private Map<String, Integer> cardCounts = null;
|
||||
|
||||
/**
|
||||
* <p>Constructor for Generate2ColorDeck.</p>
|
||||
*
|
||||
* @param Clr1 a {@link java.lang.String} object.
|
||||
* @param Clr2 a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* Constructor for Generate2ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param Clr1
|
||||
* a {@link java.lang.String} object.
|
||||
* @param Clr2
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public Generate2ColorDeck(String Clr1, String Clr2) {
|
||||
public Generate2ColorDeck(final String Clr1, final String Clr2) {
|
||||
r = MyRandom.random;
|
||||
|
||||
cardCounts = new HashMap<String, Integer>();
|
||||
@@ -55,8 +68,9 @@ public class Generate2ColorDeck {
|
||||
|
||||
// choose second color
|
||||
String c2 = notColors.get(r.nextInt(5));
|
||||
while (c2.equals(color1))
|
||||
while (c2.equals(color1)) {
|
||||
c2 = notColors.get(r.nextInt(5));
|
||||
}
|
||||
color2 = c2;
|
||||
} else {
|
||||
color1 = Clr1;
|
||||
@@ -67,7 +81,7 @@ public class Generate2ColorDeck {
|
||||
notColors.remove(color2);
|
||||
|
||||
dL = GenerateDeckUtil.getDualLandList(clrMap.get(color1) + clrMap.get(color2));
|
||||
|
||||
|
||||
for (int i = 0; i < dL.size(); i++) {
|
||||
cardCounts.put(dL.get(i), 0);
|
||||
}
|
||||
@@ -75,12 +89,17 @@ public class Generate2ColorDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>get2ColorDeck.</p>
|
||||
*
|
||||
* @param Size a int.
|
||||
* <p>
|
||||
* get2ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param Size
|
||||
* a int.
|
||||
* @param pt
|
||||
* the pt
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public CardList get2ColorDeck(int Size, final PlayerType pt) {
|
||||
public final CardList get2ColorDeck(final int Size, final PlayerType pt) {
|
||||
int lc = 0; // loop counter to prevent infinite card selection loops
|
||||
String tmpDeck = "";
|
||||
CardList tDeck = new CardList();
|
||||
@@ -92,9 +111,9 @@ public class Generate2ColorDeck {
|
||||
// start with all cards
|
||||
// remove cards that generated decks don't like
|
||||
CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
public boolean addCard(final Card c) {
|
||||
if (c.getSVar("RemRandomDeck").equals("True")) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN)));
|
||||
}
|
||||
@@ -107,7 +126,7 @@ public class Generate2ColorDeck {
|
||||
|
||||
// remove multicolor cards that don't match the colors
|
||||
CardListFilter clrF = new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
public boolean addCard(final Card c) {
|
||||
for (int i = 0; i < notColors.size(); i++) {
|
||||
if (c.getManaCost().contains(clrMap.get(notColors.get(i)))) {
|
||||
return false;
|
||||
@@ -123,7 +142,7 @@ public class Generate2ColorDeck {
|
||||
CardList Cr1 = CL1.getType("Creature");
|
||||
CardList Cr2 = CL2.getType("Creature");
|
||||
|
||||
String ISE[] = {"Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature"};
|
||||
String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" };
|
||||
CardList Sp1 = CL1.getValidCards(ISE, null, null);
|
||||
CardList Sp2 = CL2.getValidCards(ISE, null, null);
|
||||
|
||||
@@ -132,9 +151,9 @@ public class Generate2ColorDeck {
|
||||
CardList Sp12 = new CardList();
|
||||
|
||||
// used for mana curve in the card pool
|
||||
final int MinCMC[] = {1}, MaxCMC[] = {2};
|
||||
final int MinCMC[] = { 1 }, MaxCMC[] = { 2 };
|
||||
CardListFilter cmcF = new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
public boolean addCard(final Card c) {
|
||||
int cCMC = c.getCMC();
|
||||
return (cCMC >= MinCMC[0]) && (cCMC <= MaxCMC[0]);
|
||||
}
|
||||
@@ -168,11 +187,12 @@ public class Generate2ColorDeck {
|
||||
MinCMC[0] += 2;
|
||||
MaxCMC[0] += 2;
|
||||
// resulting mana curve of the card pool
|
||||
//16x 1 - 2
|
||||
//12x 3 - 4
|
||||
//8x 5 - 6
|
||||
//4x 7 - 8
|
||||
//=40x - card pool could support up to a 275 card deck (all 4-ofs plus basic lands)
|
||||
// 16x 1 - 2
|
||||
// 12x 3 - 4
|
||||
// 8x 5 - 6
|
||||
// 4x 7 - 8
|
||||
// =40x - card pool could support up to a 275 card deck (all 4-ofs
|
||||
// plus basic lands)
|
||||
}
|
||||
|
||||
// shuffle card pools
|
||||
@@ -230,7 +250,8 @@ public class Generate2ColorDeck {
|
||||
if (LandsPercentage > 0) {
|
||||
p = (float) ((float) LandsPercentage * .01);
|
||||
numLands = (int) (p * (float) Size);
|
||||
} else { // otherwise, just fill in the rest of the deck with basic lands
|
||||
} else { // otherwise, just fill in the rest of the deck with basic
|
||||
// lands
|
||||
numLands = Size - tDeck.size();
|
||||
}
|
||||
|
||||
@@ -257,16 +278,14 @@ public class Generate2ColorDeck {
|
||||
|
||||
numLands -= nDLands;
|
||||
|
||||
if (numLands > 0) // attempt to optimize basic land counts according to color representation
|
||||
if (numLands > 0) // attempt to optimize basic land counts according to
|
||||
// color representation
|
||||
{
|
||||
CCnt ClrCnts[] = {new CCnt("Plains", 0),
|
||||
new CCnt("Island", 0),
|
||||
new CCnt("Swamp", 0),
|
||||
new CCnt("Mountain", 0),
|
||||
new CCnt("Forest", 0)};
|
||||
CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
|
||||
new CCnt("Mountain", 0), new CCnt("Forest", 0) };
|
||||
|
||||
// count each card color using mana costs
|
||||
// TODO: count hybrid mana differently?
|
||||
// TODO count hybrid mana differently?
|
||||
for (int i = 0; i < tDeck.size(); i++) {
|
||||
String mc = tDeck.get(i).getManaCost();
|
||||
|
||||
@@ -276,17 +295,13 @@ public class Generate2ColorDeck {
|
||||
|
||||
if (c == 'W') {
|
||||
ClrCnts[0].Count++;
|
||||
}
|
||||
else if (c == 'U') {
|
||||
} else if (c == 'U') {
|
||||
ClrCnts[1].Count++;
|
||||
}
|
||||
else if (c == 'B') {
|
||||
} else if (c == 'B') {
|
||||
ClrCnts[2].Count++;
|
||||
}
|
||||
else if (c == 'R') {
|
||||
} else if (c == 'R') {
|
||||
ClrCnts[3].Count++;
|
||||
}
|
||||
else if (c == 'G') {
|
||||
} else if (c == 'G') {
|
||||
ClrCnts[4].Count++;
|
||||
}
|
||||
}
|
||||
@@ -302,12 +317,14 @@ public class Generate2ColorDeck {
|
||||
tmpDeck += "totalColor:" + totalColor + "\n";
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (ClrCnts[i].Count > 0) { // calculate number of lands for each color
|
||||
if (ClrCnts[i].Count > 0) { // calculate number of lands for
|
||||
// each color
|
||||
p = (float) ClrCnts[i].Count / (float) totalColor;
|
||||
int nLand = (int) ((float) numLands * p);
|
||||
tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n";
|
||||
|
||||
// just to prevent a null exception by the deck size fixing code
|
||||
// just to prevent a null exception by the deck size fixing
|
||||
// code
|
||||
cardCounts.put(ClrCnts[i].Color, nLand);
|
||||
|
||||
for (int j = 0; j <= nLand; j++) {
|
||||
@@ -345,7 +362,7 @@ public class Generate2ColorDeck {
|
||||
for (int i = 0; i < diff; i++) {
|
||||
Card c = tDeck.get(r.nextInt(tDeck.size()));
|
||||
|
||||
while (c.isBasicLand()) { // don't remove basic lands
|
||||
while (c.isBasicLand()) { // don't remove basic lands
|
||||
c = tDeck.get(r.nextInt(tDeck.size()));
|
||||
}
|
||||
|
||||
@@ -366,7 +383,7 @@ public class Generate2ColorDeck {
|
||||
public String Color;
|
||||
public int Count;
|
||||
|
||||
public CCnt(String clr, int cnt) {
|
||||
public CCnt(final String clr, final int cnt) {
|
||||
Color = clr;
|
||||
Count = cnt;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
package forge.deck.generate;
|
||||
|
||||
import forge.*;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardFilter;
|
||||
import forge.CardList;
|
||||
import forge.CardListFilter;
|
||||
import forge.Constant;
|
||||
import forge.MyRandom;
|
||||
import forge.PlayerType;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
|
||||
/**
|
||||
* <p>Generate3ColorDeck class.</p>
|
||||
*
|
||||
* <p>
|
||||
* Generate3ColorDeck class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -26,13 +35,18 @@ public class Generate3ColorDeck {
|
||||
private Map<String, Integer> cardCounts = null;
|
||||
|
||||
/**
|
||||
* <p>Constructor for Generate3ColorDeck.</p>
|
||||
*
|
||||
* @param Clr1 a {@link java.lang.String} object.
|
||||
* @param Clr2 a {@link java.lang.String} object.
|
||||
* @param Clr3 a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* Constructor for Generate3ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param Clr1
|
||||
* a {@link java.lang.String} object.
|
||||
* @param Clr2
|
||||
* a {@link java.lang.String} object.
|
||||
* @param Clr3
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public Generate3ColorDeck(String Clr1, String Clr2, String Clr3) {
|
||||
public Generate3ColorDeck(final String Clr1, final String Clr2, final String Clr3) {
|
||||
r = MyRandom.random;
|
||||
|
||||
cardCounts = new HashMap<String, Integer>();
|
||||
@@ -57,13 +71,15 @@ public class Generate3ColorDeck {
|
||||
|
||||
// choose second color
|
||||
String c2 = notColors.get(r.nextInt(5));
|
||||
while (c2.equals(color1))
|
||||
while (c2.equals(color1)) {
|
||||
c2 = notColors.get(r.nextInt(5));
|
||||
}
|
||||
color2 = c2;
|
||||
|
||||
String c3 = notColors.get(r.nextInt(5));
|
||||
while (c3.equals(color1) || c3.equals(color2))
|
||||
while (c3.equals(color1) || c3.equals(color2)) {
|
||||
c3 = notColors.get(r.nextInt(5));
|
||||
}
|
||||
color3 = c3;
|
||||
} else {
|
||||
color1 = Clr1;
|
||||
@@ -76,7 +92,7 @@ public class Generate3ColorDeck {
|
||||
notColors.remove(color3);
|
||||
|
||||
dL = GenerateDeckUtil.getDualLandList(crMap.get(color1) + crMap.get(color2) + crMap.get(color3));
|
||||
|
||||
|
||||
for (int i = 0; i < dL.size(); i++) {
|
||||
cardCounts.put(dL.get(i), 0);
|
||||
}
|
||||
@@ -84,12 +100,17 @@ public class Generate3ColorDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>get3ColorDeck.</p>
|
||||
*
|
||||
* @param Size a int.
|
||||
* <p>
|
||||
* get3ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param Size
|
||||
* a int.
|
||||
* @param pt
|
||||
* the pt
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public CardList get3ColorDeck(int Size, final PlayerType pt) {
|
||||
public final CardList get3ColorDeck(final int Size, final PlayerType pt) {
|
||||
int lc = 0; // loop counter to prevent infinite card selection loops
|
||||
String tmpDeck = "";
|
||||
CardList tDeck = new CardList();
|
||||
@@ -101,11 +122,11 @@ public class Generate3ColorDeck {
|
||||
// start with all cards
|
||||
// remove cards that generated decks don't like
|
||||
CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
public boolean addCard(final Card c) {
|
||||
if (c.getSVar("RemRandomDeck").equals("True")) {
|
||||
return false;
|
||||
}
|
||||
return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN)));
|
||||
}
|
||||
return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN)));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -117,10 +138,11 @@ public class Generate3ColorDeck {
|
||||
|
||||
// remove multicolor cards that don't match the colors
|
||||
CardListFilter clrF = new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
public boolean addCard(final Card c) {
|
||||
for (int i = 0; i < notColors.size(); i++) {
|
||||
if (c.getManaCost().contains(crMap.get(notColors.get(i))))
|
||||
if (c.getManaCost().contains(crMap.get(notColors.get(i)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -134,7 +156,7 @@ public class Generate3ColorDeck {
|
||||
CardList Cr2 = CL2.getType("Creature");
|
||||
CardList Cr3 = CL3.getType("Creature");
|
||||
|
||||
String ISE[] = {"Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature"};
|
||||
String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" };
|
||||
CardList Sp1 = CL1.getValidCards(ISE, null, null);
|
||||
CardList Sp2 = CL2.getValidCards(ISE, null, null);
|
||||
CardList Sp3 = CL3.getValidCards(ISE, null, null);
|
||||
@@ -144,9 +166,9 @@ public class Generate3ColorDeck {
|
||||
CardList Sp123 = new CardList();
|
||||
|
||||
// used for mana curve in the card pool
|
||||
final int MinCMC[] = {1}, MaxCMC[] = {3};
|
||||
final int MinCMC[] = { 1 }, MaxCMC[] = { 3 };
|
||||
CardListFilter cmcF = new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
public boolean addCard(final Card c) {
|
||||
int cCMC = c.getCMC();
|
||||
return (cCMC >= MinCMC[0]) && (cCMC <= MaxCMC[0]);
|
||||
}
|
||||
@@ -191,10 +213,11 @@ public class Generate3ColorDeck {
|
||||
MinCMC[0] += 2;
|
||||
MaxCMC[0] += 2;
|
||||
// resulting mana curve of the card pool
|
||||
//18x 1 - 3
|
||||
//12x 3 - 5
|
||||
//6x 5 - 7
|
||||
//=36x - card pool could support up to a 257 card deck (all 4-ofs plus basic lands)
|
||||
// 18x 1 - 3
|
||||
// 12x 3 - 5
|
||||
// 6x 5 - 7
|
||||
// =36x - card pool could support up to a 257 card deck (all 4-ofs
|
||||
// plus basic lands)
|
||||
}
|
||||
|
||||
// shuffle card pools
|
||||
@@ -219,8 +242,9 @@ public class Generate3ColorDeck {
|
||||
c = Cr123.get(r.nextInt(Cr123.size()));
|
||||
lc++;
|
||||
}
|
||||
if (lc > 100)
|
||||
if (lc > 100) {
|
||||
throw new RuntimeException("Generate3ColorDeck : get3ColorDeck -- looped too much -- Cr123");
|
||||
}
|
||||
|
||||
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
|
||||
int n = cardCounts.get(c.getName());
|
||||
@@ -236,8 +260,9 @@ public class Generate3ColorDeck {
|
||||
c = Sp123.get(r.nextInt(Sp123.size()));
|
||||
lc++;
|
||||
}
|
||||
if (lc > 100)
|
||||
if (lc > 100) {
|
||||
throw new RuntimeException("Generate3ColorDeck : get3ColorDeck -- looped too much -- Sp123");
|
||||
}
|
||||
|
||||
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
|
||||
int n = cardCounts.get(c.getName());
|
||||
@@ -250,8 +275,10 @@ public class Generate3ColorDeck {
|
||||
if (LandsPercentage > 0) {
|
||||
p = (float) ((float) LandsPercentage * .01);
|
||||
numLands = (int) (p * (float) Size);
|
||||
} else // otherwise, just fill in the rest of the deck with basic lands
|
||||
} else {
|
||||
// otherwise, just fill in the rest of the deck with basic lands
|
||||
numLands = Size - tDeck.size();
|
||||
}
|
||||
|
||||
tmpDeck += "numLands:" + numLands + "\n";
|
||||
|
||||
@@ -264,8 +291,9 @@ public class Generate3ColorDeck {
|
||||
s = dL.get(r.nextInt(dL.size()));
|
||||
lc++;
|
||||
}
|
||||
if (lc > 20)
|
||||
if (lc > 20) {
|
||||
throw new RuntimeException("Generate3ColorDeck : get3ColorDeck -- looped too much -- dL");
|
||||
}
|
||||
|
||||
tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer()));
|
||||
int n = cardCounts.get(s);
|
||||
@@ -275,16 +303,14 @@ public class Generate3ColorDeck {
|
||||
|
||||
numLands -= ndLands;
|
||||
|
||||
if (numLands > 0) // attempt to optimize basic land counts according to color representation
|
||||
if (numLands > 0) // attempt to optimize basic land counts according to
|
||||
// color representation
|
||||
{
|
||||
CCnt ClrCnts[] = {new CCnt("Plains", 0),
|
||||
new CCnt("Island", 0),
|
||||
new CCnt("Swamp", 0),
|
||||
new CCnt("Mountain", 0),
|
||||
new CCnt("Forest", 0)};
|
||||
CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
|
||||
new CCnt("Mountain", 0), new CCnt("Forest", 0) };
|
||||
|
||||
// count each card color using mana costs
|
||||
// TODO: count hybrid mana differently?
|
||||
// TODO count hybrid mana differently?
|
||||
for (int i = 0; i < tDeck.size(); i++) {
|
||||
String mc = tDeck.get(i).getManaCost();
|
||||
|
||||
@@ -292,16 +318,17 @@ public class Generate3ColorDeck {
|
||||
for (int j = 0; j < mc.length(); j++) {
|
||||
char c = mc.charAt(j);
|
||||
|
||||
if (c == 'W')
|
||||
if (c == 'W') {
|
||||
ClrCnts[0].Count++;
|
||||
else if (c == 'U')
|
||||
} else if (c == 'U') {
|
||||
ClrCnts[1].Count++;
|
||||
else if (c == 'B')
|
||||
} else if (c == 'B') {
|
||||
ClrCnts[2].Count++;
|
||||
else if (c == 'R')
|
||||
} else if (c == 'R') {
|
||||
ClrCnts[3].Count++;
|
||||
else if (c == 'G')
|
||||
} else if (c == 'G') {
|
||||
ClrCnts[4].Count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,16 +342,19 @@ public class Generate3ColorDeck {
|
||||
tmpDeck += "totalColor:" + totalColor + "\n";
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (ClrCnts[i].Count > 0) { // calculate number of lands for each color
|
||||
if (ClrCnts[i].Count > 0) { // calculate number of lands for
|
||||
// each color
|
||||
p = (float) ClrCnts[i].Count / (float) totalColor;
|
||||
int nLand = (int) ((float) numLands * p);
|
||||
tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n";
|
||||
|
||||
// just to prevent a null exception by the deck size fixing code
|
||||
// just to prevent a null exception by the deck size fixing
|
||||
// code
|
||||
cardCounts.put(ClrCnts[i].Color, nLand);
|
||||
|
||||
for (int j = 0; j <= nLand; j++)
|
||||
for (int j = 0; j <= nLand; j++) {
|
||||
tDeck.add(AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -342,8 +372,9 @@ public class Generate3ColorDeck {
|
||||
c = tDeck.get(r.nextInt(tDeck.size()));
|
||||
lc++;
|
||||
}
|
||||
if (lc > Size)
|
||||
if (lc > Size) {
|
||||
throw new RuntimeException("Generate3ColorDeck : get3ColorDeck -- looped too much -- undersize");
|
||||
}
|
||||
|
||||
int n = cardCounts.get(c.getName());
|
||||
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
|
||||
@@ -356,8 +387,10 @@ public class Generate3ColorDeck {
|
||||
for (int i = 0; i < diff; i++) {
|
||||
Card c = tDeck.get(r.nextInt(tDeck.size()));
|
||||
|
||||
while (c.isBasicLand()) // don't remove basic lands
|
||||
while (c.isBasicLand()) {
|
||||
// don't remove basic lands
|
||||
c = tDeck.get(r.nextInt(tDeck.size()));
|
||||
}
|
||||
|
||||
tDeck.remove(c);
|
||||
tmpDeck += "Removed:" + c.getName() + "\n";
|
||||
@@ -365,8 +398,9 @@ public class Generate3ColorDeck {
|
||||
}
|
||||
|
||||
tmpDeck += "DeckSize:" + tDeck.size() + "\n";
|
||||
if (ForgeProps.getProperty("showdeck/3color", "false").equals("true"))
|
||||
if (ForgeProps.getProperty("showdeck/3color", "false").equals("true")) {
|
||||
ErrorViewer.showError(tmpDeck);
|
||||
}
|
||||
|
||||
return tDeck;
|
||||
}
|
||||
@@ -375,7 +409,7 @@ public class Generate3ColorDeck {
|
||||
public String Color;
|
||||
public int Count;
|
||||
|
||||
public CCnt(String clr, int cnt) {
|
||||
public CCnt(final String clr, final int cnt) {
|
||||
Color = clr;
|
||||
Count = cnt;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@ import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
|
||||
/**
|
||||
* <p>Generate5ColorDeck class.</p>
|
||||
*
|
||||
* <p>
|
||||
* Generate5ColorDeck class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -35,24 +37,30 @@ public class Generate5ColorDeck {
|
||||
private Map<String, Integer> cardCounts = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new generate5 color deck.
|
||||
*/
|
||||
public Generate5ColorDeck() {
|
||||
this("white", "blue", "black", "red", "green");
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Constructor for Generate5ColorDeck.</p>
|
||||
*
|
||||
* @param clr1 a {@link java.lang.String} object.
|
||||
* @param clr2 a {@link java.lang.String} object.
|
||||
* @param clr3 a {@link java.lang.String} object.
|
||||
* @param clr4 a {@link java.lang.String} object.
|
||||
* @param clr5 a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* Constructor for Generate5ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param clr1
|
||||
* a {@link java.lang.String} object.
|
||||
* @param clr2
|
||||
* a {@link java.lang.String} object.
|
||||
* @param clr3
|
||||
* a {@link java.lang.String} object.
|
||||
* @param clr4
|
||||
* a {@link java.lang.String} object.
|
||||
* @param clr5
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public Generate5ColorDeck(final String clr1, final String clr2,
|
||||
final String clr3, final String clr4, final String clr5)
|
||||
{
|
||||
public Generate5ColorDeck(final String clr1, final String clr2, final String clr3, final String clr4,
|
||||
final String clr5) {
|
||||
r = MyRandom.random;
|
||||
|
||||
cardCounts = new HashMap<String, Integer>();
|
||||
@@ -91,10 +99,14 @@ public class Generate5ColorDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>get3ColorDeck.</p>
|
||||
*
|
||||
* @param size a int.
|
||||
* @param pt a PlayerType
|
||||
* <p>
|
||||
* get3ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param size
|
||||
* a int.
|
||||
* @param pt
|
||||
* a PlayerType
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList get5ColorDeck(final int size, final PlayerType pt) {
|
||||
@@ -112,8 +124,8 @@ public class Generate5ColorDeck {
|
||||
public boolean addCard(final Card c) {
|
||||
if (c.getSVar("RemRandomDeck").equals("True")) {
|
||||
return false;
|
||||
}
|
||||
return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN)));
|
||||
}
|
||||
return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN)));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -149,7 +161,7 @@ public class Generate5ColorDeck {
|
||||
CardList cr4 = cL4.getType("Creature");
|
||||
CardList cr5 = cL5.getType("Creature");
|
||||
|
||||
String[] ise = {"Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature"};
|
||||
String[] ise = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" };
|
||||
CardList sp1 = cL1.getValidCards(ise, null, null);
|
||||
CardList sp2 = cL2.getValidCards(ise, null, null);
|
||||
CardList sp3 = cL3.getValidCards(ise, null, null);
|
||||
@@ -161,8 +173,8 @@ public class Generate5ColorDeck {
|
||||
CardList sp12345 = new CardList();
|
||||
|
||||
// used for mana curve in the card pool
|
||||
final int[] minCMC = {1};
|
||||
final int[] maxCMC = {3};
|
||||
final int[] minCMC = { 1 };
|
||||
final int[] maxCMC = { 3 };
|
||||
CardListFilter cmcF = new CardListFilter() {
|
||||
public boolean addCard(final Card c) {
|
||||
int cCMC = c.getCMC();
|
||||
@@ -229,10 +241,11 @@ public class Generate5ColorDeck {
|
||||
minCMC[0] += 2;
|
||||
maxCMC[0] += 2;
|
||||
// resulting mana curve of the card pool
|
||||
//18x 1 - 3
|
||||
//12x 3 - 5
|
||||
//6x 5 - 7
|
||||
//=36x - card pool could support up to a 257 card deck (all 4-ofs plus basic lands)
|
||||
// 18x 1 - 3
|
||||
// 12x 3 - 5
|
||||
// 6x 5 - 7
|
||||
// =36x - card pool could support up to a 257 card deck (all 4-ofs
|
||||
// plus basic lands)
|
||||
}
|
||||
|
||||
// shuffle card pools
|
||||
@@ -290,7 +303,8 @@ public class Generate5ColorDeck {
|
||||
if (landsPercentage > 0) {
|
||||
p = (float) ((float) landsPercentage * .01);
|
||||
numLands = (int) (p * (float) size);
|
||||
} else { // otherwise, just fill in the rest of the deck with basic lands
|
||||
} else { // otherwise, just fill in the rest of the deck with basic
|
||||
// lands
|
||||
numLands = size - tDeck.size();
|
||||
}
|
||||
|
||||
@@ -317,13 +331,11 @@ public class Generate5ColorDeck {
|
||||
|
||||
numLands -= nDLands;
|
||||
|
||||
if (numLands > 0) // attempt to optimize basic land counts according to color representation
|
||||
if (numLands > 0) // attempt to optimize basic land counts according to
|
||||
// color representation
|
||||
{
|
||||
CCnt[] clrCnts = {new CCnt("Plains", 0),
|
||||
new CCnt("Island", 0),
|
||||
new CCnt("Swamp", 0),
|
||||
new CCnt("Mountain", 0),
|
||||
new CCnt("Forest", 0)};
|
||||
CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
|
||||
new CCnt("Mountain", 0), new CCnt("Forest", 0) };
|
||||
|
||||
// count each card color using mana costs
|
||||
// TODO: count hybrid mana differently?
|
||||
@@ -336,17 +348,13 @@ public class Generate5ColorDeck {
|
||||
|
||||
if (c == 'W') {
|
||||
clrCnts[0].setCount(clrCnts[0].getCount() + 1);
|
||||
}
|
||||
else if (c == 'U') {
|
||||
} else if (c == 'U') {
|
||||
clrCnts[1].setCount(clrCnts[1].getCount() + 1);
|
||||
}
|
||||
else if (c == 'B') {
|
||||
} else if (c == 'B') {
|
||||
clrCnts[2].setCount(clrCnts[2].getCount() + 1);
|
||||
}
|
||||
else if (c == 'R') {
|
||||
} else if (c == 'R') {
|
||||
clrCnts[3].setCount(clrCnts[3].getCount() + 1);
|
||||
}
|
||||
else if (c == 'G') {
|
||||
} else if (c == 'G') {
|
||||
clrCnts[4].setCount(clrCnts[4].getCount() + 1);
|
||||
}
|
||||
}
|
||||
@@ -362,12 +370,14 @@ public class Generate5ColorDeck {
|
||||
tmpDeck += "totalColor:" + totalColor + "\n";
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (clrCnts[i].getCount() > 0) { // calculate number of lands for each color
|
||||
if (clrCnts[i].getCount() > 0) { // calculate number of lands
|
||||
// for each color
|
||||
p = (float) clrCnts[i].getCount() / (float) totalColor;
|
||||
int nLand = (int) ((float) numLands * p);
|
||||
tmpDeck += "nLand-" + clrCnts[i].getColor() + ":" + nLand + "\n";
|
||||
|
||||
// just to prevent a null exception by the deck size fixing code
|
||||
// just to prevent a null exception by the deck size fixing
|
||||
// code
|
||||
cardCounts.put(clrCnts[i].getColor(), nLand);
|
||||
|
||||
for (int j = 0; j <= nLand; j++) {
|
||||
@@ -405,7 +415,7 @@ public class Generate5ColorDeck {
|
||||
for (int i = 0; i < diff; i++) {
|
||||
Card c = tDeck.get(r.nextInt(tDeck.size()));
|
||||
|
||||
while (c.isBasicLand()) { // don't remove basic lands
|
||||
while (c.isBasicLand()) { // don't remove basic lands
|
||||
c = tDeck.get(r.nextInt(tDeck.size()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
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;
|
||||
@@ -9,13 +13,12 @@ import forge.CardListUtil;
|
||||
import forge.CardUtil;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>GenerateConstructedDeck class.</p>
|
||||
*
|
||||
* <p>
|
||||
* GenerateConstructedDeck class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -26,14 +29,18 @@ public class GenerateConstructedDeck {
|
||||
private Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
* <p>Constructor for GenerateConstructedDeck.</p>
|
||||
* <p>
|
||||
* Constructor for GenerateConstructedDeck.
|
||||
* </p>
|
||||
*/
|
||||
public GenerateConstructedDeck() {
|
||||
setupMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setupMap.</p>
|
||||
* <p>
|
||||
* setupMap.
|
||||
* </p>
|
||||
*/
|
||||
private void setupMap() {
|
||||
map.put(Constant.Color.Black, "Swamp");
|
||||
@@ -44,8 +51,10 @@ public class GenerateConstructedDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>generateDeck.</p>
|
||||
*
|
||||
* <p>
|
||||
* generateDeck.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList generateDeck() {
|
||||
@@ -62,16 +71,21 @@ public class GenerateConstructedDeck {
|
||||
addLand(deck);
|
||||
|
||||
if (deck.size() != 60) {
|
||||
throw new RuntimeException("GenerateConstructedDeck() : generateDeck() error, deck size it not 60, deck size is " + deck.size());
|
||||
throw new RuntimeException(
|
||||
"GenerateConstructedDeck() : generateDeck() error, deck size it not 60, deck size is "
|
||||
+ deck.size());
|
||||
}
|
||||
return deck;
|
||||
}
|
||||
|
||||
//25 lands
|
||||
// 25 lands
|
||||
/**
|
||||
* <p>addLand.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* addLand.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
private void addLand(final CardList list) {
|
||||
Card land;
|
||||
@@ -82,25 +96,27 @@ public class GenerateConstructedDeck {
|
||||
land = AllZone.getCardFactory().getCard(map.get(color2).toString(), AllZone.getComputerPlayer());
|
||||
list.add(land);
|
||||
}
|
||||
} //addLand()
|
||||
} // 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.
|
||||
*
|
||||
* 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
|
||||
* never null
|
||||
*/
|
||||
private CardList getCards() {
|
||||
return filterBadCards(AllZone.getCardFactory());
|
||||
} //getCards()
|
||||
} // getCards()
|
||||
|
||||
/**
|
||||
* <p>get2ColorDeck.</p>
|
||||
*
|
||||
* <p>
|
||||
* get2ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
private CardList get2ColorDeck() {
|
||||
@@ -109,7 +125,8 @@ public class GenerateConstructedDeck {
|
||||
CardList out = new CardList();
|
||||
deck.shuffle();
|
||||
|
||||
//trim deck size down to 34 cards, presumes 26 land, for a total of 60 cards
|
||||
// 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));
|
||||
}
|
||||
@@ -117,9 +134,12 @@ public class GenerateConstructedDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>get2Colors.</p>
|
||||
*
|
||||
* @param in a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* get2Colors.
|
||||
* </p>
|
||||
*
|
||||
* @param in
|
||||
* a {@link forge.CardList} object.
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
private CardList get2Colors(final CardList in) {
|
||||
@@ -129,7 +149,7 @@ public class GenerateConstructedDeck {
|
||||
do {
|
||||
a = CardUtil.getRandomIndex(Constant.Color.onlyColors);
|
||||
b = CardUtil.getRandomIndex(Constant.Color.onlyColors);
|
||||
} while (a == b); //do not want to get the same color twice
|
||||
} while (a == b); // do not want to get the same color twice
|
||||
|
||||
color1 = Constant.Color.onlyColors[a];
|
||||
color2 = Constant.Color.onlyColors[b];
|
||||
@@ -141,8 +161,8 @@ public class GenerateConstructedDeck {
|
||||
|
||||
CardList artifact = in.filter(new CardListFilter() {
|
||||
public boolean addCard(final Card c) {
|
||||
//is this really a colorless artifact and not something
|
||||
//weird like Sarcomite Myr which is a colored artifact
|
||||
// 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().deckGenRmvArtifacts;
|
||||
}
|
||||
@@ -164,14 +184,14 @@ public class GenerateConstructedDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* @return a subset of sequence <= sequence; might be empty, but never
|
||||
* null
|
||||
* @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) {
|
||||
|
||||
@@ -185,14 +205,15 @@ public class GenerateConstructedDeck {
|
||||
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
|
||||
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()
|
||||
} // filterBadCards()
|
||||
}
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
package forge.deck.generate;
|
||||
|
||||
import forge.*;
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>GenerateConstructedMultiColorDeck class.</p>
|
||||
*
|
||||
* <p>
|
||||
* GenerateConstructedMultiColorDeck class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -22,7 +33,9 @@ public class GenerateConstructedMultiColorDeck {
|
||||
private Map<String, String[]> multiMap = new HashMap<String, String[]>();
|
||||
|
||||
/**
|
||||
* <p>Constructor for GenerateConstructedMultiColorDeck.</p>
|
||||
* <p>
|
||||
* Constructor for GenerateConstructedMultiColorDeck.
|
||||
* </p>
|
||||
*/
|
||||
public GenerateConstructedMultiColorDeck() {
|
||||
setupBasicLandMap();
|
||||
@@ -30,7 +43,9 @@ public class GenerateConstructedMultiColorDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setupBasicLandMap.</p>
|
||||
* <p>
|
||||
* setupBasicLandMap.
|
||||
* </p>
|
||||
*/
|
||||
private void setupBasicLandMap() {
|
||||
map.put(Constant.Color.Black, "Swamp");
|
||||
@@ -41,38 +56,41 @@ public class GenerateConstructedMultiColorDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setupMultiMap.</p>
|
||||
* <p>
|
||||
* setupMultiMap.
|
||||
* </p>
|
||||
*/
|
||||
private void setupMultiMap() {
|
||||
multiMap.put(Constant.Color.Black + Constant.Color.Blue, new String[]{"Underground Sea", "Watery Grave"});
|
||||
multiMap.put(Constant.Color.Black + Constant.Color.Green, new String[]{"Bayou", "Overgrown Tomb"});
|
||||
multiMap.put(Constant.Color.Black + Constant.Color.Red, new String[]{"Badlands", "Blood Crypt"});
|
||||
multiMap.put(Constant.Color.Black + Constant.Color.White, new String[]{"Scrubland", "Godless Shrine"});
|
||||
multiMap.put(Constant.Color.Blue + Constant.Color.Black, new String[]{"Underground Sea", "Watery Grave"});
|
||||
multiMap.put(Constant.Color.Blue + Constant.Color.Green, new String[]{"Tropical Island", "Breeding Pool"});
|
||||
multiMap.put(Constant.Color.Blue + Constant.Color.Red, new String[]{"Volcanic Island", "Steam Vents"});
|
||||
multiMap.put(Constant.Color.Blue + Constant.Color.White, new String[]{"Tundra", "Hallowed Fountain"});
|
||||
multiMap.put(Constant.Color.Green + Constant.Color.Black, new String[]{"Bayou", "Overgrown Tomb"});
|
||||
multiMap.put(Constant.Color.Green + Constant.Color.Blue, new String[]{"Tropical Island", "Breeding Pool"});
|
||||
multiMap.put(Constant.Color.Green + Constant.Color.Red, new String[]{"Taiga", "Stomping Ground"});
|
||||
multiMap.put(Constant.Color.Green + Constant.Color.White, new String[]{"Savannah", "Temple Garden"});
|
||||
multiMap.put(Constant.Color.Red + Constant.Color.Black, new String[]{"Badlands", "Blood Crypt"});
|
||||
multiMap.put(Constant.Color.Red + Constant.Color.Blue, new String[]{"Volcanic Island", "Steam Vents"});
|
||||
multiMap.put(Constant.Color.Red + Constant.Color.Green, new String[]{"Taiga", "Stomping Ground"});
|
||||
multiMap.put(Constant.Color.Red + Constant.Color.White, new String[]{"Plateau", "Sacred Foundry"});
|
||||
multiMap.put(Constant.Color.White + Constant.Color.Black, new String[]{"Scrubland", "Godless Shrine"});
|
||||
multiMap.put(Constant.Color.White + Constant.Color.Blue, new String[]{"Tundra", "Hallowed Fountain"});
|
||||
multiMap.put(Constant.Color.White + Constant.Color.Green, new String[]{"Savannah", "Temple Garden"});
|
||||
multiMap.put(Constant.Color.White + Constant.Color.Red, new String[]{"Plateau", "Sacred Foundry"});
|
||||
multiMap.put(Constant.Color.Black + Constant.Color.Blue, new String[] { "Underground Sea", "Watery Grave" });
|
||||
multiMap.put(Constant.Color.Black + Constant.Color.Green, new String[] { "Bayou", "Overgrown Tomb" });
|
||||
multiMap.put(Constant.Color.Black + Constant.Color.Red, new String[] { "Badlands", "Blood Crypt" });
|
||||
multiMap.put(Constant.Color.Black + Constant.Color.White, new String[] { "Scrubland", "Godless Shrine" });
|
||||
multiMap.put(Constant.Color.Blue + Constant.Color.Black, new String[] { "Underground Sea", "Watery Grave" });
|
||||
multiMap.put(Constant.Color.Blue + Constant.Color.Green, new String[] { "Tropical Island", "Breeding Pool" });
|
||||
multiMap.put(Constant.Color.Blue + Constant.Color.Red, new String[] { "Volcanic Island", "Steam Vents" });
|
||||
multiMap.put(Constant.Color.Blue + Constant.Color.White, new String[] { "Tundra", "Hallowed Fountain" });
|
||||
multiMap.put(Constant.Color.Green + Constant.Color.Black, new String[] { "Bayou", "Overgrown Tomb" });
|
||||
multiMap.put(Constant.Color.Green + Constant.Color.Blue, new String[] { "Tropical Island", "Breeding Pool" });
|
||||
multiMap.put(Constant.Color.Green + Constant.Color.Red, new String[] { "Taiga", "Stomping Ground" });
|
||||
multiMap.put(Constant.Color.Green + Constant.Color.White, new String[] { "Savannah", "Temple Garden" });
|
||||
multiMap.put(Constant.Color.Red + Constant.Color.Black, new String[] { "Badlands", "Blood Crypt" });
|
||||
multiMap.put(Constant.Color.Red + Constant.Color.Blue, new String[] { "Volcanic Island", "Steam Vents" });
|
||||
multiMap.put(Constant.Color.Red + Constant.Color.Green, new String[] { "Taiga", "Stomping Ground" });
|
||||
multiMap.put(Constant.Color.Red + Constant.Color.White, new String[] { "Plateau", "Sacred Foundry" });
|
||||
multiMap.put(Constant.Color.White + Constant.Color.Black, new String[] { "Scrubland", "Godless Shrine" });
|
||||
multiMap.put(Constant.Color.White + Constant.Color.Blue, new String[] { "Tundra", "Hallowed Fountain" });
|
||||
multiMap.put(Constant.Color.White + Constant.Color.Green, new String[] { "Savannah", "Temple Garden" });
|
||||
multiMap.put(Constant.Color.White + Constant.Color.Red, new String[] { "Plateau", "Sacred Foundry" });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>generate3ColorDeck.</p>
|
||||
*
|
||||
* <p>
|
||||
* generate3ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public CardList generate3ColorDeck() {
|
||||
public final CardList generate3ColorDeck() {
|
||||
CardList deck;
|
||||
|
||||
int check;
|
||||
@@ -85,37 +103,49 @@ public class GenerateConstructedMultiColorDeck {
|
||||
|
||||
addLand(deck, 3);
|
||||
|
||||
if (deck.size() != 60)
|
||||
throw new RuntimeException("GenerateConstructedDeck() : generateDeck() error, deck size it not 60, deck size is " + deck.size());
|
||||
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>
|
||||
*
|
||||
* <p>
|
||||
* generate5ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public CardList generate5ColorDeck() {
|
||||
public final CardList generate5ColorDeck() {
|
||||
CardList deck;
|
||||
|
||||
deck = get5ColorDeck();
|
||||
|
||||
addLand(deck, 5);
|
||||
|
||||
if (deck.size() != 60)
|
||||
throw new RuntimeException("GenerateConstructedDeck() : generateDeck() error, deck size it not 60, deck size is " + deck.size());
|
||||
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.
|
||||
* <p>
|
||||
* addLand.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
* @param colors
|
||||
* a int.
|
||||
*/
|
||||
private void addLand(CardList list, int colors) {
|
||||
private void addLand(final CardList list, final int colors) {
|
||||
if (colors == 3) {
|
||||
int numberBasic = 2;
|
||||
Card land;
|
||||
@@ -173,7 +203,6 @@ public class GenerateConstructedMultiColorDeck {
|
||||
list.add(land);
|
||||
}
|
||||
|
||||
|
||||
int numberDual = 2;
|
||||
for (int i = 0; i < numberDual; i++) {
|
||||
land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color2)[0], AllZone.getComputerPlayer());
|
||||
@@ -208,25 +237,28 @@ public class GenerateConstructedMultiColorDeck {
|
||||
}
|
||||
|
||||
}
|
||||
}//addLand()
|
||||
} // 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.
|
||||
* Filters out cards by color and their suitability for being placed in a
|
||||
* randomly created deck.
|
||||
*
|
||||
* @return a subset of all cards in the CardFactory database
|
||||
* which might be empty, but never null
|
||||
* @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(int colors) {
|
||||
private CardList getCards(final int colors) {
|
||||
return filterBadCards(AllZone.getCardFactory(), colors);
|
||||
}//getCards()
|
||||
} // getCards()
|
||||
|
||||
/**
|
||||
* <p>get3ColorDeck.</p>
|
||||
*
|
||||
* <p>
|
||||
* get3ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
private CardList get3ColorDeck() {
|
||||
@@ -235,16 +267,20 @@ public class GenerateConstructedMultiColorDeck {
|
||||
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++)
|
||||
// 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>
|
||||
*
|
||||
* <p>
|
||||
* get5ColorDeck.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
private CardList get5ColorDeck() {
|
||||
@@ -253,20 +289,25 @@ public class GenerateConstructedMultiColorDeck {
|
||||
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++)
|
||||
// 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.
|
||||
* <p>
|
||||
* get3Colors.
|
||||
* </p>
|
||||
*
|
||||
* @param in
|
||||
* a {@link forge.CardList} object.
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
private CardList get3Colors(CardList in) {
|
||||
private CardList get3Colors(final CardList in) {
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
@@ -275,7 +316,8 @@ public class GenerateConstructedMultiColorDeck {
|
||||
do {
|
||||
b = CardUtil.getRandomIndex(Constant.Color.onlyColors);
|
||||
c = CardUtil.getRandomIndex(Constant.Color.onlyColors);
|
||||
} while (a == b || a == c || b == c);//do not want to get the same color thrice
|
||||
} while (a == b || a == c || b == c); // do not want to get the same
|
||||
// color thrice
|
||||
|
||||
color1 = Constant.Color.onlyColors[a];
|
||||
color2 = Constant.Color.onlyColors[b];
|
||||
@@ -288,21 +330,18 @@ public class GenerateConstructedMultiColorDeck {
|
||||
out.shuffle();
|
||||
|
||||
CardList artifact = in.filter(new CardListFilter() {
|
||||
public boolean addCard(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().deckGenRmvArtifacts;
|
||||
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().deckGenRmvArtifacts;
|
||||
}
|
||||
});
|
||||
out.addAll(artifact);
|
||||
|
||||
out = out.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
if (c.isCreature() &&
|
||||
c.getNetAttack() <= 1 &&
|
||||
Singletons.getModel().getPreferences().deckGenRmvSmall) {
|
||||
public boolean addCard(final Card c) {
|
||||
if (c.isCreature() && c.getNetAttack() <= 1 && Singletons.getModel().getPreferences().deckGenRmvSmall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -315,12 +354,15 @@ public class GenerateConstructedMultiColorDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>get5Colors.</p>
|
||||
*
|
||||
* @param in a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* get5Colors.
|
||||
* </p>
|
||||
*
|
||||
* @param in
|
||||
* a {@link forge.CardList} object.
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
private CardList get5Colors(CardList in) {
|
||||
private CardList get5Colors(final CardList in) {
|
||||
|
||||
color1 = Constant.Color.Black;
|
||||
color2 = Constant.Color.Blue;
|
||||
@@ -330,31 +372,28 @@ public class GenerateConstructedMultiColorDeck {
|
||||
|
||||
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.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();
|
||||
|
||||
CardList artifact = in.filter(new CardListFilter() {
|
||||
public boolean addCard(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().deckGenRmvArtifacts;
|
||||
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().deckGenRmvArtifacts;
|
||||
}
|
||||
});
|
||||
out.addAll(artifact);
|
||||
|
||||
out = out.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
if (c.isCreature() &&
|
||||
c.getNetAttack() <= 1 &&
|
||||
Singletons.getModel().getPreferences().deckGenRmvSmall) {
|
||||
public boolean addCard(final Card c) {
|
||||
if (c.isCreature() && c.getNetAttack() <= 1 && Singletons.getModel().getPreferences().deckGenRmvSmall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -366,56 +405,61 @@ public class GenerateConstructedMultiColorDeck {
|
||||
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
|
||||
* 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.
|
||||
* @param sequence
|
||||
* an Iterable of Card instances
|
||||
*
|
||||
* @return a subset of sequence <= sequence which might be empty, but
|
||||
* never null
|
||||
* @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(Iterable<Card> sequence, int colors) {
|
||||
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");
|
||||
// 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() {
|
||||
public boolean addCard(Card c) {
|
||||
public boolean addCard(final Card c) {
|
||||
ArrayList<String> list = CardUtil.getColors(c);
|
||||
|
||||
if (list.size() == 3) {
|
||||
if (!list.contains(color1) || !list.contains(color2) || !list.contains(color3))
|
||||
if (!list.contains(color1) || !list.contains(color2) || !list.contains(color3)) {
|
||||
return false;
|
||||
}
|
||||
} else if (list.size() == 2) {
|
||||
if (!(list.contains(color1) && list.contains(color2)) &&
|
||||
!(list.contains(color1) && list.contains(color3)) &&
|
||||
!(list.contains(color2) && list.contains(color3)))
|
||||
if (!(list.contains(color1) && list.contains(color2))
|
||||
&& !(list.contains(color1) && list.contains(color3))
|
||||
&& !(list.contains(color2) && list.contains(color3))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return CardUtil.getColors(c).size() <= 3 &&
|
||||
!c.isLand() && //no land
|
||||
!c.getSVar("RemRandomDeck").equals("True") &&
|
||||
!c.getSVar("RemAIDeck").equals("True") || //OR very important
|
||||
return CardUtil.getColors(c).size() <= 3 && !c.isLand() && // no
|
||||
// land
|
||||
!c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True") ||
|
||||
// OR very important
|
||||
goodLand.contains(c.getName());
|
||||
}
|
||||
});
|
||||
} else if (colors == 5) {
|
||||
out = CardFilter.filter(sequence, new CardListFilter() {
|
||||
public boolean addCard(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") || //OR very important
|
||||
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") ||
|
||||
// OR very important
|
||||
goodLand.contains(c.getName());
|
||||
}
|
||||
});
|
||||
@@ -423,5 +467,5 @@ public class GenerateConstructedMultiColorDeck {
|
||||
}
|
||||
|
||||
return out;
|
||||
}//filterBadCards()
|
||||
} // filterBadCards()
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package forge.deck.generate;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* <p>GenerateDeckUtil class.</p>
|
||||
*
|
||||
* <p>
|
||||
* GenerateDeckUtil class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: GenerateDeckUtil.java 10011 2011-08-28 12:20:52Z Sloth $
|
||||
*/
|
||||
@@ -13,7 +15,9 @@ public class GenerateDeckUtil {
|
||||
/**
|
||||
*
|
||||
* Arrays of dual and tri-land cards.
|
||||
* @param colors a String
|
||||
*
|
||||
* @param colors
|
||||
* a String
|
||||
* @return ArrayList<String>
|
||||
*/
|
||||
public static ArrayList<String> getDualLandList(final String colors) {
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
package forge.deck.generate;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
import forge.MyRandom;
|
||||
import forge.error.ErrorViewer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@@ -15,9 +9,17 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
import forge.MyRandom;
|
||||
import forge.error.ErrorViewer;
|
||||
|
||||
/**
|
||||
* <p>GenerateThemeDeck class.</p>
|
||||
*
|
||||
* <p>
|
||||
* GenerateThemeDeck class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -25,15 +27,19 @@ public class GenerateThemeDeck {
|
||||
private BufferedReader in = null;
|
||||
|
||||
/**
|
||||
* <p>Constructor for GenerateThemeDeck.</p>
|
||||
* <p>
|
||||
* Constructor for GenerateThemeDeck.
|
||||
* </p>
|
||||
*/
|
||||
public GenerateThemeDeck() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getThemeNames.</p>
|
||||
*
|
||||
* <p>
|
||||
* getThemeNames.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public final ArrayList<String> getThemeNames() {
|
||||
@@ -62,13 +68,17 @@ public class GenerateThemeDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getThemeDeck.</p>
|
||||
*
|
||||
* @param themeName a {@link java.lang.String} object.
|
||||
* @param size a int.
|
||||
* <p>
|
||||
* getThemeDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param themeName
|
||||
* a {@link java.lang.String} object.
|
||||
* @param size
|
||||
* a int.
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public CardList getThemeDeck(final String themeName, final int size) {
|
||||
public final CardList getThemeDeck(final String themeName, final int size) {
|
||||
CardList tDeck = new CardList();
|
||||
|
||||
ArrayList<Grp> groups = new ArrayList<Grp>();
|
||||
@@ -158,7 +168,9 @@ public class GenerateThemeDeck {
|
||||
s = g.Cardnames.get(r.nextInt(cnSize));
|
||||
|
||||
int lc = 0;
|
||||
while (cardCounts.get(s) >= g.MaxCnt || lc > size) // don't keep looping forever
|
||||
while (cardCounts.get(s) >= g.MaxCnt || lc > size) // don't keep
|
||||
// looping
|
||||
// forever
|
||||
{
|
||||
s = g.Cardnames.get(r.nextInt(cnSize));
|
||||
lc++;
|
||||
@@ -177,22 +189,21 @@ public class GenerateThemeDeck {
|
||||
}
|
||||
|
||||
int numBLands = 0;
|
||||
if (bLandPercentage > 0) { // if theme explicitly defines this
|
||||
if (bLandPercentage > 0) { // if theme explicitly defines this
|
||||
float p = (float) ((float) bLandPercentage * .01);
|
||||
numBLands = (int) (p * (float) size);
|
||||
} else { // otherwise, just fill in the rest of the deck with basic lands
|
||||
} else { // otherwise, just fill in the rest of the deck with basic
|
||||
// lands
|
||||
numBLands = size - tDeck.size();
|
||||
}
|
||||
|
||||
tmpDeck += "numBLands:" + numBLands + "\n";
|
||||
|
||||
if (numBLands > 0) // attempt to optimize basic land counts according to color representation
|
||||
if (numBLands > 0) // attempt to optimize basic land counts according to
|
||||
// color representation
|
||||
{
|
||||
CCnt[] clrCnts = {new CCnt("Plains", 0),
|
||||
new CCnt("Island", 0),
|
||||
new CCnt("Swamp", 0),
|
||||
new CCnt("Mountain", 0),
|
||||
new CCnt("Forest", 0)};
|
||||
CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
|
||||
new CCnt("Mountain", 0), new CCnt("Forest", 0) };
|
||||
|
||||
// count each instance of a color in mana costs
|
||||
// TODO count hybrid mana differently?
|
||||
@@ -225,7 +236,8 @@ public class GenerateThemeDeck {
|
||||
tmpDeck += "totalColor:" + totalColor + "\n";
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (clrCnts[i].Count > 0) { // calculate number of lands for each color
|
||||
if (clrCnts[i].Count > 0) { // calculate number of lands for
|
||||
// each color
|
||||
float p = (float) clrCnts[i].Count / (float) totalColor;
|
||||
int nLand = (int) ((float) numBLands * p);
|
||||
tmpDeck += "numLand-" + clrCnts[i].Color + ":" + nLand + "\n";
|
||||
@@ -278,12 +290,14 @@ public class GenerateThemeDeck {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>readLine.</p>
|
||||
*
|
||||
* <p>
|
||||
* readLine.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private String readLine() {
|
||||
//makes the checked exception, into an unchecked runtime exception
|
||||
// makes the checked exception, into an unchecked runtime exception
|
||||
try {
|
||||
String s = in.readLine();
|
||||
if (s != null) {
|
||||
@@ -294,18 +308,30 @@ public class GenerateThemeDeck {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("GenerateThemeDeck : readLine error");
|
||||
}
|
||||
} //readLine(Card)
|
||||
} // readLine(Card)
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO Write javadoc for this type.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class CCnt {
|
||||
|
||||
/** The Color. */
|
||||
public String Color;
|
||||
|
||||
/** The Count. */
|
||||
public int Count;
|
||||
|
||||
public CCnt(String clr, int cnt) {
|
||||
/**
|
||||
* Instantiates a new c cnt.
|
||||
*
|
||||
* @param clr
|
||||
* the clr
|
||||
* @param cnt
|
||||
* the cnt
|
||||
*/
|
||||
public CCnt(final String clr, final int cnt) {
|
||||
Color = clr;
|
||||
Count = cnt;
|
||||
}
|
||||
@@ -314,12 +340,17 @@ public class GenerateThemeDeck {
|
||||
/**
|
||||
*
|
||||
* TODO Write javadoc for this type.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class Grp {
|
||||
|
||||
/** The Cardnames. */
|
||||
public ArrayList<String> Cardnames = new ArrayList<String>();
|
||||
|
||||
/** The Max cnt. */
|
||||
public int MaxCnt;
|
||||
|
||||
/** The Percentage. */
|
||||
public int Percentage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
/** Forge Card Game */
|
||||
/** Forge Card Game. */
|
||||
package forge.deck.generate;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
/** Forge Card Game */
|
||||
/** Forge Card Game. */
|
||||
package forge.deck;
|
||||
|
||||
Reference in New Issue
Block a user