diff --git a/src/main/java/forge/game/GameEndReason.java b/src/main/java/forge/game/GameEndReason.java index 8c0bf5fd596..0cc6aa445bb 100644 --- a/src/main/java/forge/game/GameEndReason.java +++ b/src/main/java/forge/game/GameEndReason.java @@ -1,10 +1,18 @@ package forge.game; +/** + * The Enum GameEndReason. + */ public enum GameEndReason { + /** The All opponents lost. */ AllOpponentsLost, // Noone won - Draw, // Having little idea how they can reach a draw, so I didn't enumerate possible reasons here + /** The Draw. */ + Draw, // Having little idea how they can reach a draw, so I didn't enumerate + // possible reasons here // Special conditions, they force one player to win and thus end the game - WinsGameSpellEffect // ones that could be both hardcoded (felidar) and scripted ( such as Mayael's Aria ) + /** The Wins game spell effect. */ + WinsGameSpellEffect // ones that could be both hardcoded (felidar) and + // scripted ( such as Mayael's Aria ) } diff --git a/src/main/java/forge/game/GameFormat.java b/src/main/java/forge/game/GameFormat.java index cbab3dcf94a..5da08e88d2f 100644 --- a/src/main/java/forge/game/GameFormat.java +++ b/src/main/java/forge/game/GameFormat.java @@ -4,62 +4,95 @@ import java.util.Collections; import java.util.List; import net.slightlymagic.maxmtg.Predicate; - import forge.card.CardRules; import forge.item.CardPrinted; -/** +/** * TODO: Write javadoc for this type. - * + * */ public final class GameFormat { - + private final String name; // contains allowed sets, when empty allows all sets - private final List allowedSetCodes; - private final List bannedCardNames; - + private final List allowedSetCodes; + private final List bannedCardNames; + private final Predicate filterRules; private final Predicate filterPrinted; - - - public GameFormat(final String fName, final List sets, final List bannedCards) - { - name = fName; - allowedSetCodes = Collections.unmodifiableList(sets); - bannedCardNames = Collections.unmodifiableList(bannedCards); - filterRules = buildFilterRules(); - filterPrinted = buildFilterPritned(); + + /** + * Instantiates a new game format. + * + * @param fName the f name + * @param sets the sets + * @param bannedCards the banned cards + */ + public GameFormat(final String fName, final List sets, final List bannedCards) { + this.name = fName; + this.allowedSetCodes = Collections.unmodifiableList(sets); + this.bannedCardNames = Collections.unmodifiableList(bannedCards); + this.filterRules = this.buildFilterRules(); + this.filterPrinted = this.buildFilterPritned(); } - private Predicate buildFilterPritned() { - Predicate banNames = CardPrinted.Predicates.namesExcept(bannedCardNames); - Predicate allowSets = allowedSetCodes == null || allowedSetCodes.isEmpty() - ? CardPrinted.Predicates.Presets.isTrue - : CardPrinted.Predicates.printedInSets(allowedSetCodes, true); + final Predicate banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames); + final Predicate allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.isTrue + : CardPrinted.Predicates.printedInSets(this.allowedSetCodes, true); return Predicate.and(banNames, allowSets); } - private Predicate buildFilterRules() { - Predicate banNames = CardPrinted.Predicates.namesExcept(bannedCardNames); - Predicate allowSets = allowedSetCodes == null || allowedSetCodes.isEmpty() - ? CardPrinted.Predicates.Presets.isTrue - : Predicate.brigde(CardRules.Predicates.wasPrintedInSets(allowedSetCodes), CardPrinted.fnGetRules); + final Predicate banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames); + final Predicate allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.isTrue + : Predicate.brigde(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.fnGetRules); return Predicate.and(banNames, allowSets); } - public String getName() { return name; } - public Predicate getFilterRules() { return filterRules; } - public Predicate getFilterPrinted() { return filterPrinted; } - - public boolean isSetLegal(String setCode) { return allowedSetCodes.isEmpty() || allowedSetCodes.contains(setCode); } - - @Override - public String toString() - { - return name + " (format)"; + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return this.name; } - + + /** + * Gets the filter rules. + * + * @return the filter rules + */ + public Predicate getFilterRules() { + return this.filterRules; + } + + /** + * Gets the filter printed. + * + * @return the filter printed + */ + public Predicate getFilterPrinted() { + return this.filterPrinted; + } + + /** + * Checks if is sets the legal. + * + * @param setCode the set code + * @return true, if is sets the legal + */ + public boolean isSetLegal(final String setCode) { + return this.allowedSetCodes.isEmpty() || this.allowedSetCodes.contains(setCode); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return this.name + " (format)"; + } + } diff --git a/src/main/java/forge/game/GameLossReason.java b/src/main/java/forge/game/GameLossReason.java index d18f1e89abd..cc7176d8f9a 100644 --- a/src/main/java/forge/game/GameLossReason.java +++ b/src/main/java/forge/game/GameLossReason.java @@ -1,36 +1,52 @@ package forge.game; +/** + * The Enum GameLossReason. + */ public enum GameLossReason { - DidNotLoseYet, // a winner must have this status by the end of the game - - Conceded, // rule 104.3a - LifeReachedZero, // rule 104.3b - Milled, // 104.3c - Poisoned, // 104.3d + /** The Did not lose yet. */ + DidNotLoseYet, // a winner must have this status by the end of the game + + /** The Conceded. */ + Conceded, // rule 104.3a + /** The Life reached zero. */ + LifeReachedZero, // rule 104.3b + /** The Milled. */ + Milled, // 104.3c + /** The Poisoned. */ + Poisoned, // 104.3d // 104.3e and others - SpellEffect - - /*DoorToNothingness, // Door To Nothingness's ability activated - - // TODO: Implement game logics for the ones below - Transcendence20Life, // When you have 20 or more life, you lose the game. - FailedToPayPactUpkeep, // Pacts from Future Sight series (cost 0 but you must pay their real cost at next turn's upkeep, otherwise GL) - PhageTheUntouchableDamage, // Whenever Phage deals combat damage to a player, that player loses the game. - PhageTheUntouchableWrongETB, // When Phage the Untouchable ETB, if you didn't cast it from your hand, you lose the game. - NefariousLichLeavesTB, // When Nefarious Lich leaves the battlefield, you lose the game. - NefariousLichCannotExileGrave, // If damage would be dealt to you, exile that many cards from your graveyard instead. If you can't, you lose the game. - LichWasPutToGraveyard, // When Lich is put into a graveyard from the battlefield, you lose the game. - FinalFortune, // same as Warrior's Oath - lose at the granted extra turn's end step - ImmortalCoilEmptyGraveyard, // When there are no cards in your graveyard, you lose the game. - ForbiddenCryptEmptyGraveyard, // If you would draw a card, return a card from your graveyard to your hand instead. If you can't, you lose the game. + /** The Spell effect. */ + SpellEffect - // Amulet of quoz skipped for using ante, - // Form of the Squirrel and Rocket-Powered Turbo Slug skipped for being part of UN- set + /* + * DoorToNothingness, // Door To Nothingness's ability activated + * + * // TODO: Implement game logics for the ones below Transcendence20Life, // + * When you have 20 or more life, you lose the game. FailedToPayPactUpkeep, + * // Pacts from Future Sight series (cost 0 but you must pay their real + * cost at next turn's upkeep, otherwise GL) PhageTheUntouchableDamage, // + * Whenever Phage deals combat damage to a player, that player loses the + * game. PhageTheUntouchableWrongETB, // When Phage the Untouchable ETB, if + * you didn't cast it from your hand, you lose the game. + * NefariousLichLeavesTB, // When Nefarious Lich leaves the battlefield, you + * lose the game. NefariousLichCannotExileGrave, // If damage would be dealt + * to you, exile that many cards from your graveyard instead. If you can't, + * you lose the game. LichWasPutToGraveyard, // When Lich is put into a + * graveyard from the battlefield, you lose the game. FinalFortune, // same + * as Warrior's Oath - lose at the granted extra turn's end step + * ImmortalCoilEmptyGraveyard, // When there are no cards in your graveyard, + * you lose the game. ForbiddenCryptEmptyGraveyard, // If you would draw a + * card, return a card from your graveyard to your hand instead. If you + * can't, you lose the game. + * + * // Amulet of quoz skipped for using ante, // Form of the Squirrel and + * Rocket-Powered Turbo Slug skipped for being part of UN- set + */ - */ - - // refer to http://gatherer.wizards.com/Pages/Search/Default.aspx?output=standard&text=+[%22lose+the+game%22] for more cards when they are printed + // refer to + // http://gatherer.wizards.com/Pages/Search/Default.aspx?output=standard&text=+[%22lose+the+game%22] + // for more cards when they are printed } - diff --git a/src/main/java/forge/game/GamePlayerRating.java b/src/main/java/forge/game/GamePlayerRating.java index 29282f944a0..e9058543582 100644 --- a/src/main/java/forge/game/GamePlayerRating.java +++ b/src/main/java/forge/game/GamePlayerRating.java @@ -1,47 +1,91 @@ package forge.game; /** - * - * @author Max + * The Class GamePlayerRating. * + * @author Max */ public class GamePlayerRating { - boolean hasWonTheCoin; - protected int turnsMade = 0; - protected int openingHandSize = 7; - protected int timesMulliganed = 0; + /** The has won the coin. */ + private boolean hasWonTheCoin; - protected GameLossReason lossReason = GameLossReason.DidNotLoseYet; - protected String lossSpellName; + /** The turns made. */ + private int turnsMade = 0; + /** The opening hand size. */ + private int openingHandSize = 7; + + /** The times mulliganed. */ + private int timesMulliganed = 0; + + /** The loss reason. */ + private GameLossReason lossReason = GameLossReason.DidNotLoseYet; + + /** The loss spell name. */ + private String lossSpellName; + + /** + * Gets the loss reason. + * + * @return the loss reason + */ public final GameLossReason getLossReason() { - return lossReason; - } - - public void setLossReason(GameLossReason loseCondition, String spellName) { - lossReason = loseCondition; - lossSpellName = spellName; - } - public String getLossSpellName() { - return lossSpellName; + return this.lossReason; } + /** + * Sets the loss reason. + * + * @param loseCondition the lose condition + * @param spellName the spell name + */ + public void setLossReason(final GameLossReason loseCondition, final String spellName) { + this.lossReason = loseCondition; + this.lossSpellName = spellName; + } + + /** + * Gets the loss spell name. + * + * @return the loss spell name + */ + public String getLossSpellName() { + return this.lossSpellName; + } + + /** + * Gets the opening hand size. + * + * @return the opening hand size + */ public final int getOpeningHandSize() { - return openingHandSize; + return this.openingHandSize; } + /** + * Notify has mulliganed. + */ public final void notifyHasMulliganed() { - timesMulliganed++; + this.timesMulliganed++; } + /** + * Gets the mulligan count. + * + * @return the mulligan count + */ public final int getMulliganCount() { - return timesMulliganed; + return this.timesMulliganed; } + /** + * Notify opening hand size. + * + * @param newHand the new hand + */ public final void notifyOpeningHandSize(final int newHand) { - openingHandSize = newHand; + this.openingHandSize = newHand; } - } diff --git a/src/main/java/forge/game/GameSummary.java b/src/main/java/forge/game/GameSummary.java index 9a3ac3e1d32..0fc191b54e0 100644 --- a/src/main/java/forge/game/GameSummary.java +++ b/src/main/java/forge/game/GameSummary.java @@ -3,63 +3,141 @@ package forge.game; import java.util.HashMap; import java.util.Map; - /** - *

GameInfo class.

- * + *

+ * GameInfo class. + *

+ * * @author Forge * @version $Id$ */ -// This class might be divided in two parts: the very summary (immutable with only getters) and +// This class might be divided in two parts: the very summary (immutable with +// only getters) and // GameObserver class - who should be notified of any considerable ingame event public final class GameSummary { - protected String playerWinner = "Nobody"; - protected String playerGotFirstTurn = "Nobody"; - protected int lastTurnNumber = 0; - - protected GameEndReason winCondition; - protected String spellEffectWin; - protected final Map playerRating = new HashMap(); - public GameSummary(String... names) - { - for (String n : names) { - playerRating.put(n, new GamePlayerRating()); + /** The player winner. */ + private String playerWinner = "Nobody"; + + /** The player got first turn. */ + private String playerGotFirstTurn = "Nobody"; + + /** The last turn number. */ + private int lastTurnNumber = 0; + + /** The win condition. */ + private GameEndReason winCondition; + + /** The spell effect win. */ + private String spellEffectWin; + + /** The player rating. */ + private final Map playerRating = new HashMap(); + + /** + * Instantiates a new game summary. + * + * @param names the names + */ + public GameSummary(final String... names) { + for (final String n : names) { + this.playerRating.put(n, new GamePlayerRating()); } } - - public final void end( final GameEndReason condition, String winner, String spellEffect ) - { - winCondition = condition; - playerWinner = winner; - spellEffectWin = spellEffect; + + /** + * End. + * + * @param condition the condition + * @param winner the winner + * @param spellEffect the spell effect + */ + public void end(final GameEndReason condition, final String winner, final String spellEffect) { + this.winCondition = condition; + this.playerWinner = winner; + this.spellEffectWin = spellEffect; } - public final boolean isDraw() { return null == playerWinner; } - public final boolean isWinner(String name) { return name != null && name.equals(playerWinner); } - public String getWinner() { return playerWinner; } - public GameEndReason getWinCondition() { return winCondition; } - public GamePlayerRating getPlayerRating(String name) { return playerRating.get(name); } + /** + * Checks if is draw. + * + * @return true, if is draw + */ + public boolean isDraw() { + return null == this.playerWinner; + } + /** + * Checks if is winner. + * + * @param name the name + * @return true, if is winner + */ + public boolean isWinner(final String name) { + return (name != null) && name.equals(this.playerWinner); + } + + /** + * Gets the winner. + * + * @return the winner + */ + public String getWinner() { + return this.playerWinner; + } + + /** + * Gets the win condition. + * + * @return the win condition + */ + public GameEndReason getWinCondition() { + return this.winCondition; + } + + /** + * Gets the player rating. + * + * @param name the name + * @return the player rating + */ + public GamePlayerRating getPlayerRating(final String name) { + return this.playerRating.get(name); + } + + /** + * Gets the turn game ended. + * + * @return the turn game ended + */ public int getTurnGameEnded() { - return lastTurnNumber; - } - - public final void setPlayerWhoGotFirstTurn(String playerName) - { - playerGotFirstTurn = playerName; + return this.lastTurnNumber; } + /** + * Sets the player who got first turn. + * + * @param playerName the new player who got first turn + */ + public void setPlayerWhoGotFirstTurn(final String playerName) { + this.playerGotFirstTurn = playerName; + } + + /** + * Notify next turn. + */ public void notifyNextTurn() { - lastTurnNumber++; + this.lastTurnNumber++; } + /** + * Gets the win spell effect. + * + * @return the win spell effect + */ public String getWinSpellEffect() { - return spellEffectWin; + return this.spellEffectWin; } - - - } diff --git a/src/main/java/forge/game/GameType.java b/src/main/java/forge/game/GameType.java index 187bcaf7139..9123f2cc111 100644 --- a/src/main/java/forge/game/GameType.java +++ b/src/main/java/forge/game/GameType.java @@ -1,25 +1,50 @@ package forge.game; -/** +/** * GameType is an enum to determine the type of current game. :) */ public enum GameType { + + /** The Constructed. */ Constructed(false), - Sealed(true), - Draft(true), - Commander(false), - Quest(true); + /** The Sealed. */ + Sealed(true), + /** The Draft. */ + Draft(true), + /** The Commander. */ + Commander(false), + /** The Quest. */ + Quest(true); private final boolean bLimited; - public final boolean isLimited() { return bLimited; } - GameType(final boolean isLimited) { - bLimited = isLimited; + /** + * Checks if is limited. + * + * @return true, if is limited + */ + public final boolean isLimited() { + return this.bLimited; } + /** + * Instantiates a new game type. + * + * @param isLimited the is limited + */ + GameType(final boolean isLimited) { + this.bLimited = isLimited; + } + + /** + * Smart value of. + * + * @param value the value + * @return the game type + */ public static GameType smartValueOf(final String value) { - String valToCompate = value.trim(); - for (GameType v : GameType.values()) { + final String valToCompate = value.trim(); + for (final GameType v : GameType.values()) { if (v.name().compareToIgnoreCase(valToCompate) == 0) { return v; } diff --git a/src/main/java/forge/game/limited/BoosterDraft.java b/src/main/java/forge/game/limited/BoosterDraft.java index 5c41b6d5294..bfe581dfea0 100644 --- a/src/main/java/forge/game/limited/BoosterDraft.java +++ b/src/main/java/forge/game/limited/BoosterDraft.java @@ -5,52 +5,57 @@ import forge.item.CardPrinted; import forge.item.ItemPoolView; /** - *

BoosterDraft interface.

- * + *

+ * BoosterDraft interface. + *

+ * * @author Forge * @version $Id$ */ public interface BoosterDraft { /** - *

nextChoice.

- * + *

+ * nextChoice. + *

+ * * @return a {@link forge.CardList} object. */ ItemPoolView nextChoice(); /** - *

setChoice.

- * - * @param c a {@link forge.Card} object. + *

+ * setChoice. + *

+ * + * @param c + * a {@link forge.Card} object. */ void setChoice(CardPrinted c); /** - *

hasNextChoice.

- * + *

+ * hasNextChoice. + *

+ * * @return a boolean. */ boolean hasNextChoice(); /** - *

getDecks.

- * + *

+ * getDecks. + *

+ * * @return an array of {@link forge.deck.Deck} objects. */ - Deck[] getDecks(); //size 7, all the computers decks + Deck[] getDecks(); // size 7, all the computers decks /** Constant LandSetCode="{}". */ - public String LandSetCode[] = {""}; + String[] LAND_SET_CODE = { "" }; /** * Called when drafting is over - to upload picks. */ void finishedDrafting(); - + } - - - - - - diff --git a/src/main/java/forge/game/limited/BoosterDraftAI.java b/src/main/java/forge/game/limited/BoosterDraftAI.java index 73655cef271..78f1730d187 100644 --- a/src/main/java/forge/game/limited/BoosterDraftAI.java +++ b/src/main/java/forge/game/limited/BoosterDraftAI.java @@ -1,5 +1,13 @@ package forge.game.limited; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + import forge.AllZone; import forge.Card; import forge.CardList; @@ -11,118 +19,139 @@ import forge.card.spellability.Ability_Mana; import forge.deck.Deck; import forge.game.GameType; -import java.util.*; - /** - *

BoosterDraftAI class.

- * + *

+ * BoosterDraftAI class. + *

+ * * @author Forge * @version $Id$ */ public class BoosterDraftAI { - public BoosterDraft bd = null; - //once a deck has this number of creatures the computer randomly - //picks a card, so the final computer deck has 12-20 creatures - //minimum of creatures per deck - //private static final int nCreatures = 16; + + /** The bd. */ + private BoosterDraft bd = null; + // once a deck has this number of creatures the computer randomly + // picks a card, so the final computer deck has 12-20 creatures + // minimum of creatures per deck + // private static final int nCreatures = 16; /** - * Constant nDecks=7 + * Constant nDecks=7. */ - private static final int nDecks = 7; + private static final int N_DECKS = 7; - //holds all the cards for each of the computer's decks - private CardList[] deck = new CardList[nDecks]; - private String[][] deckColor = new String[nDecks][]; + // holds all the cards for each of the computer's decks + private final CardList[] deck = new CardList[BoosterDraftAI.N_DECKS]; + private final String[][] deckColor = new String[BoosterDraftAI.N_DECKS][]; /** - * Constant colorToLand + * Constant colorToLand. */ private static Map colorToLand = new TreeMap(); - //picks one Card from in_choose, removes that card, and returns the list - //returns the cards not picked + // picks one Card from in_choose, removes that card, and returns the list + // returns the cards not picked /** - *

choose.

- * - * @param chooseFrom a {@link forge.CardList} object. - * @param player a int. + *

+ * choose. + *

+ * + * @param chooseFrom + * a {@link forge.CardList} object. + * @param player + * a int. * @return a {@link forge.CardList} object. */ - public Card choose(final CardList chooseFrom, int player) { - //in_choose should ONLY be on the RIGHT side of any equal sign - //only 1 card should be removed from in_choose + public Card choose(final CardList chooseFrom, final int player) { + // in_choose should ONLY be on the RIGHT side of any equal sign + // only 1 card should be removed from in_choose - if (Constant.Runtime.DEV_MODE[0]) + if (Constant.Runtime.DEV_MODE[0]) { System.out.println("Player[" + player + "] pack: " + chooseFrom.toString()); + } - CardList wouldPick = new CardList(); + final CardList wouldPick = new CardList(); boolean hasPicked = false; Card pickedCard = new Card(); - CardList AIPlayables = chooseFrom.filter(new CardListFilter() { - public boolean addCard(Card c) { - if (c.getSVar("RemAIDeck").equals("True") || c.getSVar("RemRandomDeck").equals("True")) - return false; + final CardList aiPlayables = chooseFrom.filter(new CardListFilter() { + @Override + public boolean addCard(final Card c) { + if (c.getSVar("RemAIDeck").equals("True") || c.getSVar("RemRandomDeck").equals("True")) { + return false; + } return true; } }); - if (playerColors.get(player).Color1.equals("none") && playerColors.get(player).Color2.equals("none")) { + if (this.playerColors.get(player).Color1.equals("none") && this.playerColors.get(player).Color2.equals("none")) { // - CardList creatures = AIPlayables.getType("Creature").getColored(); - creatures.sort(bestCreature); - //for (int i=0; i 0) { pickedCard = creatures.get(creatures.size() - 1); - playerColors.get(player).Color1 = pickedCard.getColor().get(0).toStringArray().get(0); - if (Constant.Runtime.DEV_MODE[0]) - System.out.println("Player[" + player + "] Color1: " + playerColors.get(player).Color1); + this.playerColors.get(player).Color1 = pickedCard.getColor().get(0).toStringArray().get(0); + if (Constant.Runtime.DEV_MODE[0]) { + System.out.println("Player[" + player + "] Color1: " + this.playerColors.get(player).Color1); + } - playerColors.get(player).Mana1 = playerColors.get(player).ColorToMana(playerColors.get(player).Color1); - - //if the first pick has more than one color add the second as second color to draft + this.playerColors.get(player).Mana1 = this.playerColors.get(player).ColorToMana( + this.playerColors.get(player).Color1); + + // if the first pick has more than one color add the second as + // second color to draft if (pickedCard.getColor().get(0).toStringArray().size() > 1) { - playerColors.get(player).Color2 = pickedCard.getColor().get(0).toStringArray().get(1); - if (Constant.Runtime.DEV_MODE[0]) - System.out.println("Player[" + player + "] Color2: " + playerColors.get(player).Color2); + this.playerColors.get(player).Color2 = pickedCard.getColor().get(0).toStringArray().get(1); + if (Constant.Runtime.DEV_MODE[0]) { + System.out.println("Player[" + player + "] Color2: " + this.playerColors.get(player).Color2); + } + + this.playerColors.get(player).Mana2 = this.playerColors.get(player).ColorToMana( + this.playerColors.get(player).Color2); + } - playerColors.get(player).Mana2 = playerColors.get(player).ColorToMana(playerColors.get(player).Color2); - } - hasPicked = true; } - } else if (!playerColors.get(player).Color1.equals("none") && playerColors.get(player).Color2.equals("none")) { - CardList creatures = AIPlayables.getType("Creature").getColored(); - creatures.sort(bestCreature); - //for (int i=0; i 0) { pickedCard = creatures.get(creatures.size() - 1); - playerColors.get(player).Color2 = pickedCard.getColor().get(0).toStringArray().get(0); - if (Constant.Runtime.DEV_MODE[0]) - System.out.println("Player[" + player + "] Color2: " + playerColors.get(player).Color2); + this.playerColors.get(player).Color2 = pickedCard.getColor().get(0).toStringArray().get(0); + if (Constant.Runtime.DEV_MODE[0]) { + System.out.println("Player[" + player + "] Color2: " + this.playerColors.get(player).Color2); + } - playerColors.get(player).Mana2 = playerColors.get(player).ColorToMana(playerColors.get(player).Color2); + this.playerColors.get(player).Mana2 = this.playerColors.get(player).ColorToMana( + this.playerColors.get(player).Color2); hasPicked = true; } } else { CardList typeList; CardList colorList; - colorList = AIPlayables.getOnly2Colors(playerColors.get(player).Color1, playerColors.get(player).Color2); + colorList = aiPlayables.getOnly2Colors(this.playerColors.get(player).Color1, + this.playerColors.get(player).Color2); if (colorList.size() > 0) { typeList = colorList.getType("Creature"); if (typeList.size() > 0) { - typeList.sort(bestCreature); + typeList.sort(this.bestCreature); typeList.reverse(); wouldPick.add(typeList.get(0)); - if (typeList.size() > 1) + if (typeList.size() > 1) { wouldPick.add(typeList.get(1)); + } } typeList = colorList.getType("Instant"); @@ -139,9 +168,10 @@ public class BoosterDraftAI { } typeList = colorList.getType("Planeswalker"); - if (typeList.size() > 0) + if (typeList.size() > 0) { wouldPick.add(typeList.get(0)); - + } + typeList = colorList.getType("Artifact"); if (typeList.size() > 0) { CardListUtil.sortCMC(typeList); @@ -149,52 +179,50 @@ public class BoosterDraftAI { } } else { -/* if (!playerColors.get(player).Splash.equals("none")) { - // pick randomly from splash color - colorList = AIPlayables.getColor(playerColors.get(player).Splash); - if (colorList.size() > 0) { - Random r = new Random(); - list.add(colorList.get(r.nextInt(colorList.size()))); - } - } - else { - // pick splash color - ArrayList otherColors = new ArrayList(); - for (int i=0; i<5; i++) - otherColors.add(Constant.Color.onlyColors[i]); - otherColors.remove(playerColors.get(player).Color1); - otherColors.remove(playerColors.get(player).Color2); - - colorList = new CardList(); - for (int i=0; i 0) { - Random r = new Random(); - pickedCard = colorList.get(r.nextInt(colorList.size())); - playerColors.get(player).Splash = pickedCard.getColor().get(0).toStringArray().get(0); - System.out.println("Player["+player+"] Splash: "+playerColors.get(player).Splash); - playerColors.get(player).ManaS = playerColors.get(player).ColorToMana(playerColors.get(player).Splash); - hasPicked = true; - } - } -*/ - typeList = AIPlayables.getType("Land"); + /* + * if (!playerColors.get(player).Splash.equals("none")) { // + * pick randomly from splash color colorList = + * AIPlayables.getColor(playerColors.get(player).Splash); if + * (colorList.size() > 0) { Random r = new Random(); + * list.add(colorList.get(r.nextInt(colorList.size()))); } } + * else { // pick splash color ArrayList otherColors = + * new ArrayList(); for (int i=0; i<5; i++) + * otherColors.add(Constant.Color.onlyColors[i]); + * otherColors.remove(playerColors.get(player).Color1); + * otherColors.remove(playerColors.get(player).Color2); + * + * colorList = new CardList(); for (int i=0; + * i 0) { Random r = new Random(); + * pickedCard = colorList.get(r.nextInt(colorList.size())); + * playerColors.get(player).Splash = + * pickedCard.getColor().get(0).toStringArray().get(0); + * System.out + * .println("Player["+player+"] Splash: "+playerColors. + * get(player).Splash); playerColors.get(player).ManaS = + * playerColors + * .get(player).ColorToMana(playerColors.get(player).Splash); + * hasPicked = true; } } + */ + typeList = aiPlayables.getType("Land"); if (typeList.size() > 0) { for (int i = 0; i < typeList.size(); i++) { - ArrayList maList = typeList.get(i).getManaAbility(); + final ArrayList maList = typeList.get(i).getManaAbility(); for (int j = 0; j < maList.size(); j++) { - if (maList.get(j).canProduce(playerColors.get(player).Mana1) || maList.get(j).canProduce(playerColors.get(player).Mana2)) //|| maList.get(j).canProduce(playerColors.get(player).ManaS)) + if (maList.get(j).canProduce(this.playerColors.get(player).Mana1) + || maList.get(j).canProduce(this.playerColors.get(player).Mana2)) { wouldPick.add(typeList.get(i)); + } } } } } - } if (!hasPicked) { - Random r = new Random(); + final Random r = new Random(); if (wouldPick.size() > 0) { wouldPick.shuffle(); @@ -203,251 +231,281 @@ public class BoosterDraftAI { chooseFrom.shuffle(); pickedCard = chooseFrom.get(r.nextInt(chooseFrom.size())); } - + hasPicked = true; } if (hasPicked) { chooseFrom.remove(pickedCard); - deck[player].add(pickedCard); + this.deck[player].add(pickedCard); - if (Constant.Runtime.DEV_MODE[0]) - System.out.println("Player[" + player + "] picked " + pickedCard.getName() + " (" + pickedCard.getManaCost() + ") " + pickedCard.getType().toString() + "\n"); + if (Constant.Runtime.DEV_MODE[0]) { + System.out.println("Player[" + player + "] picked " + pickedCard.getName() + " (" + + pickedCard.getManaCost() + ") " + pickedCard.getType().toString() + "\n"); + } } return pickedCard; } -/* - I get some wierd error when I have this method, I don't know whats wrong - - private void checkDeckList(CardList[] deck) - { - if(deck.length != nDecks) - throw new RuntimeException("BoosterDraftAI : checkDeckList() error, deck list size is not 7 - " +deck.length); - - for(int i = 0; i < nDecks; i++) - { - if(deck[i].size() != 22) - { - throw new RuntimeException("BoosterDraftAI : checkDeckList() error, deck list size is not 22 - " +deck[i].size() +" - " +deck.toString()); - } - if(countCreatures(deck[i]) < nCreatures) - throw new RuntimeException("BoosterDraftAI : checkDeckList() error, deck needs more creatures - " +countCreatures(deck[i])); - - for(int inner = 0; inner < 22; inner++) - if(! CardUtil.getColors(deck[i].getCard(inner)).contains(deckColor[i][0]) && - ! CardUtil.getColors(deck[i].getCard(inner)).contains(deckColor[i][1])) - throw new RuntimeException("BoosterDraftAI : checkDeckList() error, deck has different card colors"); - }//for - }//checkDeckList() -*/ - - //private int countCreatures(CardList list) {return list.getType("Creature").size();} - - /** - *

testColors.

- * - * @param n an array of int. + /* + * I get some wierd error when I have this method, I don't know whats wrong + * + * private void checkDeckList(CardList[] deck) { if(deck.length != nDecks) + * throw new RuntimeException( + * "BoosterDraftAI : checkDeckList() error, deck list size is not 7 - " + * +deck.length); + * + * for(int i = 0; i < nDecks; i++) { if(deck[i].size() != 22) { throw new + * RuntimeException + * ("BoosterDraftAI : checkDeckList() error, deck list size is not 22 - " + * +deck[i].size() +" - " +deck.toString()); } if(countCreatures(deck[i]) < + * nCreatures) throw new RuntimeException( + * "BoosterDraftAI : checkDeckList() error, deck needs more creatures - " + * +countCreatures(deck[i])); + * + * for(int inner = 0; inner < 22; inner++) if(! + * CardUtil.getColors(deck[i].getCard(inner)).contains(deckColor[i][0]) && ! + * CardUtil.getColors(deck[i].getCard(inner)).contains(deckColor[i][1])) + * throw new RuntimeException( + * "BoosterDraftAI : checkDeckList() error, deck has different card colors" + * ); }//for }//checkDeckList() */ - private void testColors(int[] n) { - if (n.length != nDecks) - throw new RuntimeException("BoosterDraftAI : testColors error, numbers array length does not equal 7"); - Set set = new TreeSet(); - for (int i = 0; i < nDecks; i++) - set.add(Integer.valueOf(n[i])); - - if (set.size() != nDecks) - throw new RuntimeException("BoosterDraftAI : testColors error, numbers not unique"); - - for (int i = 0; i < nDecks; i++) - if (n[i] < 0 || deckColorChoices.length <= n[i]) - throw new RuntimeException("BoosterDraftAI : testColors error, index out of range - " + n[i]); - }//testColors() + // private int countCreatures(CardList list) {return + // list.getType("Creature").size();} /** - *

getDecks.

- * + *

+ * testColors. + *

+ * + * @param n + * an array of int. + */ + private void testColors(final int[] n) { + if (n.length != BoosterDraftAI.N_DECKS) { + throw new RuntimeException("BoosterDraftAI : testColors error, numbers array length does not equal 7"); + } + + final Set set = new TreeSet(); + for (int i = 0; i < BoosterDraftAI.N_DECKS; i++) { + set.add(Integer.valueOf(n[i])); + } + + if (set.size() != BoosterDraftAI.N_DECKS) { + throw new RuntimeException("BoosterDraftAI : testColors error, numbers not unique"); + } + + for (int i = 0; i < BoosterDraftAI.N_DECKS; i++) { + if ((n[i] < 0) || (this.deckColorChoices.length <= n[i])) { + throw new RuntimeException("BoosterDraftAI : testColors error, index out of range - " + n[i]); + } + } + } // testColors() + + /** + *

+ * getDecks. + *

+ * * @return an array of {@link forge.deck.Deck} objects. */ public Deck[] getDecks() { - //check CardList[] deck for errors - //checkDeckList(deck); + // check CardList[] deck for errors + // checkDeckList(deck); - Deck[] out = new Deck[deck.length]; + final Deck[] out = new Deck[this.deck.length]; - for (int i = 0; i < deck.length; i++) { - //addLand(deck[i], deckColor[i]); - //out[i] = getDeck(deck[i]); - if (Constant.Runtime.DEV_MODE[0]) + for (int i = 0; i < this.deck.length; i++) { + // addLand(deck[i], deckColor[i]); + // out[i] = getDeck(deck[i]); + if (Constant.Runtime.DEV_MODE[0]) { System.out.println("Deck[" + i + "]"); + } - out[i] = buildDeck(deck[i], playerColors.get(i)); + out[i] = this.buildDeck(this.deck[i], this.playerColors.get(i)); } return out; - }//getDecks() + } // getDecks() /** - *

buildDeck.

- * - * @param dList a {@link forge.CardList} object. - * @param pClrs a {@link forge.game.limited.DeckColors} object. + *

+ * buildDeck. + *

+ * + * @param dList + * a {@link forge.CardList} object. + * @param pClrs + * a {@link forge.game.limited.DeckColors} object. * @return a {@link forge.deck.Deck} object. */ - private Deck buildDeck(CardList dList, DeckColors pClrs) { - Deck out = new Deck(GameType.Draft); - CardList outList = new CardList(); + private Deck buildDeck(final CardList dList, final DeckColors pClrs) { + final Deck out = new Deck(GameType.Draft); + final CardList outList = new CardList(); int cardsNeeded = 22; int landsNeeded = 18; - CardList AIPlayables = dList.filter(new CardListFilter() { - public boolean addCard(Card c) { + final CardList aiPlayables = dList.filter(new CardListFilter() { + @Override + public boolean addCard(final Card c) { return !(c.getSVar("RemAIDeck").equals("True")); } }); - for (int i = 0; i < AIPlayables.size(); i++) - dList.remove(AIPlayables.get(i)); + for (int i = 0; i < aiPlayables.size(); i++) { + dList.remove(aiPlayables.get(i)); + } - CardList creatures = AIPlayables.getType("Creature").getOnly2Colors(pClrs.Color1, pClrs.Color2); + final CardList creatures = aiPlayables.getType("Creature").getOnly2Colors(pClrs.Color1, pClrs.Color2); int nCreatures = 15; - creatures.sort(bestCreature); + creatures.sort(this.bestCreature); creatures.reverse(); int i = 0; - while (nCreatures > 0 && i < creatures.size()) { - Card c = creatures.get(i); + while ((nCreatures > 0) && (i < creatures.size())) { + final Card c = creatures.get(i); outList.add(c); cardsNeeded--; nCreatures--; - AIPlayables.remove(c); + aiPlayables.remove(c); - if (Constant.Runtime.DEV_MODE[0]) + if (Constant.Runtime.DEV_MODE[0]) { System.out.println("Creature[" + i + "]:" + c.getName() + " (" + c.getManaCost() + ")"); + } i++; } - CardList otherCreatures = AIPlayables.getType("Creature"); - while (nCreatures > 1 && otherCreatures.size() > 1) { - Card c = otherCreatures.get(MyRandom.getRandom().nextInt(otherCreatures.size() - 1)); + CardList otherCreatures = aiPlayables.getType("Creature"); + while ((nCreatures > 1) && (otherCreatures.size() > 1)) { + final Card c = otherCreatures.get(MyRandom.getRandom().nextInt(otherCreatures.size() - 1)); outList.add(c); cardsNeeded--; nCreatures--; - AIPlayables.remove(c); + aiPlayables.remove(c); - otherCreatures = AIPlayables.getType("Creature"); + otherCreatures = aiPlayables.getType("Creature"); - if (Constant.Runtime.DEV_MODE[0]) + if (Constant.Runtime.DEV_MODE[0]) { System.out.println("AddCreature: " + c.getName() + " (" + c.getManaCost() + ")"); + } } - CardList others = AIPlayables.getNotType("Creature").getNotType("Land").getOnly2Colors(pClrs.Color1, pClrs.Color2); + CardList others = aiPlayables.getNotType("Creature").getNotType("Land") + .getOnly2Colors(pClrs.Color1, pClrs.Color2); int ii = 0; - while (cardsNeeded > 0 && others.size() > 1) { - Card c = others.get(MyRandom.getRandom().nextInt(others.size() - 1)); + while ((cardsNeeded > 0) && (others.size() > 1)) { + final Card c = others.get(MyRandom.getRandom().nextInt(others.size() - 1)); - //out.addMain(c.getName()); + // out.addMain(c.getName()); outList.add(c); cardsNeeded--; - AIPlayables.remove(c); + aiPlayables.remove(c); - others = AIPlayables.getNotType("Creature").getNotType("Land").getOnly2Colors(pClrs.Color1, pClrs.Color2); + others = aiPlayables.getNotType("Creature").getNotType("Land").getOnly2Colors(pClrs.Color1, pClrs.Color2); - if (Constant.Runtime.DEV_MODE[0]) + if (Constant.Runtime.DEV_MODE[0]) { System.out.println("Others[" + ii++ + "]:" + c.getName() + " (" + c.getManaCost() + ")"); + } } ii = 0; - CardList z = AIPlayables.getNotType("Land"); - while (cardsNeeded > 0 && z.size() > 1) { + CardList z = aiPlayables.getNotType("Land"); + while ((cardsNeeded > 0) && (z.size() > 1)) { - //if (z.size() < 1) - // throw new RuntimeException("BoosterDraftAI : buildDeck() error, deck does not have enough non-lands"); - Card c = z.get(MyRandom.getRandom().nextInt(z.size() - 1)); + // if (z.size() < 1) + // throw new + // RuntimeException("BoosterDraftAI : buildDeck() error, deck does not have enough non-lands"); + final Card c = z.get(MyRandom.getRandom().nextInt(z.size() - 1)); - //out.addMain(c.getName()); + // out.addMain(c.getName()); outList.add(c); cardsNeeded--; - AIPlayables.remove(c); + aiPlayables.remove(c); - z = AIPlayables.getNotType("Land"); + z = aiPlayables.getNotType("Land"); - if (Constant.Runtime.DEV_MODE[0]) + if (Constant.Runtime.DEV_MODE[0]) { System.out.println("NonLands[" + ii++ + "]:" + c.getName() + "(" + c.getManaCost() + ")"); + } } - CardList lands = AIPlayables.getType("Land"); - while (landsNeeded > 0 && lands.size() > 0) { - Card c = lands.get(0); + CardList lands = aiPlayables.getType("Land"); + while ((landsNeeded > 0) && (lands.size() > 0)) { + final Card c = lands.get(0); outList.add(c); landsNeeded--; - AIPlayables.remove(c); + aiPlayables.remove(c); - lands = AIPlayables.getType("Land"); + lands = aiPlayables.getType("Land"); - if (Constant.Runtime.DEV_MODE[0]) + if (Constant.Runtime.DEV_MODE[0]) { System.out.println("Land:" + c.getName()); + } } - if (landsNeeded > 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)}; + if (landsNeeded > 0) { + // attempt to optimize basic land counts according + // to color representation + + final 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? for (i = 0; i < outList.size(); i++) { - String mc = outList.get(i).getManaCost(); + final String mc = outList.get(i).getManaCost(); // count each mana symbol in the mana cost for (int j = 0; j < mc.length(); j++) { - char c = mc.charAt(j); + final char c = mc.charAt(j); - if (c == 'W') - ClrCnts[0].Count++; - else if (c == 'U') - ClrCnts[1].Count++; - else if (c == 'B') - ClrCnts[2].Count++; - else if (c == 'R') - ClrCnts[3].Count++; - else if (c == 'G') - ClrCnts[4].Count++; + if (c == 'W') { + clrCnts[0].setCount(clrCnts[0].getCount() + 1); + } else if (c == 'U') { + clrCnts[1].setCount(clrCnts[1].getCount() + 1); + } else if (c == 'B') { + clrCnts[2].setCount(clrCnts[2].getCount() + 1); + } else if (c == 'R') { + clrCnts[3].setCount(clrCnts[3].getCount() + 1); + } else if (c == 'G') { + clrCnts[4].setCount(clrCnts[4].getCount() + 1); + } } } // total of all ClrCnts int totalColor = 0; for (i = 0; i < 5; i++) { - totalColor += ClrCnts[i].Count; - //tmpDeck += ClrCnts[i].Color + ":" + ClrCnts[i].Count + "\n"; + totalColor += clrCnts[i].getCount(); + // tmpDeck += ClrCnts[i].Color + ":" + ClrCnts[i].Count + "\n"; } - //tmpDeck += "totalColor:" + totalColor + "\n"; + // tmpDeck += "totalColor:" + totalColor + "\n"; for (i = 0; i < 5; i++) { - if (ClrCnts[i].Count > 0) { // calculate number of lands for each color - float p = (float) ClrCnts[i].Count / (float) totalColor; - int nLand = (int) ((float) landsNeeded * p) + 1; - //tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n"; - if (Constant.Runtime.DEV_MODE[0]) - System.out.println("Basics[" + ClrCnts[i].Color + "]:" + nLand); + if (clrCnts[i].getCount() > 0) { // calculate number of lands for + // each color + final float p = (float) clrCnts[i].getCount() / (float) totalColor; + final int nLand = (int) (landsNeeded * p) + 1; + // tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + + // "\n"; + if (Constant.Runtime.DEV_MODE[0]) { + System.out.println("Basics[" + clrCnts[i].getColor() + "]:" + nLand); + } - // just to prevent a null exception by the deck size fixing code - //CardCounts.put(ClrCnts[i].Color, nLand); + // 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++) { - Card c = AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer()); - c.setCurSetCode(BoosterDraft.LandSetCode[0]); + final Card c = AllZone.getCardFactory().getCard(clrCnts[i].getColor(), AllZone.getComputerPlayer()); + c.setCurSetCode(BoosterDraft.LAND_SET_CODE[0]); outList.add(c); landsNeeded--; } @@ -455,202 +513,223 @@ public class BoosterDraftAI { } int n = 0; while (landsNeeded > 0) { - if (ClrCnts[n].Count > 0) { - Card c = AllZone.getCardFactory().getCard(ClrCnts[n].Color, AllZone.getComputerPlayer()); - c.setCurSetCode(BoosterDraft.LandSetCode[0]); + if (clrCnts[n].getCount() > 0) { + final Card c = AllZone.getCardFactory().getCard(clrCnts[n].getColor(), AllZone.getComputerPlayer()); + c.setCurSetCode(BoosterDraft.LAND_SET_CODE[0]); outList.add(c); landsNeeded--; - if (Constant.Runtime.DEV_MODE[0]) + if (Constant.Runtime.DEV_MODE[0]) { System.out.println("AddBasics: " + c.getName()); + } } - if (++n > 4) + if (++n > 4) { n = 0; + } } } while (outList.size() > 40) { - Card c = outList.get(MyRandom.getRandom().nextInt(outList.size() - 1)); + final Card c = outList.get(MyRandom.getRandom().nextInt(outList.size() - 1)); outList.remove(c); - AIPlayables.add(c); + aiPlayables.add(c); } while (outList.size() < 40) { - Card c = AIPlayables.get(MyRandom.getRandom().nextInt(AIPlayables.size() - 1)); + final Card c = aiPlayables.get(MyRandom.getRandom().nextInt(aiPlayables.size() - 1)); outList.add(c); - AIPlayables.remove(c); + aiPlayables.remove(c); } if (outList.size() == 40) { - for (i = 0; i < outList.size(); i++) + for (i = 0; i < outList.size(); i++) { out.addMain(outList.get(i).getName() + "|" + outList.get(i).getCurSetCode()); + } - for (i = 0; i < AIPlayables.size(); i++) - out.addSideboard(AIPlayables.get(i).getName() + "|" + AIPlayables.get(i).getCurSetCode()); + for (i = 0; i < aiPlayables.size(); i++) { + out.addSideboard(aiPlayables.get(i).getName() + "|" + aiPlayables.get(i).getCurSetCode()); + } - for (i = 0; i < dList.size(); i++) + for (i = 0; i < dList.size(); i++) { out.addSideboard(dList.get(i).getName() + "|" + dList.get(i).getCurSetCode()); - } else + } + } else { throw new RuntimeException("BoosterDraftAI : buildDeck() error, decksize not 40"); + } return out; } -/* private Deck getDeck(CardList list) - { - Deck out = new Deck(GameType.Draft); - for(int i = 0; i < list.size(); i++) - out.addMain(list.get(i).getName()); + /* + * private Deck getDeck(CardList list) { Deck out = new + * Deck(GameType.Draft); for(int i = 0; i < list.size(); i++) + * out.addMain(list.get(i).getName()); + * + * return out; }//getDeck() + * + * //add Land to list argument private void addLand(CardList list, String[] + * color) { Card land; for(int i = 0; i < 9; i++) { land = + * AllZone.getCardFactory().getCard(colorToLand.get(color[0]).toString(), + * AllZone.getComputerPlayer()); + * + * land.setCurSetCode(land.getMostRecentSet()); + * land.setImageFilename(CardUtil.buildFilename(land)); + * + * list.add(land); + * + * land = + * AllZone.getCardFactory().getCard(colorToLand.get(color[1]).toString(), + * AllZone.getComputerPlayer()); + * + * land.setCurSetCode(land.getMostRecentSet()); + * land.setImageFilename(CardUtil.buildFilename(land)); + * + * list.add(land); } + * + * //if(list.getType("Land").size() != 18) //throw new RuntimeException( + * "BoosterDraftAI : addLand() error, deck does not have 18 lands - " + * +list.getType("Land").size()); + * + * //if(list.size() != 40) //throw new + * RuntimeException("BoosterDraftAI : addLand() error, deck is not 40 cards - " + * +list.size()); }//addLand() + */ - return out; - }//getDeck() - - //add Land to list argument - private void addLand(CardList list, String[] color) - { - Card land; - for(int i = 0; i < 9; i++) - { - land = AllZone.getCardFactory().getCard(colorToLand.get(color[0]).toString(), AllZone.getComputerPlayer()); - - land.setCurSetCode(land.getMostRecentSet()); - land.setImageFilename(CardUtil.buildFilename(land)); - - list.add(land); - - land = AllZone.getCardFactory().getCard(colorToLand.get(color[1]).toString(), AllZone.getComputerPlayer()); - - land.setCurSetCode(land.getMostRecentSet()); - land.setImageFilename(CardUtil.buildFilename(land)); - - list.add(land); - } - - //if(list.getType("Land").size() != 18) - //throw new RuntimeException("BoosterDraftAI : addLand() error, deck does not have 18 lands - " +list.getType("Land").size()); - - //if(list.size() != 40) - //throw new RuntimeException("BoosterDraftAI : addLand() error, deck is not 40 cards - " +list.size()); - }//addLand() -*/ - - //returns 7 different ints, within the range of 0-9 + // returns 7 different ints, within the range of 0-9 /** - *

getDeckColors.

- * + *

+ * getDeckColors. + *

+ * * @return an array of int. */ private int[] getDeckColors() { - int[] out = new int[nDecks]; + final int[] out = new int[BoosterDraftAI.N_DECKS]; int start = MyRandom.getRandom().nextInt(10); for (int i = 0; i < out.length; i++) { - //% to get an index between 0 and deckColorChoices.length - out[i] = start % deckColorChoices.length; + // % to get an index between 0 and deckColorChoices.length + out[i] = start % this.deckColorChoices.length; start++; } - testColors(out); + this.testColors(out); return out; - }//getDeckColors() + } // getDeckColors() /** - *

Constructor for BoosterDraftAI.

+ *

+ * Constructor for BoosterDraftAI. + *

*/ public BoosterDraftAI() { - //choose colors for decks - int[] n = getDeckColors(); + // choose colors for decks + final int[] n = this.getDeckColors(); for (int i = 0; i < n.length; i++) { - deckColor[i] = deckColorChoices[n[i]]; + this.deckColor[i] = this.deckColorChoices[n[i]]; } - //initilize color map - colorToLand.put(Constant.Color.BLACK, "Swamp"); - colorToLand.put(Constant.Color.BLUE, "Island"); - colorToLand.put(Constant.Color.GREEN, "Forest"); - colorToLand.put(Constant.Color.RED, "Mountain"); - colorToLand.put(Constant.Color.WHITE, "Plains"); + // initilize color map + BoosterDraftAI.colorToLand.put(Constant.Color.BLACK, "Swamp"); + BoosterDraftAI.colorToLand.put(Constant.Color.BLUE, "Island"); + BoosterDraftAI.colorToLand.put(Constant.Color.GREEN, "Forest"); + BoosterDraftAI.colorToLand.put(Constant.Color.RED, "Mountain"); + BoosterDraftAI.colorToLand.put(Constant.Color.WHITE, "Plains"); - //initilize deck array and playerColors list - for (int i = 0; i < deck.length; i++) { - deck[i] = new CardList(); - playerColors.add(new DeckColors()); + // initilize deck array and playerColors list + for (int i = 0; i < this.deck.length; i++) { + this.deck[i] = new CardList(); + this.playerColors.add(new DeckColors()); } - }//BoosterDraftAI() + } // BoosterDraftAI() + /** + * @return the bd + */ + public BoosterDraft getBd() { + return bd; + } - private ArrayList playerColors = new ArrayList(); + /** + * @param bd the bd to set + */ + public void setBd(BoosterDraft bd) { + this.bd = bd; // TODO: Add 0 to parameter's name. + } - //all 10 two color combinations - private String[][] deckColorChoices = { - {Constant.Color.BLACK, Constant.Color.BLUE}, {Constant.Color.BLACK, Constant.Color.GREEN}, - {Constant.Color.BLACK, Constant.Color.RED}, {Constant.Color.BLACK, Constant.Color.WHITE}, + private final ArrayList playerColors = new ArrayList(); - {Constant.Color.BLUE, Constant.Color.GREEN}, {Constant.Color.BLUE, Constant.Color.RED}, - {Constant.Color.BLUE, Constant.Color.WHITE}, + // all 10 two color combinations + private final String[][] deckColorChoices = { { Constant.Color.BLACK, Constant.Color.BLUE }, + { Constant.Color.BLACK, Constant.Color.GREEN }, { Constant.Color.BLACK, Constant.Color.RED }, + { Constant.Color.BLACK, Constant.Color.WHITE }, - {Constant.Color.GREEN, Constant.Color.RED}, {Constant.Color.GREEN, Constant.Color.WHITE}, + { Constant.Color.BLUE, Constant.Color.GREEN }, { Constant.Color.BLUE, Constant.Color.RED }, + { Constant.Color.BLUE, Constant.Color.WHITE }, - {Constant.Color.RED, Constant.Color.WHITE} - }; + { Constant.Color.GREEN, Constant.Color.RED }, { Constant.Color.GREEN, Constant.Color.WHITE }, - private Comparator bestCreature = new Comparator() { - public int compare(Card a, Card b) { + { Constant.Color.RED, Constant.Color.WHITE } }; + + private final Comparator bestCreature = new Comparator() { + @Override + public int compare(final Card a, final Card b) { int cmcA = a.getCMC(); - if (cmcA == 0) + if (cmcA == 0) { cmcA = 1; + } cmcA *= 10; int cmcB = b.getCMC(); - if (cmcB == 0) + if (cmcB == 0) { cmcB = 1; + } cmcB *= 10; - int attA = a.getBaseAttack() * 10; - int attB = b.getBaseAttack() * 10; + final int attA = a.getBaseAttack() * 10; + final int attB = b.getBaseAttack() * 10; - int defA = a.getBaseDefense() * 10; - int defB = b.getBaseDefense() * 10; + final int defA = a.getBaseDefense() * 10; + final int defB = b.getBaseDefense() * 10; - int keyA = a.getKeyword().size() * 10; - int keyB = b.getKeyword().size() * 10; + final int keyA = a.getKeyword().size() * 10; + final int keyB = b.getKeyword().size() * 10; - int abA = a.getSpellAbility().length * 10; - int abB = b.getSpellAbility().length * 10; + final int abA = a.getSpellAbility().length * 10; + final int abB = b.getSpellAbility().length * 10; + + final int trgA = a.getTriggers().size() * 10; + final int trgB = b.getTriggers().size() * 10; - int trgA = a.getTriggers().size() * 10; - int trgB = b.getTriggers().size() * 10; - int rarA = 0; int rarB = 0; - - if (a.getCurSetRarity().equals("Common")) - rarA = 1; - else if (a.getCurSetRarity().equals("Uncommon")) - rarA = 2; - else if (a.getCurSetRarity().equals("Rare")) - rarA = 4; - else if (a.getCurSetRarity().equals("Mythic")) - rarA = 8; - - if (b.getCurSetRarity().equals("Common")) - rarB = 1; - else if (b.getCurSetRarity().equals("Uncommon")) - rarB = 2; - else if (b.getCurSetRarity().equals("Rare")) - rarB = 4; - else if (b.getCurSetRarity().equals("Mythic")) - rarB = 8; - int scoreA = ((attA + defA) / cmcA) + keyA + abA + trgA + rarA; - int scoreB = ((attB + defB) / cmcB) + keyB + abB + trgB + rarB; + if (a.getCurSetRarity().equals("Common")) { + rarA = 1; + } else if (a.getCurSetRarity().equals("Uncommon")) { + rarA = 2; + } else if (a.getCurSetRarity().equals("Rare")) { + rarA = 4; + } else if (a.getCurSetRarity().equals("Mythic")) { + rarA = 8; + } + + if (b.getCurSetRarity().equals("Common")) { + rarB = 1; + } else if (b.getCurSetRarity().equals("Uncommon")) { + rarB = 2; + } else if (b.getCurSetRarity().equals("Rare")) { + rarB = 4; + } else if (b.getCurSetRarity().equals("Mythic")) { + rarB = 8; + } + + final int scoreA = ((attA + defA) / cmcA) + keyA + abA + trgA + rarA; + final int scoreB = ((attB + defB) / cmcB) + keyB + abB + trgB + rarB; return scoreA - scoreB; } }; -}//BoosterDraftAI() - - - +} // BoosterDraftAI() diff --git a/src/main/java/forge/game/limited/BoosterDraft_1.java b/src/main/java/forge/game/limited/BoosterDraft_1.java index f99da238aee..7268637ffaa 100644 --- a/src/main/java/forge/game/limited/BoosterDraft_1.java +++ b/src/main/java/forge/game/limited/BoosterDraft_1.java @@ -1,5 +1,19 @@ package forge.game.limited; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.TreeMap; + +import javax.swing.JOptionPane; + +import net.slightlymagic.braids.util.lambda.Lambda1; +import net.slightlymagic.maxmtg.Closure1; + +import org.apache.commons.lang3.ArrayUtils; + import forge.AllZone; import forge.Card; import forge.CardList; @@ -18,156 +32,154 @@ import forge.item.CardPrinted; import forge.item.ItemPool; import forge.item.ItemPoolView; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.TreeMap; - -import javax.swing.JOptionPane; - -import org.apache.commons.lang3.ArrayUtils; - -import net.slightlymagic.braids.util.lambda.Lambda1; -import net.slightlymagic.maxmtg.Closure1; - /** * * TODO Write javadoc for this type. - * + * */ public final class BoosterDraft_1 implements BoosterDraft { private final BoosterDraftAI draftAI = new BoosterDraftAI(); - private static final int nPlayers = 8; + private static final int N_PLAYERS = 8; private int nextBoosterGroup = 0; private int currentBoosterSize = 0; private int currentBoosterPick = 0; - private List> pack; //size 8 - - public Map draftPicks = new TreeMap(); - private CardPoolLimitation draftFormat; + private List> pack; // size 8 - private ArrayList, BoosterGenerator>> packs = new ArrayList, BoosterGenerator>>(); + /** The draft picks. */ + private Map draftPicks = new TreeMap(); + private final CardPoolLimitation draftFormat; + + private final ArrayList, BoosterGenerator>> packs = new ArrayList, BoosterGenerator>>(); /** - *

Constructor for BoosterDraft_1.

- * - * @param draftType a {@link java.lang.String} object. + *

+ * Constructor for BoosterDraft_1. + *

+ * + * @param draftType + * a {@link java.lang.String} object. */ - public BoosterDraft_1(CardPoolLimitation draftType) { - draftAI.bd = this; - draftFormat = draftType; + public BoosterDraft_1(final CardPoolLimitation draftType) { + this.draftAI.setBd(this); + this.draftFormat = draftType; switch (draftType) { - case Full: // Draft from all cards in Forge - BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards()); - Closure1, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull); - for (int i = 0; i < 3; i++) { - packs.add(picker); + case Full: // Draft from all cards in Forge + final BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards()); + final Closure1, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull); + for (int i = 0; i < 3; i++) { + this.packs.add(picker); + } + + BoosterDraft.LAND_SET_CODE[0] = CardDb.instance().getCard("Plains").getSet(); + break; + + case Block: // Draft from cards by block or set + final List blocks = SetUtils.getBlocks(); + + final Object o = GuiUtils.getChoice("Choose Block", blocks.toArray()); + final CardBlock block = (CardBlock) o; + + final CardSet[] cardSets = block.getSets(); + final String[] sets = new String[cardSets.length]; + for (int k = cardSets.length - 1; k >= 0; --k) { + sets[k] = cardSets[k].getCode(); + } + + final int nPacks = block.getCntBoostersDraft(); + + final ArrayList setCombos = new ArrayList(); + if (sets.length >= 2) { + setCombos.add(String.format("%s/%s/%s", sets[0], sets[0], sets[0])); + setCombos.add(String.format("%s/%s/%s", sets[1], sets[0], sets[0])); + setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[0])); + setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[1])); + } + if (sets.length >= 3) { + setCombos.add(String.format("%s/%s/%s", sets[2], sets[1], sets[0])); + setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[0])); + setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[1])); + setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[2])); + } + + if (sets.length > 1) { + final Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray()); + final String[] pp = p.toString().split("/"); + for (int i = 0; i < nPacks; i++) { + final BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i])); + this.packs.add(BoosterGenerator.getSimplePicker(bpMulti)); } - - LandSetCode[0] = CardDb.instance().getCard("Plains").getSet(); - break; - - case Block: // Draft from cards by block or set - List blocks = SetUtils.getBlocks(); - - Object o = GuiUtils.getChoice("Choose Block", blocks.toArray()); - CardBlock block = (CardBlock) o; - - CardSet[] cardSets = block.getSets(); - String[] sets = new String[cardSets.length]; - for (int k = cardSets.length - 1; k >= 0 ; --k) { sets[k] = cardSets[k].getCode();} - - int nPacks = block.getCntBoostersDraft(); - - ArrayList setCombos = new ArrayList(); - if (sets.length >= 2) { - setCombos.add(String.format("%s/%s/%s", sets[0], sets[0], sets[0])); - setCombos.add(String.format("%s/%s/%s", sets[1], sets[0], sets[0])); - setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[0])); - setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[1])); + + } else { + final BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0])); + final Closure1, BoosterGenerator> pick1 = BoosterGenerator.getSimplePicker(bpOne); + for (int i = 0; i < nPacks; i++) { + this.packs.add(pick1); } - if (sets.length >= 3) { - setCombos.add(String.format("%s/%s/%s", sets[2], sets[1], sets[0])); - setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[0])); - setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[1])); - setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[2])); - } - - - if (sets.length > 1) { - Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray()); - String[] pp = p.toString().split("/"); - for (int i = 0; i < nPacks; i++) { - BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i])); - packs.add(BoosterGenerator.getSimplePicker(bpMulti)); - } - - } else { - BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0])); - Closure1, BoosterGenerator> pick1 = BoosterGenerator.getSimplePicker(bpOne); - for (int i = 0; i < nPacks; i++) { packs.add(pick1); } - } - - LandSetCode[0] = block.getLandSet().getCode(); - break; - - case Custom: - List myDrafts = loadCustomDrafts("res/draft/", ".draft"); - - if (myDrafts.size() < 1) { - JOptionPane.showMessageDialog(null, "No custom draft files found.", "", JOptionPane.INFORMATION_MESSAGE); - } else { - CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Draft", myDrafts.toArray()); - setupCustomDraft(draft); - } - break; - default: - throw new NoSuchElementException("Draft for mode " + draftType + " has not been set up!"); + } + + BoosterDraft.LAND_SET_CODE[0] = block.getLandSet().getCode(); + break; + + case Custom: + final List myDrafts = this.loadCustomDrafts("res/draft/", ".draft"); + + if (myDrafts.size() < 1) { + JOptionPane + .showMessageDialog(null, "No custom draft files found.", "", JOptionPane.INFORMATION_MESSAGE); + } else { + final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Draft", + myDrafts.toArray()); + this.setupCustomDraft(draft); + } + break; + default: + throw new NoSuchElementException("Draft for mode " + draftType + " has not been set up!"); } - pack = get8BoosterPack(); + this.pack = this.get8BoosterPack(); } - private void setupCustomDraft(final CustomLimited draft) - { - DeckManager dio = AllZone.getDeckManager(); - Deck dPool = dio.getDeck(draft.DeckFile); + private void setupCustomDraft(final CustomLimited draft) { + final DeckManager dio = AllZone.getDeckManager(); + final Deck dPool = dio.getDeck(draft.DeckFile); if (dPool == null) { throw new RuntimeException("BoosterGenerator : deck not found - " + draft.DeckFile); } - BoosterGenerator bpCustom = new BoosterGenerator(dPool); - Lambda1, BoosterGenerator> fnPick = new Lambda1, BoosterGenerator>() { - @Override public List apply(BoosterGenerator pack) { - if ( draft.IgnoreRarity ) { + final BoosterGenerator bpCustom = new BoosterGenerator(dPool); + final Lambda1, BoosterGenerator> fnPick = new Lambda1, BoosterGenerator>() { + @Override + public List apply(final BoosterGenerator pack) { + if (draft.IgnoreRarity) { if (!draft.Singleton) { - return pack.getBoosterPack(0, 0, 0, 0, 0, 0, 0, draft.NumCards, 0); + return pack.getBoosterPack(0, 0, 0, 0, 0, 0, 0, draft.NumCards, 0); } else { return pack.getSingletonBoosterPack(draft.NumCards); } } - return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, draft.NumSpecials, 0, 0, 0); + return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, + draft.NumSpecials, 0, 0, 0); } }; - Closure1, BoosterGenerator> picker = new Closure1, BoosterGenerator>(fnPick, bpCustom); - for (int i = 0; i < draft.NumPacks; i++) { packs.add(picker); } + final Closure1, BoosterGenerator> picker = new Closure1, BoosterGenerator>( + fnPick, bpCustom); + for (int i = 0; i < draft.NumPacks; i++) { + this.packs.add(picker); + } - LandSetCode[0] = draft.LandSetCode; + BoosterDraft.LAND_SET_CODE[0] = draft.LandSetCode; } - - /** Looks for res/draft/*.draft files, reads them, returns a list */ - private List loadCustomDrafts(String lookupFolder, String fileExtension) - { + + /** Looks for res/draft/*.draft files, reads them, returns a list. */ + private List loadCustomDrafts(final String lookupFolder, final String fileExtension) { String[] dList; - ArrayList customs = new ArrayList(); + final ArrayList customs = new ArrayList(); // get list of custom draft files - File dFolder = new File(lookupFolder); + final File dFolder = new File(lookupFolder); if (!dFolder.exists()) { throw new RuntimeException("BoosterDraft : folder not found -- folder is " + dFolder.getAbsolutePath()); } @@ -178,151 +190,172 @@ public final class BoosterDraft_1 implements BoosterDraft { dList = dFolder.list(); - for (int i = 0; i < dList.length; i++) { - if (dList[i].endsWith(fileExtension)) { - List dfData = FileUtil.readFile(lookupFolder + dList[i]); + for (final String element : dList) { + if (element.endsWith(fileExtension)) { + final List dfData = FileUtil.readFile(lookupFolder + element); customs.add(CustomLimited.parse(dfData)); } } return customs; } - - + /** - *

nextChoice.

- * + *

+ * nextChoice. + *

+ * * @return a {@link forge.CardList} object. */ + @Override public ItemPoolView nextChoice() { - if (pack.get(getCurrentBoosterIndex()).size() == 0) { - pack = get8BoosterPack(); + if (this.pack.get(this.getCurrentBoosterIndex()).size() == 0) { + this.pack = this.get8BoosterPack(); } - computerChoose(); - return ItemPool.createFrom(pack.get(getCurrentBoosterIndex()), CardPrinted.class); + this.computerChoose(); + return ItemPool.createFrom(this.pack.get(this.getCurrentBoosterIndex()), CardPrinted.class); } /** - *

get8BoosterPack.

- * + *

+ * get8BoosterPack. + *

+ * * @return an array of {@link forge.CardList} objects. */ public List> get8BoosterPack() { - if (nextBoosterGroup >= packs.size()) { return null; } + if (this.nextBoosterGroup >= this.packs.size()) { + return null; + } - List> list = new ArrayList>(); - for (int i = 0; i < 8; i++) { list.add(packs.get(nextBoosterGroup).apply()); } - - nextBoosterGroup++; - currentBoosterSize = list.get(0).size(); - currentBoosterPick = 0; + final List> list = new ArrayList>(); + for (int i = 0; i < 8; i++) { + list.add(this.packs.get(this.nextBoosterGroup).apply()); + } + + this.nextBoosterGroup++; + this.currentBoosterSize = list.get(0).size(); + this.currentBoosterPick = 0; return list; } - //size 7, all the computers decks + // size 7, all the computers decks /** - *

getDecks.

- * + *

+ * getDecks. + *

+ * * @return an array of {@link forge.deck.Deck} objects. */ + @Override public Deck[] getDecks() { - return draftAI.getDecks(); + return this.draftAI.getDecks(); } private void computerChoose() { - int iHumansBooster = getCurrentBoosterIndex(); + final int iHumansBooster = this.getCurrentBoosterIndex(); int iPlayer = 0; - for (int i = 0; i < pack.size(); i++) { - if (iHumansBooster == i) { continue; } // don't touch player's booster + for (int i = 0; i < this.pack.size(); i++) { + if (iHumansBooster == i) { + continue; + } // don't touch player's booster - CardList forAi = new CardList(); - List booster = pack.get(i); - for (CardPrinted cr : booster) { + final CardList forAi = new CardList(); + final List booster = this.pack.get(i); + for (final CardPrinted cr : booster) { forAi.add(cr.toForgeCard()); } - // TODO: Please write this drafting code to work without heavy card objects - Card aiPick = draftAI.choose(forAi, iPlayer++); - String pickedName = aiPick.getName(); + // TODO: Please write this drafting code to work without heavy card + // objects + final Card aiPick = this.draftAI.choose(forAi, iPlayer++); + final String pickedName = aiPick.getName(); for (int pick = booster.size() - 1; pick >= 0; pick--) { - CardPrinted cp = booster.get(pick); + final CardPrinted cp = booster.get(pick); if (cp.getName().equalsIgnoreCase(pickedName)) { booster.remove(pick); break; } } } - } //computerChoose() + } // computerChoose() private int getCurrentBoosterIndex() { - return currentBoosterPick % nPlayers; + return this.currentBoosterPick % BoosterDraft_1.N_PLAYERS; } /** - *

hasNextChoice.

- * + *

+ * hasNextChoice. + *

+ * * @return a boolean. */ + @Override public boolean hasNextChoice() { - boolean isLastGroup = nextBoosterGroup >= packs.size(); - boolean isBoosterDepleted = currentBoosterPick >= currentBoosterSize; - boolean noMoreCards = isLastGroup && isBoosterDepleted; + final boolean isLastGroup = this.nextBoosterGroup >= this.packs.size(); + final boolean isBoosterDepleted = this.currentBoosterPick >= this.currentBoosterSize; + final boolean noMoreCards = isLastGroup && isBoosterDepleted; return !noMoreCards; } /** {@inheritDoc} */ + @Override public void setChoice(final CardPrinted c) { - List thisBooster = pack.get(getCurrentBoosterIndex()); + final List thisBooster = this.pack.get(this.getCurrentBoosterIndex()); if (!thisBooster.contains(c)) { - throw new RuntimeException("BoosterDraft : setChoice() error - card not found - " + c + " - booster pack = " + thisBooster); + throw new RuntimeException("BoosterDraft : setChoice() error - card not found - " + c + + " - booster pack = " + thisBooster); } if (Constant.Runtime.UPLOAD_DRAFT[0]) { for (int i = 0; i < thisBooster.size(); i++) { - CardPrinted cc = thisBooster.get(i); - String cnBk = cc.getName() + "|" + cc.getSet(); + final CardPrinted cc = thisBooster.get(i); + final String cnBk = cc.getName() + "|" + cc.getSet(); float pickValue = 0; if (cc.equals(c)) { - pickValue = thisBooster.size() * (1f - ((float) currentBoosterPick / currentBoosterSize) * 2f); + pickValue = thisBooster.size() + * (1f - (((float) this.currentBoosterPick / this.currentBoosterSize) * 2f)); } else { pickValue = 0; } - if (!draftPicks.containsKey(cnBk)) { - draftPicks.put(cnBk, pickValue); + if (!this.draftPicks.containsKey(cnBk)) { + this.draftPicks.put(cnBk, pickValue); } else { - float curValue = draftPicks.get(cnBk); - float newValue = (curValue + pickValue) / 2; - draftPicks.put(cnBk, newValue); + final float curValue = this.draftPicks.get(cnBk); + final float newValue = (curValue + pickValue) / 2; + this.draftPicks.put(cnBk, newValue); } } } thisBooster.remove(c); - currentBoosterPick++; - } //setChoice() + this.currentBoosterPick++; + } // setChoice() /** This will upload drafting picks to cardforge HQ. */ + @Override public void finishedDrafting() { if (Constant.Runtime.UPLOAD_DRAFT[0]) { - if (draftPicks.size() > 1) { - ArrayList outDraftData = new ArrayList(); + if (this.draftPicks.size() > 1) { + final ArrayList outDraftData = new ArrayList(); - String[] keys = draftPicks.keySet().toArray(ArrayUtils.EMPTY_STRING_ARRAY); + final String[] keys = this.draftPicks.keySet().toArray(ArrayUtils.EMPTY_STRING_ARRAY); - for (int i = 0; i < keys.length; i++) { - outDraftData.add(keys[i] + "|" + draftPicks.get(keys[i])); + for (final String key : keys) { + outDraftData.add(key + "|" + this.draftPicks.get(key)); } FileUtil.writeFile("res/draft/tmpDraftData.txt", outDraftData); - HttpUtil poster = new HttpUtil(); - poster.upload("http://cardforge.org/draftAI/submitDraftData.php?fmt=" - + draftFormat, "res/draft/tmpDraftData.txt"); + final HttpUtil poster = new HttpUtil(); + poster.upload("http://cardforge.org/draftAI/submitDraftData.php?fmt=" + this.draftFormat, + "res/draft/tmpDraftData.txt"); } } } diff --git a/src/main/java/forge/game/limited/CCnt.java b/src/main/java/forge/game/limited/CCnt.java index 4b114be1fec..5d27dffc708 100644 --- a/src/main/java/forge/game/limited/CCnt.java +++ b/src/main/java/forge/game/limited/CCnt.java @@ -1,29 +1,73 @@ package forge.game.limited; /** - *

CCnt class.

- * + *

+ * CCnt class. + *

+ * * @author Forge * @version $Id$ */ class CCnt { - public String Color; - public int Count; + + /** The Color. */ + private String color; + + /** The Count. */ + private int count; /** - *

Constructor for CCnt.

- * - * @param clr a {@link java.lang.String} object. - * @param cnt a int. + *

+ * Constructor for CCnt. + *

+ * + * @param clr + * a {@link java.lang.String} object. + * @param cnt + * a int. */ /** - *

deckColors class.

- * - * @param clr a {@link java.lang.String} object. - * @param cnt a int. + *

+ * deckColors class. + *

+ * + * @param clr + * a {@link java.lang.String} object. + * @param cnt + * a int. */ public CCnt(final String clr, final int cnt) { - Color = clr; - Count = cnt; + this.setColor(clr); + this.setCount(cnt); + } + + /** + * @return the color + */ + public String getColor() { + return this.color; + } + + /** + * @param color + * the color to set + */ + public void setColor(final String color) { + this.color = color; // TODO: Add 0 to parameter's name. + } + + /** + * @return the count + */ + public int getCount() { + return this.count; + } + + /** + * @param count + * the count to set + */ + public void setCount(final int count) { + this.count = count; // TODO: Add 0 to parameter's name. } } diff --git a/src/main/java/forge/game/limited/CardPoolLimitation.java b/src/main/java/forge/game/limited/CardPoolLimitation.java index 3317da3160a..da92a743671 100644 --- a/src/main/java/forge/game/limited/CardPoolLimitation.java +++ b/src/main/java/forge/game/limited/CardPoolLimitation.java @@ -1,11 +1,15 @@ package forge.game.limited; -/** +/** * TODO: Write javadoc for this type. - * + * */ public enum CardPoolLimitation { + + /** The Full. */ Full, - Block, - Custom + /** The Block. */ + Block, + /** The Custom. */ + Custom } diff --git a/src/main/java/forge/game/limited/CustomLimited.java b/src/main/java/forge/game/limited/CustomLimited.java index d8ace10cebf..c8985c10567 100644 --- a/src/main/java/forge/game/limited/CustomLimited.java +++ b/src/main/java/forge/game/limited/CustomLimited.java @@ -5,53 +5,125 @@ import java.util.List; import forge.AllZone; /** - *

CustomDraft class.

- * + *

+ * CustomDraft class. + *

+ * * @author Forge * @version $Id$ */ class CustomLimited { + + /** The Name. */ public String Name; + + /** The Type. */ public String Type; + + /** The Deck file. */ public String DeckFile; + + /** The Ignore rarity. */ public Boolean IgnoreRarity; + + /** The Singleton. */ public Boolean Singleton = false; + + /** The Num cards. */ public int NumCards = 15; + + /** The Num specials. */ public int NumSpecials = 0; + + /** The Num mythics. */ public int NumMythics = 1; + + /** The Num rares. */ public int NumRares = 1; + + /** The Num uncommons. */ public int NumUncommons = 3; + + /** The Num commons. */ public int NumCommons = 11; + + /** The Num double faced. */ public int NumDoubleFaced = 0; + + /** The Num packs. */ public int NumPacks = 3; + + /** The Land set code. */ public String LandSetCode = AllZone.getCardFactory().getCard("Plains", AllZone.getHumanPlayer()).getMostRecentSet(); - - @Override public String toString() { return Name; } - - public static CustomLimited parse(List dfData) - { - CustomLimited cd = new CustomLimited(); - for (String dd : dfData) { - String[] v = dd.split(":", 2); - String key = v[0]; - String value = v.length > 1 ? v[1].trim() : ""; - - if (key.equalsIgnoreCase("Name")) { cd.Name = value; } - if (key.equalsIgnoreCase("Type")) { cd.Type = value; } - if (key.equalsIgnoreCase("DeckFile")) { cd.DeckFile = value; } - if (key.equalsIgnoreCase("IgnoreRarity")) { cd.IgnoreRarity = value.equals("True"); } - if (key.equalsIgnoreCase("Singleton")) { cd.Singleton = value.equals("True"); } - if (key.equalsIgnoreCase("LandSetCode")) { cd.LandSetCode = value; } + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return this.Name; + } - if (key.equalsIgnoreCase("NumCards")) { cd.NumCards = Integer.parseInt(value); } - if (key.equalsIgnoreCase("NumDoubleFaced")) { cd.NumDoubleFaced = Integer.parseInt(value); } - if (key.equalsIgnoreCase("NumSpecials")) { cd.NumSpecials = Integer.parseInt(value); } - if (key.equalsIgnoreCase("NumMythics")) { cd.NumMythics = Integer.parseInt(value); } - if (key.equalsIgnoreCase("NumRares")) { cd.NumRares = Integer.parseInt(value); } - if (key.equalsIgnoreCase("NumUncommons")) { cd.NumUncommons = Integer.parseInt(value); } - if (key.equalsIgnoreCase("NumCommons")) { cd.NumCommons = Integer.parseInt(value); } - if (key.equalsIgnoreCase("NumPacks")) { cd.NumPacks = Integer.parseInt(value); } + /** + * Parses the. + * + * @param dfData + * the df data + * @return the custom limited + */ + public static CustomLimited parse(final List dfData) { + final CustomLimited cd = new CustomLimited(); + + for (final String dd : dfData) { + final String[] v = dd.split(":", 2); + final String key = v[0]; + final String value = v.length > 1 ? v[1].trim() : ""; + + if (key.equalsIgnoreCase("Name")) { + cd.Name = value; + } + if (key.equalsIgnoreCase("Type")) { + cd.Type = value; + } + if (key.equalsIgnoreCase("DeckFile")) { + cd.DeckFile = value; + } + if (key.equalsIgnoreCase("IgnoreRarity")) { + cd.IgnoreRarity = value.equals("True"); + } + if (key.equalsIgnoreCase("Singleton")) { + cd.Singleton = value.equals("True"); + } + if (key.equalsIgnoreCase("LandSetCode")) { + cd.LandSetCode = value; + } + + if (key.equalsIgnoreCase("NumCards")) { + cd.NumCards = Integer.parseInt(value); + } + if (key.equalsIgnoreCase("NumDoubleFaced")) { + cd.NumDoubleFaced = Integer.parseInt(value); + } + if (key.equalsIgnoreCase("NumSpecials")) { + cd.NumSpecials = Integer.parseInt(value); + } + if (key.equalsIgnoreCase("NumMythics")) { + cd.NumMythics = Integer.parseInt(value); + } + if (key.equalsIgnoreCase("NumRares")) { + cd.NumRares = Integer.parseInt(value); + } + if (key.equalsIgnoreCase("NumUncommons")) { + cd.NumUncommons = Integer.parseInt(value); + } + if (key.equalsIgnoreCase("NumCommons")) { + cd.NumCommons = Integer.parseInt(value); + } + if (key.equalsIgnoreCase("NumPacks")) { + cd.NumPacks = Integer.parseInt(value); + } } return cd; } diff --git a/src/main/java/forge/game/limited/DeckColors.java b/src/main/java/forge/game/limited/DeckColors.java index ab35412bedf..ea7d2708896 100644 --- a/src/main/java/forge/game/limited/DeckColors.java +++ b/src/main/java/forge/game/limited/DeckColors.java @@ -3,56 +3,71 @@ package forge.game.limited; import forge.Constant; /** - * Created by IntelliJ IDEA. - * User: dhudson - * Date: 6/24/11 - * Time: 8:42 PM - * To change this template use File | Settings | File Templates. + * Created by IntelliJ IDEA. User: dhudson Date: 6/24/11 Time: 8:42 PM To change + * this template use File | Settings | File Templates. */ class DeckColors { + + /** The Color1. */ public String Color1 = "none"; + + /** The Color2. */ public String Color2 = "none"; - //public String Splash = "none"; + // public String Splash = "none"; + /** The Mana1. */ public String Mana1 = ""; + + /** The Mana2. */ public String Mana2 = ""; - //public String ManaS = ""; + + // public String ManaS = ""; /** - *

Constructor for deckColors.

- * - * @param c1 a {@link java.lang.String} object. - * @param c2 a {@link java.lang.String} object. - * @param sp a {@link java.lang.String} object. + *

+ * Constructor for deckColors. + *

+ * + * @param c1 + * a {@link java.lang.String} object. + * @param c2 + * a {@link java.lang.String} object. + * @param sp + * a {@link java.lang.String} object. */ - public DeckColors(String c1, String c2, String sp) { - Color1 = c1; - Color2 = c2; - //Splash = sp; + public DeckColors(final String c1, final String c2, final String sp) { + this.Color1 = c1; + this.Color2 = c2; + // Splash = sp; } /** - *

Constructor for DeckColors.

+ *

+ * Constructor for DeckColors. + *

*/ public DeckColors() { } /** - *

ColorToMana.

- * - * @param color a {@link java.lang.String} object. + *

+ * ColorToMana. + *

+ * + * @param color + * a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ - public String ColorToMana(String color) { - String Mana[] = {"W", "U", "B", "R", "G"}; + public String ColorToMana(final String color) { + final String Mana[] = { "W", "U", "B", "R", "G" }; for (int i = 0; i < Constant.Color.ONLY_COLORS.length; i++) { - if (Constant.Color.ONLY_COLORS[i].equals(color)) + if (Constant.Color.ONLY_COLORS[i].equals(color)) { return Mana[i]; + } } return ""; } - } diff --git a/src/main/java/forge/game/limited/SealedDeck.java b/src/main/java/forge/game/limited/SealedDeck.java index c9e4f622031..23f01406fb4 100644 --- a/src/main/java/forge/game/limited/SealedDeck.java +++ b/src/main/java/forge/game/limited/SealedDeck.java @@ -1,5 +1,13 @@ package forge.game.limited; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JOptionPane; + +import net.slightlymagic.braids.util.lambda.Lambda1; +import net.slightlymagic.maxmtg.Closure1; import forge.AllZone; import forge.Card; import forge.CardList; @@ -21,164 +29,180 @@ import forge.item.CardDb; import forge.item.CardPrinted; import forge.item.ItemPool; -import javax.swing.*; - -import net.slightlymagic.braids.util.lambda.Lambda1; -import net.slightlymagic.maxmtg.Closure1; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - /** - *

SealedDeck class.

- * + *

+ * SealedDeck class. + *

+ * * @author Forge * @version $Id$ * @since 1.0.15 */ public class SealedDeck { - private List, BoosterGenerator>> packs = new ArrayList, BoosterGenerator>>(); - public String LandSetCode[] = {""}; + private final List, BoosterGenerator>> packs = new ArrayList, BoosterGenerator>>(); + + /** The Land set code. */ + public String LandSetCode[] = { "" }; /** - *

Constructor for SealedDeck.

- * - * @param sealedType a {@link java.lang.String} object. + *

+ * Constructor for SealedDeck. + *

+ * + * @param sealedType + * a {@link java.lang.String} object. */ - public SealedDeck(String sealedType) { + public SealedDeck(final String sealedType) { if (sealedType.equals("Full")) { - BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards()); - Closure1, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull); - for (int i = 0; i < 6; i++) - packs.add(picker); + final BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards()); + final Closure1, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull); + for (int i = 0; i < 6; i++) { + this.packs.add(picker); + } - LandSetCode[0] = CardDb.instance().getCard("Plains").getSet(); + this.LandSetCode[0] = CardDb.instance().getCard("Plains").getSet(); } else if (sealedType.equals("Block")) { - Object o = GuiUtils.getChoice("Choose Block", SetUtils.getBlocks().toArray()); - CardBlock block = (CardBlock) o; + final Object o = GuiUtils.getChoice("Choose Block", SetUtils.getBlocks().toArray()); + final CardBlock block = (CardBlock) o; - CardSet[] cardSets = block.getSets(); - String[] sets = new String[cardSets.length]; - for (int k = cardSets.length - 1; k >= 0 ; --k) { sets[k] = cardSets[k].getCode();} + final CardSet[] cardSets = block.getSets(); + final String[] sets = new String[cardSets.length]; + for (int k = cardSets.length - 1; k >= 0; --k) { + sets[k] = cardSets[k].getCode(); + } - int nPacks = block.getCntBoostersSealed(); + final int nPacks = block.getCntBoostersSealed(); - List setCombos = new ArrayList(); + final List setCombos = new ArrayList(); if (sets.length >= 2) { - setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[0], sets[0], sets[0], sets[0], sets[0], sets[0])); - setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[0], sets[0], sets[0], sets[0])); - setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[1], sets[0], sets[0], sets[0])); + setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[0], sets[0], sets[0], sets[0], sets[0], sets[0])); + setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[0], sets[0], sets[0], sets[0])); + setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[1], sets[0], sets[0], sets[0])); } if (sets.length >= 3) { - setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[2], sets[0], sets[0], sets[0])); - setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[1], sets[1], sets[0], sets[0])); + setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[2], sets[0], sets[0], sets[0])); + setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[1], sets[1], sets[0], sets[0])); } - if (sets.length > 1) { - Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray()); + final Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray()); - String[] pp = p.toString().split("/"); + final String[] pp = p.toString().split("/"); for (int i = 0; i < nPacks; i++) { - BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i])); - packs.add(BoosterGenerator.getSimplePicker(bpMulti)); + final BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i])); + this.packs.add(BoosterGenerator.getSimplePicker(bpMulti)); } } else { - BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0])); - Closure1, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpOne); - for (int i = 0; i < nPacks; i++) { packs.add(picker); } + final BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0])); + final Closure1, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpOne); + for (int i = 0; i < nPacks; i++) { + this.packs.add(picker); + } } - LandSetCode[0] = block.getLandSet().getCode(); + this.LandSetCode[0] = block.getLandSet().getCode(); } else if (sealedType.equals("Custom")) { String dList[]; - ArrayList customs = new ArrayList(); + final ArrayList customs = new ArrayList(); // get list of custom draft files - File dFolder = new File("res/sealed/"); - if (!dFolder.exists()) - throw new RuntimeException("GenerateSealed : folder not found -- folder is " + dFolder.getAbsolutePath()); + final File dFolder = new File("res/sealed/"); + if (!dFolder.exists()) { + throw new RuntimeException("GenerateSealed : folder not found -- folder is " + + dFolder.getAbsolutePath()); + } - if (!dFolder.isDirectory()) + if (!dFolder.isDirectory()) { throw new RuntimeException("GenerateSealed : not a folder -- " + dFolder.getAbsolutePath()); + } dList = dFolder.list(); - for (int i = 0; i < dList.length; i++) { - if (dList[i].endsWith(".sealed")) { - ArrayList dfData = FileUtil.readFile("res/sealed/" + dList[i]); - CustomLimited cs = CustomLimited.parse(dfData); + for (final String element : dList) { + if (element.endsWith(".sealed")) { + final ArrayList dfData = FileUtil.readFile("res/sealed/" + element); + final CustomLimited cs = CustomLimited.parse(dfData); customs.add(cs); } } // present list to user - if (customs.size() < 1) - JOptionPane.showMessageDialog(null, "No custom sealed files found.", "", JOptionPane.INFORMATION_MESSAGE); + if (customs.size() < 1) { + JOptionPane.showMessageDialog(null, "No custom sealed files found.", "", + JOptionPane.INFORMATION_MESSAGE); + } else { + final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Sealed Pool", + customs.toArray()); - else { - final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Sealed Pool", customs.toArray()); - - DeckManager dio = AllZone.getDeckManager(); - Deck dPool = dio.getDeck(draft.DeckFile); + final DeckManager dio = AllZone.getDeckManager(); + final Deck dPool = dio.getDeck(draft.DeckFile); if (dPool == null) { throw new RuntimeException("BoosterGenerator : deck not found - " + draft.DeckFile); } - BoosterGenerator bpCustom = new BoosterGenerator(dPool); - Lambda1, BoosterGenerator> fnPick = new Lambda1, BoosterGenerator>() { - @Override public List apply(BoosterGenerator pack) { - if ( draft.IgnoreRarity ) { + final BoosterGenerator bpCustom = new BoosterGenerator(dPool); + final Lambda1, BoosterGenerator> fnPick = new Lambda1, BoosterGenerator>() { + @Override + public List apply(final BoosterGenerator pack) { + if (draft.IgnoreRarity) { return pack.getBoosterPack(0, 0, 0, 0, 0, 0, 0, draft.NumCards, 0); } - return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, draft.NumSpecials, draft.NumDoubleFaced, 0, 0); + return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, + draft.NumMythics, draft.NumSpecials, draft.NumDoubleFaced, 0, 0); } }; - Closure1, BoosterGenerator> picker = new Closure1, BoosterGenerator>(fnPick, bpCustom); + final Closure1, BoosterGenerator> picker = new Closure1, BoosterGenerator>( + fnPick, bpCustom); for (int i = 0; i < draft.NumPacks; i++) { - packs.add(picker); + this.packs.add(picker); } - LandSetCode[0] = draft.LandSetCode; + this.LandSetCode[0] = draft.LandSetCode; } } } /** - *

getCardpool.

- * + *

+ * getCardpool. + *

+ * * @return a {@link forge.CardList} object. */ public ItemPool getCardpool() { - ItemPool pool = new ItemPool(CardPrinted.class); + final ItemPool pool = new ItemPool(CardPrinted.class); - for (int i = 0; i < packs.size(); i++) - pool.addAllCards(packs.get(i).apply()); + for (int i = 0; i < this.packs.size(); i++) { + pool.addAllCards(this.packs.get(i).apply()); + } return pool; } /** - *

buildAIDeck.

- * - * @param aiCardpool a {@link forge.CardList} object. + *

+ * buildAIDeck. + *

+ * + * @param aiCardpool + * a {@link forge.CardList} object. * @return a {@link forge.deck.Deck} object. */ - public Deck buildAIDeck(CardList aiCardpool) { - CardList deck = new CardList(); + public Deck buildAIDeck(final CardList aiCardpool) { + final CardList deck = new CardList(); int cardsNeeded = 22; int landsNeeded = 18; int nCreatures = 15; - CardList AIPlayables = aiCardpool.filter(new CardListFilter() { - public boolean addCard(Card c) { + final CardList AIPlayables = aiCardpool.filter(new CardListFilter() { + @Override + public boolean addCard(final Card c) { return !(c.getSVar("RemAIDeck").equals("True")); } }); @@ -186,28 +210,32 @@ public class SealedDeck { CardList creatures = AIPlayables.getType("Creature"); CardListUtil.sortByEvaluateCreature(creatures); - CardList colorChooserList = new CardList(); // choose colors based on top 33% of creatures - for (int i = 0; i < (creatures.size() * .33); i++) + final CardList colorChooserList = new CardList(); // choose colors based + // on top 33% of + // creatures + for (int i = 0; i < (creatures.size() * .33); i++) { colorChooserList.add(creatures.get(i)); + } - int colorCounts[] = {0, 0, 0, 0, 0}; - String colors[] = Constant.Color.ONLY_COLORS; - for (int i = 0; i < colors.length; i++) + final int colorCounts[] = { 0, 0, 0, 0, 0 }; + final String colors[] = Constant.Color.ONLY_COLORS; + for (int i = 0; i < colors.length; i++) { colorCounts[i] = colorChooserList.getColor(colors[i]).size(); + } for (int i = 0; i < 4; i++) { if (colorCounts[i + 1] < colorCounts[i]) { - int t = colorCounts[i]; + final int t = colorCounts[i]; colorCounts[i] = colorCounts[i + 1]; colorCounts[i + 1] = t; - String s = colors[i]; + final String s = colors[i]; colors[i] = colors[i + 1]; colors[i + 1] = s; } } - DeckColors dcAI = new DeckColors(); + final DeckColors dcAI = new DeckColors(); dcAI.Color1 = colors[0]; dcAI.Color2 = colors[1]; dcAI.Splash = colors[2]; @@ -220,8 +248,8 @@ public class SealedDeck { CardListUtil.sortByEvaluateCreature(creatures); int i = 0; - while (nCreatures > 0 && i < creatures.size()) { - Card c = creatures.get(i); + while ((nCreatures > 0) && (i < creatures.size())) { + final Card c = creatures.get(i); deck.add(c); aiCardpool.remove(c); @@ -231,9 +259,9 @@ public class SealedDeck { i++; } - CardList splashCreatures = AIPlayables.getType("Creature").getColor(dcAI.Splash); - while (nCreatures > 1 && splashCreatures.size() > 1) { - Card c = splashCreatures.get(MyRandom.getRandom().nextInt(splashCreatures.size() - 1)); + final CardList splashCreatures = AIPlayables.getType("Creature").getColor(dcAI.Splash); + while ((nCreatures > 1) && (splashCreatures.size() > 1)) { + final Card c = splashCreatures.get(MyRandom.getRandom().nextInt(splashCreatures.size() - 1)); deck.add(c); aiCardpool.remove(c); @@ -243,7 +271,7 @@ public class SealedDeck { nCreatures--; } - CardList walkers = AIPlayables.getType("Planeswalker").getOnly2Colors(dcAI.Color1, dcAI.Color2); + final CardList walkers = AIPlayables.getType("Planeswalker").getOnly2Colors(dcAI.Color1, dcAI.Color2); if (walkers.size() > 0) { deck.add(walkers.get(0)); AIPlayables.remove(walkers.get(0)); @@ -251,12 +279,12 @@ public class SealedDeck { cardsNeeded--; } - CardList spells = AIPlayables.getType("Instant").getOnly2Colors(dcAI.Color1, dcAI.Color2); + final CardList spells = AIPlayables.getType("Instant").getOnly2Colors(dcAI.Color1, dcAI.Color2); spells.addAll(AIPlayables.getType("Sorcery").getOnly2Colors(dcAI.Color1, dcAI.Color2)); spells.addAll(AIPlayables.getType("Enchantment").getOnly2Colors(dcAI.Color1, dcAI.Color2)); - while (cardsNeeded > 0 && spells.size() > 1) { - Card c = spells.get(MyRandom.getRandom().nextInt(spells.size() - 1)); + while ((cardsNeeded > 0) && (spells.size() > 1)) { + final Card c = spells.get(MyRandom.getRandom().nextInt(spells.size() - 1)); deck.add(c); spells.remove(c); AIPlayables.remove(c); @@ -264,11 +292,11 @@ public class SealedDeck { cardsNeeded--; } - CardList splashSpells = AIPlayables.getType("Instant").getColor(dcAI.Splash); + final CardList splashSpells = AIPlayables.getType("Instant").getColor(dcAI.Splash); splashSpells.addAll(AIPlayables.getType("Sorcery").getColor(dcAI.Splash)); - while (cardsNeeded > 0 && splashSpells.size() > 1) { - Card c = splashSpells.get(MyRandom.getRandom().nextInt(splashSpells.size() - 1)); + while ((cardsNeeded > 0) && (splashSpells.size() > 1)) { + final Card c = splashSpells.get(MyRandom.getRandom().nextInt(splashSpells.size() - 1)); deck.add(c); splashSpells.remove(c); AIPlayables.remove(c); @@ -276,16 +304,18 @@ public class SealedDeck { cardsNeeded--; } - CardList lands = AIPlayables.getType("Land"); + final CardList lands = AIPlayables.getType("Land"); if (lands.size() > 0) { - final DeckColors AIdc = dcAI; // just for the filter + final DeckColors AIdc = dcAI; // just for the filter lands.filter(new CardListFilter() { - public boolean addCard(Card c) { - ArrayList maList = c.getManaAbility(); + @Override + public boolean addCard(final Card c) { + final ArrayList maList = c.getManaAbility(); for (int j = 0; j < maList.size(); j++) { - if (maList.get(j).canProduce(AIdc.Mana1) || maList.get(j).canProduce(AIdc.Mana2)) + if (maList.get(j).canProduce(AIdc.Mana1) || maList.get(j).canProduce(AIdc.Mana2)) { return true; + } } return false; @@ -294,7 +324,7 @@ public class SealedDeck { if (lands.size() > 0) { for (i = 0; i < lands.size(); i++) { - Card c = lands.get(i); + final Card c = lands.get(i); deck.add(c); aiCardpool.remove(c); @@ -304,52 +334,56 @@ public class SealedDeck { } } - if (landsNeeded > 0) // attempt to optimize basic land counts according to color representation + if (landsNeeded > 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)}; + final 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? for (i = 0; i < deck.size(); i++) { - String mc = deck.get(i).getManaCost(); + final String mc = deck.get(i).getManaCost(); // count each mana symbol in the mana cost for (int j = 0; j < mc.length(); j++) { - char c = mc.charAt(j); + final char c = mc.charAt(j); - if (c == 'W') - ClrCnts[0].Count++; - else if (c == 'U') - ClrCnts[1].Count++; - else if (c == 'B') - ClrCnts[2].Count++; - else if (c == 'R') - ClrCnts[3].Count++; - else if (c == 'G') - ClrCnts[4].Count++; + if (c == 'W') { + ClrCnts[0].setCount(ClrCnts[0].getCount() + 1); + } else if (c == 'U') { + ClrCnts[1].setCount(ClrCnts[1].getCount() + 1); + } else if (c == 'B') { + ClrCnts[2].setCount(ClrCnts[2].getCount() + 1); + } else if (c == 'R') { + ClrCnts[3].setCount(ClrCnts[3].getCount() + 1); + } else if (c == 'G') { + ClrCnts[4].setCount(ClrCnts[4].getCount() + 1); + } } } // total of all ClrCnts int totalColor = 0; for (i = 0; i < 5; i++) { - totalColor += ClrCnts[i].Count; + totalColor += ClrCnts[i].getCount(); } for (i = 0; i < 5; i++) { - if (ClrCnts[i].Count > 0) { // calculate number of lands for each color - float p = (float) ClrCnts[i].Count / (float) totalColor; - int nLand = (int) ((float) landsNeeded * p) + 1; - //tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n"; - if (Constant.Runtime.DEV_MODE[0]) - System.out.println("Basics[" + ClrCnts[i].Color + "]:" + nLand); + if (ClrCnts[i].getCount() > 0) { // calculate number of + // lands for + // each color + final float p = (float) ClrCnts[i].getCount() / (float) totalColor; + final int nLand = (int) (landsNeeded * p) + 1; + // tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + // + "\n"; + if (Constant.Runtime.DEV_MODE[0]) { + System.out.println("Basics[" + ClrCnts[i].getColor() + "]:" + nLand); + } for (int j = 0; j <= nLand; j++) { - Card c = AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer()); + final Card c = AllZone.getCardFactory().getCard(ClrCnts[i].getColor(), + AllZone.getComputerPlayer()); c.setCurSetCode(this.LandSetCode[0]); deck.add(c); landsNeeded--; @@ -358,63 +392,103 @@ public class SealedDeck { } int n = 0; while (landsNeeded > 0) { - if (ClrCnts[n].Count > 0) { - Card c = AllZone.getCardFactory().getCard(ClrCnts[n].Color, AllZone.getComputerPlayer()); + if (ClrCnts[n].getCount() > 0) { + final Card c = AllZone.getCardFactory().getCard(ClrCnts[n].getColor(), + AllZone.getComputerPlayer()); c.setCurSetCode(this.LandSetCode[0]); deck.add(c); landsNeeded--; - if (Constant.Runtime.DEV_MODE[0]) + if (Constant.Runtime.DEV_MODE[0]) { System.out.println("AddBasics: " + c.getName()); + } } - if (++n > 4) + if (++n > 4) { n = 0; + } } } } - Deck aiDeck = new Deck(GameType.Sealed); + final Deck aiDeck = new Deck(GameType.Sealed); - for (i = 0; i < deck.size(); i++) + for (i = 0; i < deck.size(); i++) { aiDeck.addMain(deck.get(i).getName() + "|" + deck.get(i).getCurSetCode()); + } - for (i = 0; i < aiCardpool.size(); i++) + for (i = 0; i < aiCardpool.size(); i++) { aiDeck.addSideboard(aiCardpool.get(i).getName() + "|" + aiCardpool.get(i).getCurSetCode()); + } return aiDeck; } + /** + * The Class DeckColors. + */ class DeckColors { + + /** The Color1. */ public String Color1 = "none"; + + /** The Color2. */ public String Color2 = "none"; + + /** The Splash. */ public String Splash = "none"; + + /** The Mana1. */ public String Mana1 = ""; + + /** The Mana2. */ public String Mana2 = ""; + + /** The Mana s. */ public String ManaS = ""; - public DeckColors(String c1, String c2, String sp) { - Color1 = c1; - Color2 = c2; - //Splash = sp; + /** + * Instantiates a new deck colors. + * + * @param c1 + * the c1 + * @param c2 + * the c2 + * @param sp + * the sp + */ + public DeckColors(final String c1, final String c2, final String sp) { + this.Color1 = c1; + this.Color2 = c2; + // Splash = sp; } + /** + * Instantiates a new deck colors. + */ public DeckColors() { } - public String ColorToMana(String color) { - String Mana[] = {"W", "U", "B", "R", "G"}; - String Clrs[] = {"white", "blue", "black", "red", "green"}; + /** + * Color to mana. + * + * @param color + * the color + * @return the string + */ + public String ColorToMana(final String color) { + final String Mana[] = { "W", "U", "B", "R", "G" }; + final String Clrs[] = { "white", "blue", "black", "red", "green" }; for (int i = 0; i < Constant.Color.ONLY_COLORS.length; i++) { - if (Clrs[i].equals(color)) + if (Clrs[i].equals(color)) { return Mana[i]; + } } return ""; } - } } diff --git a/src/main/java/forge/game/limited/package-info.java b/src/main/java/forge/game/limited/package-info.java index a8e7e05b8a1..8100d9fefd3 100644 --- a/src/main/java/forge/game/limited/package-info.java +++ b/src/main/java/forge/game/limited/package-info.java @@ -1,2 +1,3 @@ /** Forge Card Game */ package forge.game.limited; + diff --git a/src/main/java/forge/game/package-info.java b/src/main/java/forge/game/package-info.java index abf03bdb001..c1a6d89a2c5 100644 --- a/src/main/java/forge/game/package-info.java +++ b/src/main/java/forge/game/package-info.java @@ -1,2 +1,3 @@ -/** Forge Card Game */ +/** Forge Card Game. */ package forge.game; + diff --git a/src/main/java/forge/gui/deckeditor/DeckEditorDraft.java b/src/main/java/forge/gui/deckeditor/DeckEditorDraft.java index 59e5f9d895e..496a21329a1 100644 --- a/src/main/java/forge/gui/deckeditor/DeckEditorDraft.java +++ b/src/main/java/forge/gui/deckeditor/DeckEditorDraft.java @@ -292,7 +292,7 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New ItemPoolView list = ItemPool.createFrom(bottom.getCards(), CardPrinted.class); deck.addSideboard(list); - String landSet = BoosterDraft.LandSetCode[0]; + String landSet = BoosterDraft.LAND_SET_CODE[0]; final int LANDS_COUNT = 20; deck.addSideboard(CardDb.instance().getCard("Forest", landSet), LANDS_COUNT); deck.addSideboard(CardDb.instance().getCard("Mountain", landSet), LANDS_COUNT);