checkstyle

This commit is contained in:
jendave
2011-10-31 14:55:41 +00:00
parent ad7f49d808
commit 697e548218
17 changed files with 907 additions and 849 deletions

View File

@@ -21,10 +21,10 @@ public class StaticAbility {
private HashMap<String, String> mapParams = new HashMap<String, String>(); private HashMap<String, String> mapParams = new HashMap<String, String>();
/** The temporarily suppressed. */ /** The temporarily suppressed. */
protected boolean temporarilySuppressed = false; private boolean temporarilySuppressed = false;
/** The suppressed. */ /** The suppressed. */
protected boolean suppressed = false; private boolean suppressed = false;
/** /**
* <p> * <p>
@@ -34,7 +34,7 @@ public class StaticAbility {
* @return a {@link forge.Card} object. * @return a {@link forge.Card} object.
*/ */
public final Card getHostCard() { public final Card getHostCard() {
return hostCard; return this.hostCard;
} }
/** /**
@@ -45,7 +45,7 @@ public class StaticAbility {
* @return a {@link java.util.HashMap} object. * @return a {@link java.util.HashMap} object.
*/ */
public final HashMap<String, String> getMapParams() { public final HashMap<String, String> getMapParams() {
return mapParams; return this.mapParams;
} }
// ******************************************************* // *******************************************************
@@ -62,14 +62,14 @@ public class StaticAbility {
* @return a {@link java.util.HashMap} object. * @return a {@link java.util.HashMap} object.
*/ */
public final HashMap<String, String> getMapParams(final String abString, final Card hostCard) { public final HashMap<String, String> getMapParams(final String abString, final Card hostCard) {
HashMap<String, String> mapParameters = new HashMap<String, String>(); final HashMap<String, String> mapParameters = new HashMap<String, String>();
if (!(abString.length() > 0)) { if (!(abString.length() > 0)) {
throw new RuntimeException("StaticEffectFactory : getAbility -- abString too short in " throw new RuntimeException("StaticEffectFactory : getAbility -- abString too short in "
+ hostCard.getName() + ": [" + abString + "]"); + hostCard.getName() + ": [" + abString + "]");
} }
String[] a = abString.split("\\|"); final String[] a = abString.split("\\|");
for (int aCnt = 0; aCnt < a.length; aCnt++) { for (int aCnt = 0; aCnt < a.length; aCnt++) {
a[aCnt] = a[aCnt].trim(); a[aCnt] = a[aCnt].trim();
@@ -79,17 +79,17 @@ public class StaticAbility {
throw new RuntimeException("StaticEffectFactory : getAbility -- a[] too short in " + hostCard.getName()); throw new RuntimeException("StaticEffectFactory : getAbility -- a[] too short in " + hostCard.getName());
} }
for (int i = 0; i < a.length; i++) { for (final String element : a) {
String[] aa = a[i].split("\\$"); final String[] aa = element.split("\\$");
for (int aaCnt = 0; aaCnt < aa.length; aaCnt++) { for (int aaCnt = 0; aaCnt < aa.length; aaCnt++) {
aa[aaCnt] = aa[aaCnt].trim(); aa[aaCnt] = aa[aaCnt].trim();
} }
if (aa.length != 2) { if (aa.length != 2) {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("StaticEffectFactory Parsing Error: Split length of "); sb.append("StaticEffectFactory Parsing Error: Split length of ");
sb.append(a[i]).append(" in ").append(hostCard.getName()).append(" is not 2."); sb.append(element).append(" in ").append(hostCard.getName()).append(" is not 2.");
throw new RuntimeException(sb.toString()); throw new RuntimeException(sb.toString());
} }
@@ -108,46 +108,41 @@ public class StaticAbility {
*/ */
public final int getLayer() { public final int getLayer() {
if (!mapParams.get("Mode").equals("Continuous")) { if (!this.mapParams.get("Mode").equals("Continuous")) {
return 0; return 0;
} }
if (mapParams.containsKey("AddType") || mapParams.containsKey("RemoveType") if (this.mapParams.containsKey("AddType") || this.mapParams.containsKey("RemoveType")
|| mapParams.containsKey("RemoveCardType") || mapParams.containsKey("RemoveSubType") || this.mapParams.containsKey("RemoveCardType") || this.mapParams.containsKey("RemoveSubType")
|| mapParams.containsKey("RemoveSuperType")) { || this.mapParams.containsKey("RemoveSuperType")) {
return 4; return 4;
} }
if (mapParams.containsKey("AddColor") || mapParams.containsKey("RemoveColor") if (this.mapParams.containsKey("AddColor") || this.mapParams.containsKey("RemoveColor")
|| mapParams.containsKey("SetColor")) { || this.mapParams.containsKey("SetColor")) {
return 5; return 5;
} }
if (mapParams.containsKey("RemoveAllAbilities")) if (this.mapParams.containsKey("RemoveAllAbilities")) {
{
return 6; // Layer 6 return 6; // Layer 6
} }
if (mapParams.containsKey("AddKeyword") || mapParams.containsKey("AddAbility") if (this.mapParams.containsKey("AddKeyword") || this.mapParams.containsKey("AddAbility")
|| mapParams.containsKey("AddTrigger") || mapParams.containsKey("RemoveTriggers") || this.mapParams.containsKey("AddTrigger") || this.mapParams.containsKey("RemoveTriggers")
|| mapParams.containsKey("RemoveKeyword")) || this.mapParams.containsKey("RemoveKeyword")) {
{
return 7; // Layer 6 (dependent) return 7; // Layer 6 (dependent)
} }
if (mapParams.containsKey("CharacteristicDefining")) if (this.mapParams.containsKey("CharacteristicDefining")) {
{
return 8; // Layer 7a return 8; // Layer 7a
} }
if (mapParams.containsKey("AddPower") || mapParams.containsKey("AddToughness") if (this.mapParams.containsKey("AddPower") || this.mapParams.containsKey("AddToughness")
|| mapParams.containsKey("SetPower") || mapParams.containsKey("SetToughness")) || this.mapParams.containsKey("SetPower") || this.mapParams.containsKey("SetToughness")) {
{
return 9; // This is the collection of 7b and 7c return 9; // This is the collection of 7b and 7c
} }
if (mapParams.containsKey("AddHiddenKeyword")) if (this.mapParams.containsKey("AddHiddenKeyword")) {
{
return 10; // rules change return 10; // rules change
} }
@@ -163,9 +158,10 @@ public class StaticAbility {
* *
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
@Override
public final String toString() { public final String toString() {
if (mapParams.containsKey("Description") && !isSuppressed()) { if (this.mapParams.containsKey("Description") && !this.isSuppressed()) {
return mapParams.get("Description").replace("CARDNAME", hostCard.getName()); return this.mapParams.get("Description").replace("CARDNAME", this.hostCard.getName());
} else { } else {
return ""; return "";
} }
@@ -181,8 +177,8 @@ public class StaticAbility {
* the host * the host
*/ */
public StaticAbility(final String params, final Card host) { public StaticAbility(final String params, final Card host) {
mapParams = getMapParams(params, host); this.mapParams = this.getMapParams(params, host);
hostCard = host; this.hostCard = host;
} }
/** /**
@@ -194,11 +190,11 @@ public class StaticAbility {
* the host * the host
*/ */
public StaticAbility(final HashMap<String, String> params, final Card host) { public StaticAbility(final HashMap<String, String> params, final Card host) {
mapParams = new HashMap<String, String>(); this.mapParams = new HashMap<String, String>();
for (Map.Entry<String, String> entry : params.entrySet()) { for (final Map.Entry<String, String> entry : params.entrySet()) {
mapParams.put(entry.getKey(), entry.getValue()); this.mapParams.put(entry.getKey(), entry.getValue());
} }
hostCard = host; this.hostCard = host;
} }
// apply the ability if it has the right mode // apply the ability if it has the right mode
@@ -211,11 +207,11 @@ public class StaticAbility {
public final void applyAbility(final String mode) { public final void applyAbility(final String mode) {
// don't apply the ability if it hasn't got the right mode // don't apply the ability if it hasn't got the right mode
if (!mapParams.get("Mode").equals(mode)) { if (!this.mapParams.get("Mode").equals(mode)) {
return; return;
} }
if (isSuppressed() || !checkConditions()) { if (this.isSuppressed() || !this.checkConditions()) {
return; return;
} }
@@ -240,15 +236,15 @@ public class StaticAbility {
* the b * the b
* @return the int * @return the int
*/ */
public final int applyAbility(final String mode, final Card source, public final int applyAbility(final String mode, final Card source, final GameEntity target, final int in,
final GameEntity target, final int in, final boolean b) { final boolean b) {
// don't apply the ability if it hasn't got the right mode // don't apply the ability if it hasn't got the right mode
if (!mapParams.get("Mode").equals(mode)) { if (!this.mapParams.get("Mode").equals(mode)) {
return in; return in;
} }
if (isSuppressed() || !checkConditions()) { if (this.isSuppressed() || !this.checkConditions()) {
return in; return in;
} }
@@ -274,11 +270,11 @@ public class StaticAbility {
public final boolean applyAbility(final String mode, final Card card, final Player activator) { public final boolean applyAbility(final String mode, final Card card, final Player activator) {
// don't apply the ability if it hasn't got the right mode // don't apply the ability if it hasn't got the right mode
if (!mapParams.get("Mode").equals(mode)) { if (!this.mapParams.get("Mode").equals(mode)) {
return false; return false;
} }
if (isSuppressed() || !checkConditions()) { if (this.isSuppressed() || !this.checkConditions()) {
return false; return false;
} }
@@ -299,42 +295,42 @@ public class StaticAbility {
* @return true, if successful * @return true, if successful
*/ */
public final boolean checkConditions() { public final boolean checkConditions() {
Player controller = hostCard.getController(); final Player controller = this.hostCard.getController();
Zone effectZone = Zone.Battlefield; // default Zone effectZone = Zone.Battlefield; // default
if (mapParams.containsKey("EffectZone")) { if (this.mapParams.containsKey("EffectZone")) {
effectZone = Zone.smartValueOf(mapParams.get("EffectZone")); effectZone = Zone.smartValueOf(this.mapParams.get("EffectZone"));
} }
if (effectZone != null if ((effectZone != null)
&& (!AllZone.getZoneOf(hostCard).getZoneType().equals(effectZone) || hostCard.isPhasedOut())) { && (!AllZone.getZoneOf(this.hostCard).getZoneType().equals(effectZone) || this.hostCard.isPhasedOut())) {
return false; return false;
} }
if (mapParams.containsKey("Threshold") && !controller.hasThreshold()) { if (this.mapParams.containsKey("Threshold") && !controller.hasThreshold()) {
return false; return false;
} }
if (mapParams.containsKey("Hellbent") && !controller.hasHellbent()) { if (this.mapParams.containsKey("Hellbent") && !controller.hasHellbent()) {
return false; return false;
} }
if (mapParams.containsKey("Metalcraft") && !controller.hasMetalcraft()) { if (this.mapParams.containsKey("Metalcraft") && !controller.hasMetalcraft()) {
return false; return false;
} }
if (mapParams.containsKey("PlayerTurn") && !AllZone.getPhase().isPlayerTurn(controller)) { if (this.mapParams.containsKey("PlayerTurn") && !AllZone.getPhase().isPlayerTurn(controller)) {
return false; return false;
} }
if (mapParams.containsKey("OpponentTurn") && !AllZone.getPhase().isPlayerTurn(controller.getOpponent())) { if (this.mapParams.containsKey("OpponentTurn") && !AllZone.getPhase().isPlayerTurn(controller.getOpponent())) {
return false; return false;
} }
if (mapParams.containsKey("TopCardOfLibraryIs")) { if (this.mapParams.containsKey("TopCardOfLibraryIs")) {
Card topCard = controller.getCardsIn(Zone.Library).get(0); final Card topCard = controller.getCardsIn(Zone.Library).get(0);
if (!topCard.isValid(mapParams.get("TopCardOfLibraryIs").split(","), controller, hostCard)) { if (!topCard.isValid(this.mapParams.get("TopCardOfLibraryIs").split(","), controller, this.hostCard)) {
return false; return false;
} }
} }
@@ -350,15 +346,15 @@ public class StaticAbility {
* } * }
*/ */
if (mapParams.containsKey("CheckSVar")) { if (this.mapParams.containsKey("CheckSVar")) {
int sVar = AbilityFactory.calculateAmount(hostCard, mapParams.get("CheckSVar"), null); final int sVar = AbilityFactory.calculateAmount(this.hostCard, this.mapParams.get("CheckSVar"), null);
String comparator = "GE1"; String comparator = "GE1";
if (mapParams.containsKey("SVarCompare")) { if (this.mapParams.containsKey("SVarCompare")) {
comparator = mapParams.get("SVarCompare"); comparator = this.mapParams.get("SVarCompare");
} }
String svarOperator = comparator.substring(0, 2); final String svarOperator = comparator.substring(0, 2);
String svarOperand = comparator.substring(2); final String svarOperand = comparator.substring(2);
int operandValue = AbilityFactory.calculateAmount(hostCard, svarOperand, null); final int operandValue = AbilityFactory.calculateAmount(this.hostCard, svarOperand, null);
if (!AllZoneUtil.compare(sVar, svarOperator, operandValue)) { if (!AllZoneUtil.compare(sVar, svarOperator, operandValue)) {
return false; return false;
} }
@@ -374,7 +370,7 @@ public class StaticAbility {
* the new temporarily suppressed * the new temporarily suppressed
*/ */
public final void setTemporarilySuppressed(final boolean supp) { public final void setTemporarilySuppressed(final boolean supp) {
temporarilySuppressed = supp; this.temporarilySuppressed = supp;
} }
/** /**
@@ -383,7 +379,7 @@ public class StaticAbility {
* @return true, if is suppressed * @return true, if is suppressed
*/ */
public final boolean isSuppressed() { public final boolean isSuppressed() {
return (suppressed || temporarilySuppressed); return (this.suppressed || this.temporarilySuppressed);
} }
} // end class StaticEffectFactory } // end class StaticEffectFactory

View File

@@ -23,20 +23,20 @@ public class StaticAbility_CantBeCast {
* @return true, if successful * @return true, if successful
*/ */
public static boolean applyCantBeCastAbility(final StaticAbility stAb, final Card card, final Player activator) { public static boolean applyCantBeCastAbility(final StaticAbility stAb, final Card card, final Player activator) {
HashMap<String, String> params = stAb.getMapParams(); final HashMap<String, String> params = stAb.getMapParams();
Card hostCard = stAb.getHostCard(); final Card hostCard = stAb.getHostCard();
if (params.containsKey("ValidCard") if (params.containsKey("ValidCard")
&& !card.isValid(params.get("ValidCard").split(","), hostCard.getController(), hostCard)) { && !card.isValid(params.get("ValidCard").split(","), hostCard.getController(), hostCard)) {
return false; return false;
} }
if (params.containsKey("Caster") && activator != null if (params.containsKey("Caster") && (activator != null)
&& !activator.isValid(params.get("Caster"), hostCard.getController(), hostCard)) { && !activator.isValid(params.get("Caster"), hostCard.getController(), hostCard)) {
return false; return false;
} }
if (params.containsKey("OnlySorcerySpeed") && activator != null && Phase.canCastSorcery(activator)) { if (params.containsKey("OnlySorcerySpeed") && (activator != null) && Phase.canCastSorcery(activator)) {
return false; return false;
} }
@@ -54,17 +54,16 @@ public class StaticAbility_CantBeCast {
* the activator * the activator
* @return true, if successful * @return true, if successful
*/ */
public static boolean applyCantBeActivatedAbility(final StaticAbility stAb, public static boolean applyCantBeActivatedAbility(final StaticAbility stAb, final Card card, final Player activator) {
final Card card, final Player activator) { final HashMap<String, String> params = stAb.getMapParams();
HashMap<String, String> params = stAb.getMapParams(); final Card hostCard = stAb.getHostCard();
Card hostCard = stAb.getHostCard();
if (params.containsKey("ValidCard") if (params.containsKey("ValidCard")
&& !card.isValid(params.get("ValidCard").split(","), hostCard.getController(), hostCard)) { && !card.isValid(params.get("ValidCard").split(","), hostCard.getController(), hostCard)) {
return false; return false;
} }
if (params.containsKey("Activator") && activator != null if (params.containsKey("Activator") && (activator != null)
&& !activator.isValid(params.get("Activator"), hostCard.getController(), hostCard)) { && !activator.isValid(params.get("Activator"), hostCard.getController(), hostCard)) {
return false; return false;
} }

View File

@@ -31,12 +31,12 @@ public class StaticAbility_Continuous {
* a StaticAbility * a StaticAbility
*/ */
public static void applyContinuousAbility(final StaticAbility stAb) { public static void applyContinuousAbility(final StaticAbility stAb) {
HashMap<String, String> params = stAb.getMapParams(); final HashMap<String, String> params = stAb.getMapParams();
Card hostCard = stAb.getHostCard(); final Card hostCard = stAb.getHostCard();
StaticEffect se = new StaticEffect(); final StaticEffect se = new StaticEffect();
CardList affectedCards = getAffectedCards(stAb); final CardList affectedCards = StaticAbility_Continuous.getAffectedCards(stAb);
ArrayList<Player> affectedPlayers = getAffectedPlayers(stAb); final ArrayList<Player> affectedPlayers = StaticAbility_Continuous.getAffectedPlayers(stAb);
se.setAffectedCards(affectedCards); se.setAffectedCards(affectedCards);
se.setAffectedPlayers(affectedPlayers); se.setAffectedPlayers(affectedPlayers);
@@ -118,7 +118,7 @@ public class StaticAbility_Continuous {
} }
if (params.containsKey("AddAbility")) { if (params.containsKey("AddAbility")) {
String[] sVars = params.get("AddAbility").split(" & "); final String[] sVars = params.get("AddAbility").split(" & ");
for (int i = 0; i < sVars.length; i++) { for (int i = 0; i < sVars.length; i++) {
sVars[i] = hostCard.getSVar(sVars[i]); sVars[i] = hostCard.getSVar(sVars[i]);
} }
@@ -132,7 +132,7 @@ public class StaticAbility_Continuous {
if (params.containsKey("AddType")) { if (params.containsKey("AddType")) {
addTypes = params.get("AddType").split(" & "); addTypes = params.get("AddType").split(" & ");
if (addTypes[0].equals("ChosenType")) { if (addTypes[0].equals("ChosenType")) {
String chosenType = hostCard.getChosenType(); final String chosenType = hostCard.getChosenType();
addTypes[0] = chosenType; addTypes[0] = chosenType;
se.setChosenType(chosenType); se.setChosenType(chosenType);
} }
@@ -141,7 +141,7 @@ public class StaticAbility_Continuous {
if (params.containsKey("RemoveType")) { if (params.containsKey("RemoveType")) {
removeTypes = params.get("RemoveType").split(" & "); removeTypes = params.get("RemoveType").split(" & ");
if (removeTypes[0].equals("ChosenType")) { if (removeTypes[0].equals("ChosenType")) {
String chosenType = hostCard.getChosenType(); final String chosenType = hostCard.getChosenType();
removeTypes[0] = chosenType; removeTypes[0] = chosenType;
se.setChosenType(chosenType); se.setChosenType(chosenType);
} }
@@ -175,7 +175,7 @@ public class StaticAbility_Continuous {
} }
if (params.containsKey("AddTrigger")) { if (params.containsKey("AddTrigger")) {
String[] sVars = params.get("AddTrigger").split(" & "); final String[] sVars = params.get("AddTrigger").split(" & ");
for (int i = 0; i < sVars.length; i++) { for (int i = 0; i < sVars.length; i++) {
sVars[i] = hostCard.getSVar(sVars[i]); sVars[i] = hostCard.getSVar(sVars[i]);
} }
@@ -183,11 +183,11 @@ public class StaticAbility_Continuous {
} }
// modify players // modify players
for (Player p : affectedPlayers) { for (final Player p : affectedPlayers) {
// add keywords // add keywords
if (addKeywords != null) { if (addKeywords != null) {
for (String keyword : addKeywords) { for (final String keyword : addKeywords) {
p.addKeyword(keyword); p.addKeyword(keyword);
} }
} }
@@ -195,7 +195,7 @@ public class StaticAbility_Continuous {
// start modifying the cards // start modifying the cards
for (int i = 0; i < affectedCards.size(); i++) { for (int i = 0; i < affectedCards.size(); i++) {
Card affectedCard = affectedCards.get(i); final Card affectedCard = affectedCards.get(i);
// set P/T // set P/T
if (params.containsKey("CharacteristicDefining")) { if (params.containsKey("CharacteristicDefining")) {
@@ -206,7 +206,7 @@ public class StaticAbility_Continuous {
affectedCard.setBaseDefense(setToughness); affectedCard.setBaseDefense(setToughness);
} }
} else // non CharacteristicDefining } else // non CharacteristicDefining
if (setPower != -1 || setToughness != -1) { if ((setPower != -1) || (setToughness != -1)) {
if (setP.startsWith("AffectedX")) { if (setP.startsWith("AffectedX")) {
setPower = CardFactoryUtil.xCount(affectedCard, hostCard.getSVar(setP)); setPower = CardFactoryUtil.xCount(affectedCard, hostCard.getSVar(setP));
} }
@@ -221,24 +221,24 @@ public class StaticAbility_Continuous {
affectedCard.addSemiPermanentDefenseBoost(toughnessBonus); affectedCard.addSemiPermanentDefenseBoost(toughnessBonus);
// add keywords // add keywords
if (addKeywords != null || removeKeywords != null || removeAllAbilities) { if ((addKeywords != null) || (removeKeywords != null) || removeAllAbilities) {
affectedCard.addChangedCardKeywords(addKeywords, removeKeywords, removeAllAbilities, affectedCard.addChangedCardKeywords(addKeywords, removeKeywords, removeAllAbilities,
hostCard.getTimestamp()); hostCard.getTimestamp());
} }
// add HIDDEN keywords // add HIDDEN keywords
if (addHiddenKeywords != null) { if (addHiddenKeywords != null) {
for (String k : addHiddenKeywords) { for (final String k : addHiddenKeywords) {
affectedCard.addExtrinsicKeyword(k); affectedCard.addExtrinsicKeyword(k);
} }
} }
// add abilities // add abilities
if (addAbilities != null) { if (addAbilities != null) {
for (String abilty : addAbilities) { for (final String abilty : addAbilities) {
if (abilty.startsWith("AB")) { // grant the ability if (abilty.startsWith("AB")) { // grant the ability
AbilityFactory af = new AbilityFactory(); final AbilityFactory af = new AbilityFactory();
SpellAbility sa = af.getAbility(abilty, affectedCard); final SpellAbility sa = af.getAbility(abilty, affectedCard);
sa.setType("Temporary"); sa.setType("Temporary");
affectedCard.addSpellAbility(sa); affectedCard.addSpellAbility(sa);
} }
@@ -247,47 +247,47 @@ public class StaticAbility_Continuous {
// add SVars // add SVars
if (addSVars != null) { if (addSVars != null) {
for (String sVar : addSVars) { for (final String sVar : addSVars) {
affectedCard.setSVar(sVar, hostCard.getSVar(sVar)); affectedCard.setSVar(sVar, hostCard.getSVar(sVar));
} }
} }
// add Types // add Types
if (addTypes != null || removeTypes != null) { if ((addTypes != null) || (removeTypes != null)) {
affectedCard.addChangedCardTypes(addTypes, removeTypes, removeSuperTypes, removeCardTypes, affectedCard.addChangedCardTypes(addTypes, removeTypes, removeSuperTypes, removeCardTypes,
removeSubTypes, removeCreatureTypes, hostCard.getTimestamp()); removeSubTypes, removeCreatureTypes, hostCard.getTimestamp());
} }
// add colors // add colors
if (addColors != null) { if (addColors != null) {
long t = affectedCard.addColor(addColors, affectedCard, !se.isOverwriteColors(), true); final long t = affectedCard.addColor(addColors, affectedCard, !se.isOverwriteColors(), true);
se.addTimestamp(affectedCard, t); se.addTimestamp(affectedCard, t);
} }
// add triggers // add triggers
if (addTriggers != null) { if (addTriggers != null) {
for (String trigger : addTriggers) { for (final String trigger : addTriggers) {
Trigger actualTrigger = TriggerHandler.parseTrigger(trigger, affectedCard, false); final Trigger actualTrigger = TriggerHandler.parseTrigger(trigger, affectedCard, false);
affectedCard.addTrigger(actualTrigger).setTemporary(true); affectedCard.addTrigger(actualTrigger).setTemporary(true);
} }
} }
// remove triggers // remove triggers
if (params.containsKey("RemoveTriggers") || removeAllAbilities) { if (params.containsKey("RemoveTriggers") || removeAllAbilities) {
ArrayList<Trigger> triggers = affectedCard.getTriggers(); final ArrayList<Trigger> triggers = affectedCard.getTriggers();
for (Trigger trigger : triggers) { for (final Trigger trigger : triggers) {
trigger.setTemporarilySuppressed(true); trigger.setTemporarilySuppressed(true);
} }
} }
// remove activated and static abilities // remove activated and static abilities
if (removeAllAbilities) { if (removeAllAbilities) {
ArrayList<SpellAbility> abilities = affectedCard.getSpellAbilities(); final ArrayList<SpellAbility> abilities = affectedCard.getSpellAbilities();
for (SpellAbility ab : abilities) { for (final SpellAbility ab : abilities) {
ab.setTemporarilySuppressed(true); ab.setTemporarilySuppressed(true);
} }
ArrayList<StaticAbility> staticAbilities = affectedCard.getStaticAbilities(); final ArrayList<StaticAbility> staticAbilities = affectedCard.getStaticAbilities();
for (StaticAbility stA : staticAbilities) { for (final StaticAbility stA : staticAbilities) {
stA.setTemporarilySuppressed(true); stA.setTemporarilySuppressed(true);
} }
} }
@@ -295,19 +295,19 @@ public class StaticAbility_Continuous {
} }
private static ArrayList<Player> getAffectedPlayers(final StaticAbility stAb) { private static ArrayList<Player> getAffectedPlayers(final StaticAbility stAb) {
HashMap<String, String> params = stAb.getMapParams(); final HashMap<String, String> params = stAb.getMapParams();
Card hostCard = stAb.getHostCard(); final Card hostCard = stAb.getHostCard();
Player controller = hostCard.getController(); final Player controller = hostCard.getController();
ArrayList<Player> players = new ArrayList<Player>(); final ArrayList<Player> players = new ArrayList<Player>();
if (!params.containsKey("Affected")) { if (!params.containsKey("Affected")) {
return players; return players;
} }
String[] strngs = params.get("Affected").split(","); final String[] strngs = params.get("Affected").split(",");
for (String str : strngs) { for (final String str : strngs) {
if (str.equals("Player") || str.equals("You")) { if (str.equals("Player") || str.equals("You")) {
players.add(controller); players.add(controller);
} }
@@ -321,9 +321,9 @@ public class StaticAbility_Continuous {
} }
private static CardList getAffectedCards(final StaticAbility stAb) { private static CardList getAffectedCards(final StaticAbility stAb) {
HashMap<String, String> params = stAb.getMapParams(); final HashMap<String, String> params = stAb.getMapParams();
Card hostCard = stAb.getHostCard(); final Card hostCard = stAb.getHostCard();
Player controller = hostCard.getController(); final Player controller = hostCard.getController();
if (params.containsKey("CharacteristicDefining")) { if (params.containsKey("CharacteristicDefining")) {
return new CardList(hostCard); // will always be the card itself return new CardList(hostCard); // will always be the card itself

View File

@@ -26,11 +26,10 @@ public class StaticAbility_PreventDamage {
* the is combat * the is combat
* @return the int * @return the int
*/ */
public static int applyPreventDamageAbility(final StaticAbility stAb, public static int applyPreventDamageAbility(final StaticAbility stAb, final Card source, final GameEntity target,
final Card source, final GameEntity target, final int damage, final int damage, final boolean isCombat) {
final boolean isCombat) { final HashMap<String, String> params = stAb.getMapParams();
HashMap<String, String> params = stAb.getMapParams(); final Card hostCard = stAb.getHostCard();
Card hostCard = stAb.getHostCard();
int restDamage = damage; int restDamage = damage;
if (params.containsKey("Source") if (params.containsKey("Source")
@@ -51,7 +50,7 @@ public class StaticAbility_PreventDamage {
return restDamage; return restDamage;
} }
if (params.containsKey("MaxDamage") && Integer.parseInt(params.get("MaxDamage")) < damage) { if (params.containsKey("MaxDamage") && (Integer.parseInt(params.get("MaxDamage")) < damage)) {
return restDamage; return restDamage;
} }

View File

@@ -47,8 +47,8 @@ public final class Deck implements Comparable<Deck>, Serializable {
* </p> * </p>
*/ */
public Deck() { public Deck() {
main = new ItemPool<CardPrinted>(CardPrinted.class); this.main = new ItemPool<CardPrinted>(CardPrinted.class);
sideboard = new ItemPool<CardPrinted>(CardPrinted.class); this.sideboard = new ItemPool<CardPrinted>(CardPrinted.class);
} }
/** /**
@@ -61,7 +61,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
*/ */
public Deck(final GameType type) { public Deck(final GameType type) {
this(); this();
setDeckType(type); this.setDeckType(type);
} }
/** /**
@@ -72,7 +72,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return a {@link java.util.List} object. * @return a {@link java.util.List} object.
*/ */
public ItemPoolView<CardPrinted> getMain() { public ItemPoolView<CardPrinted> getMain() {
return main.getView(); return this.main.getView();
} }
/** /**
@@ -83,7 +83,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return a {@link java.util.List} object. * @return a {@link java.util.List} object.
*/ */
public ItemPoolView<CardPrinted> getSideboard() { public ItemPoolView<CardPrinted> getSideboard() {
return sideboard.getView(); return this.sideboard.getView();
} }
/** /**
@@ -94,7 +94,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public GameType getDeckType() { public GameType getDeckType() {
return deckType; return this.deckType;
} }
// can only call this method ONCE // can only call this method ONCE
@@ -123,7 +123,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public void setName(final String s) { public void setName(final String s) {
name = s; this.name = s;
} }
/** /**
@@ -134,7 +134,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public String getName() { public String getName() {
return name; return this.name;
} }
/** /**
@@ -157,7 +157,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public String getComment() { public String getComment() {
return comment; return this.comment;
} }
/** /**
@@ -169,7 +169,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public void addMain(final String cardName) { public void addMain(final String cardName) {
addMain(CardDb.instance().getCard(cardName)); this.addMain(CardDb.instance().getCard(cardName));
} }
/** /**
@@ -179,7 +179,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the card * the card
*/ */
public void addMain(final CardPrinted card) { public void addMain(final CardPrinted card) {
main.add(card); this.main.add(card);
} }
/** /**
@@ -191,7 +191,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the amount * the amount
*/ */
public void addMain(final CardPrinted card, final int amount) { public void addMain(final CardPrinted card, final int amount) {
main.add(card, amount); this.main.add(card, amount);
} }
/** /**
@@ -201,7 +201,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the list * the list
*/ */
public void addMain(final ItemPoolView<CardPrinted> list) { public void addMain(final ItemPoolView<CardPrinted> list) {
main.addAll(list); this.main.addAll(list);
} }
/** /**
@@ -211,7 +211,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the new main * the new main
*/ */
public void setMain(final Iterable<String> cards) { public void setMain(final Iterable<String> cards) {
main = new ItemPool<CardPrinted>(cards, CardPrinted.class); this.main = new ItemPool<CardPrinted>(cards, CardPrinted.class);
} }
/** /**
@@ -221,7 +221,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the card * the card
*/ */
public void removeMain(final CardPrinted card) { public void removeMain(final CardPrinted card) {
main.remove(card); this.main.remove(card);
} }
/** /**
@@ -233,7 +233,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the amount * the amount
*/ */
public void removeMain(final CardPrinted card, final int amount) { public void removeMain(final CardPrinted card, final int amount) {
main.remove(card, amount); this.main.remove(card, amount);
} }
/** /**
@@ -242,7 +242,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return the int * @return the int
*/ */
public int countMain() { public int countMain() {
return main.countAll(); return this.main.countAll();
} }
/** /**
@@ -254,7 +254,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public void addSideboard(final String cardName) { public void addSideboard(final String cardName) {
addSideboard(CardDb.instance().getCard(cardName)); this.addSideboard(CardDb.instance().getCard(cardName));
} }
/** /**
@@ -264,7 +264,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the card * the card
*/ */
public void addSideboard(final CardPrinted card) { public void addSideboard(final CardPrinted card) {
sideboard.add(card); this.sideboard.add(card);
} }
/** /**
@@ -276,7 +276,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the amount * the amount
*/ */
public void addSideboard(final CardPrinted card, final int amount) { public void addSideboard(final CardPrinted card, final int amount) {
sideboard.add(card, amount); this.sideboard.add(card, amount);
} }
/** /**
@@ -286,7 +286,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the cards * the cards
*/ */
public void addSideboard(final ItemPoolView<CardPrinted> cards) { public void addSideboard(final ItemPoolView<CardPrinted> cards) {
sideboard.addAll(cards); this.sideboard.addAll(cards);
} }
/** /**
@@ -296,7 +296,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the new sideboard * the new sideboard
*/ */
public void setSideboard(final Iterable<String> cards) { public void setSideboard(final Iterable<String> cards) {
sideboard = new ItemPool<CardPrinted>(cards, CardPrinted.class); this.sideboard = new ItemPool<CardPrinted>(cards, CardPrinted.class);
} }
/** /**
@@ -307,7 +307,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return a int. * @return a int.
*/ */
public int countSideboard() { public int countSideboard() {
return sideboard.countAll(); return this.sideboard.countAll();
} }
/** /**
@@ -320,7 +320,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* *
*/ */
public void removeFromSideboard(final CardPrinted card) { public void removeFromSideboard(final CardPrinted card) {
sideboard.remove(card); this.sideboard.remove(card);
} }
/** /**
@@ -331,7 +331,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return a boolean. * @return a boolean.
*/ */
public boolean isDraft() { public boolean isDraft() {
return getDeckType().equals(GameType.Draft); return this.getDeckType().equals(GameType.Draft);
} }
/** /**
@@ -342,7 +342,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return a boolean. * @return a boolean.
*/ */
public boolean isSealed() { public boolean isSealed() {
return getDeckType().equals(GameType.Sealed); return this.getDeckType().equals(GameType.Sealed);
} }
/** /**
@@ -353,7 +353,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return a boolean. * @return a boolean.
*/ */
public boolean isRegular() { public boolean isRegular() {
return getDeckType().equals(GameType.Constructed); return this.getDeckType().equals(GameType.Constructed);
} }
/** /**
@@ -363,14 +363,15 @@ public final class Deck implements Comparable<Deck>, Serializable {
* *
* @return a int. * @return a int.
*/ */
@Override
public int hashCode() { public int hashCode() {
return getName().hashCode(); return this.getName().hashCode();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public String toString() { public String toString() {
return getName(); return this.getName();
} }
/** /**
@@ -382,15 +383,17 @@ public final class Deck implements Comparable<Deck>, Serializable {
* a {@link forge.deck.Deck} object. * a {@link forge.deck.Deck} object.
* @return a int. * @return a int.
*/ */
@Override
public int compareTo(final Deck d) { public int compareTo(final Deck d) {
return getName().compareTo(d.getName()); return this.getName().compareTo(d.getName());
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (o instanceof Deck) { if (o instanceof Deck) {
Deck d = (Deck) o; final Deck d = (Deck) o;
return getName().equals(d.getName()); return this.getName().equals(d.getName());
} }
return false; return false;
} }
@@ -399,14 +402,14 @@ public final class Deck implements Comparable<Deck>, Serializable {
* Clear sideboard. * Clear sideboard.
*/ */
public void clearSideboard() { public void clearSideboard() {
sideboard.clear(); this.sideboard.clear();
} }
/** /**
* Clear main. * Clear main.
*/ */
public void clearMain() { public void clearMain() {
main.clear(); this.main.clear();
} }
@@ -416,7 +419,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return the player type * @return the player type
*/ */
public PlayerType getPlayerType() { public PlayerType getPlayerType() {
return playerType; return this.playerType;
} }
/** /**
@@ -435,7 +438,7 @@ public final class Deck implements Comparable<Deck>, Serializable {
* @return true, if is custom pool * @return true, if is custom pool
*/ */
public boolean isCustomPool() { public boolean isCustomPool() {
return customPool; return this.customPool;
} }
/** /**
@@ -445,6 +448,6 @@ public final class Deck implements Comparable<Deck>, Serializable {
* the new custom pool * the new custom pool
*/ */
public void setCustomPool(final boolean cp) { public void setCustomPool(final boolean cp) {
customPool = cp; this.customPool = cp;
} }
} }

View File

@@ -35,7 +35,7 @@ public abstract class DeckGeneration {
// TODO jendave to refactor deck generation // TODO jendave to refactor deck generation
Deck d = null; Deck d = null;
ArrayList<String> decks = new ArrayList<String>(); final ArrayList<String> decks = new ArrayList<String>();
decks.add("2-Color Deck"); decks.add("2-Color Deck");
decks.add("3-Color Deck"); decks.add("3-Color Deck");
decks.add("5-Color Deck"); decks.add("5-Color Deck");
@@ -44,25 +44,25 @@ public abstract class DeckGeneration {
decks.add("5-Color Deck (original)"); decks.add("5-Color Deck (original)");
decks.add("Semi-Random Theme Deck"); decks.add("Semi-Random Theme Deck");
String playerName = playerType.equals(PlayerType.HUMAN) ? "Human" : "Computer"; final String playerName = playerType.equals(PlayerType.HUMAN) ? "Human" : "Computer";
String prompt = String.format("Generate %s Deck", playerName); final String prompt = String.format("Generate %s Deck", playerName);
Object o = GuiUtils.getChoice(prompt, decks.toArray()); final Object o = GuiUtils.getChoice(prompt, decks.toArray());
if (o.toString().equals(decks.get(0))) { if (o.toString().equals(decks.get(0))) {
d = generate2ColorDeck(playerType); d = DeckGeneration.generate2ColorDeck(playerType);
} else if (o.toString().equals(decks.get(1))) { } else if (o.toString().equals(decks.get(1))) {
d = generate3ColorDeck(playerType); d = DeckGeneration.generate3ColorDeck(playerType);
} else if (o.toString().equals(decks.get(2))) { } else if (o.toString().equals(decks.get(2))) {
d = generate5ColorDeck(playerType); d = DeckGeneration.generate5ColorDeck(playerType);
} else if (o.toString().equals(decks.get(3))) { } else if (o.toString().equals(decks.get(3))) {
d = generateConstructedDeck(); d = DeckGeneration.generateConstructedDeck();
} else if (o.toString().equals(decks.get(4))) { } else if (o.toString().equals(decks.get(4))) {
d = generateConstructed3ColorDeck(); d = DeckGeneration.generateConstructed3ColorDeck();
} else if (o.toString().equals(decks.get(5))) { } else if (o.toString().equals(decks.get(5))) {
d = generateConstructed5ColorDeck(); d = DeckGeneration.generateConstructed5ColorDeck();
} else if (o.toString().equals(decks.get(6))) { } else if (o.toString().equals(decks.get(6))) {
d = generateConstructedThemeDeck(); d = DeckGeneration.generateConstructedThemeDeck();
} }
if (playerType.equals(PlayerType.HUMAN)) { if (playerType.equals(PlayerType.HUMAN)) {
@@ -80,9 +80,9 @@ public abstract class DeckGeneration {
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
private static Deck generateConstructedDeck() { private static Deck generateConstructedDeck() {
GenerateConstructedDeck gen = new GenerateConstructedDeck(); final GenerateConstructedDeck gen = new GenerateConstructedDeck();
CardList name = gen.generateDeck(); final CardList name = gen.generateDeck();
Deck deck = new Deck(GameType.Constructed); final Deck deck = new Deck(GameType.Constructed);
for (int i = 0; i < 60; i++) { for (int i = 0; i < 60; i++) {
deck.addMain(name.get(i).getName()); deck.addMain(name.get(i).getName());
@@ -98,9 +98,9 @@ public abstract class DeckGeneration {
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
private static Deck generateConstructed3ColorDeck() { private static Deck generateConstructed3ColorDeck() {
GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck(); final GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
CardList name = gen.generate3ColorDeck(); final CardList name = gen.generate3ColorDeck();
Deck deck = new Deck(GameType.Constructed); final Deck deck = new Deck(GameType.Constructed);
for (int i = 0; i < 60; i++) { for (int i = 0; i < 60; i++) {
deck.addMain(name.get(i).getName()); deck.addMain(name.get(i).getName());
@@ -116,9 +116,9 @@ public abstract class DeckGeneration {
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
private static Deck generateConstructed5ColorDeck() { private static Deck generateConstructed5ColorDeck() {
GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck(); final GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
CardList name = gen.generate5ColorDeck(); final CardList name = gen.generate5ColorDeck();
Deck deck = new Deck(GameType.Constructed); final Deck deck = new Deck(GameType.Constructed);
for (int i = 0; i < 60; i++) { for (int i = 0; i < 60; i++) {
deck.addMain(name.get(i).getName()); deck.addMain(name.get(i).getName());
@@ -134,21 +134,21 @@ public abstract class DeckGeneration {
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
private static Deck generateConstructedThemeDeck() { private static Deck generateConstructedThemeDeck() {
GenerateThemeDeck gen = new GenerateThemeDeck(); final GenerateThemeDeck gen = new GenerateThemeDeck();
ArrayList<String> tNames = gen.getThemeNames(); final ArrayList<String> tNames = gen.getThemeNames();
tNames.add(0, "Random"); tNames.add(0, "Random");
Object o = GuiUtils.getChoice("Select a theme.", tNames.toArray()); final Object o = GuiUtils.getChoice("Select a theme.", tNames.toArray());
String stDeck; String stDeck;
if (o.toString().equals("Random")) { if (o.toString().equals("Random")) {
Random r = MyRandom.getRandom(); final Random r = MyRandom.getRandom();
stDeck = tNames.get(r.nextInt(tNames.size() - 1) + 1); stDeck = tNames.get(r.nextInt(tNames.size() - 1) + 1);
} else { } else {
stDeck = o.toString(); stDeck = o.toString();
} }
CardList td = gen.getThemeDeck(stDeck, 60); final CardList td = gen.getThemeDeck(stDeck, 60);
Deck deck = new Deck(GameType.Constructed); final Deck deck = new Deck(GameType.Constructed);
for (int i = 0; i < td.size(); i++) { for (int i = 0; i < td.size(); i++) {
deck.addMain(td.get(i).getName()); deck.addMain(td.get(i).getName());
@@ -167,9 +167,9 @@ public abstract class DeckGeneration {
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
private static Deck generate2ColorDeck(final PlayerType p) { private static Deck generate2ColorDeck(final PlayerType p) {
Random r = MyRandom.getRandom(); final Random r = MyRandom.getRandom();
ArrayList<String> colors = new ArrayList<String>(); final ArrayList<String> colors = new ArrayList<String>();
colors.add("Random"); colors.add("Random");
colors.add("white"); colors.add("white");
colors.add("blue"); colors.add("blue");
@@ -199,10 +199,10 @@ public abstract class DeckGeneration {
colors.remove(c1); colors.remove(c1);
c2 = colors.get(r.nextInt(colors.size() - 1) + 1); c2 = colors.get(r.nextInt(colors.size() - 1) + 1);
} }
Generate2ColorDeck gen = new Generate2ColorDeck(c1, c2); final Generate2ColorDeck gen = new Generate2ColorDeck(c1, c2);
CardList d = gen.get2ColorDeck(60, p); final CardList d = gen.get2ColorDeck(60, p);
Deck deck = new Deck(GameType.Constructed); final Deck deck = new Deck(GameType.Constructed);
for (int i = 0; i < d.size(); i++) { for (int i = 0; i < d.size(); i++) {
deck.addMain(d.get(i).getName()); deck.addMain(d.get(i).getName());
@@ -222,9 +222,9 @@ public abstract class DeckGeneration {
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
private static Deck generate3ColorDeck(final PlayerType p) { private static Deck generate3ColorDeck(final PlayerType p) {
Random r = MyRandom.getRandom(); final Random r = MyRandom.getRandom();
ArrayList<String> colors = new ArrayList<String>(); final ArrayList<String> colors = new ArrayList<String>();
colors.add("Random"); colors.add("Random");
colors.add("white"); colors.add("white");
colors.add("blue"); colors.add("blue");
@@ -265,10 +265,10 @@ public abstract class DeckGeneration {
colors.remove(c2); colors.remove(c2);
c3 = colors.get(r.nextInt(colors.size() - 1) + 1); c3 = colors.get(r.nextInt(colors.size() - 1) + 1);
} }
Generate3ColorDeck gen = new Generate3ColorDeck(c1, c2, c3); final Generate3ColorDeck gen = new Generate3ColorDeck(c1, c2, c3);
CardList d = gen.get3ColorDeck(60, p); final CardList d = gen.get3ColorDeck(60, p);
Deck deck = new Deck(GameType.Constructed); final Deck deck = new Deck(GameType.Constructed);
for (int i = 0; i < d.size(); i++) { for (int i = 0; i < d.size(); i++) {
deck.addMain(d.get(i).getName()); deck.addMain(d.get(i).getName());
@@ -298,10 +298,10 @@ public abstract class DeckGeneration {
// colors.add("red"); // colors.add("red");
// colors.add("green"); // colors.add("green");
Generate5ColorDeck gen = new Generate5ColorDeck("white", "blue", "black", "red", "green"); final Generate5ColorDeck gen = new Generate5ColorDeck("white", "blue", "black", "red", "green");
CardList d = gen.get5ColorDeck(60, p); final CardList d = gen.get5ColorDeck(60, p);
Deck deck = new Deck(GameType.Constructed); final Deck deck = new Deck(GameType.Constructed);
for (int i = 0; i < d.size(); i++) { for (int i = 0; i < d.size(); i++) {
deck.addMain(d.get(i).getName()); deck.addMain(d.get(i).getName());

View File

@@ -1,8 +1,5 @@
package forge.deck; package forge.deck;
import static java.lang.Integer.parseInt;
import static java.lang.String.format;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@@ -53,6 +50,7 @@ import freemarker.template.TemplateException;
public class DeckManager { public class DeckManager {
/** Constant <code>BDKFileFilter</code>. */ /** Constant <code>BDKFileFilter</code>. */
private static FilenameFilter bdkFileFilter = new FilenameFilter() { private static FilenameFilter bdkFileFilter = new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) { public boolean accept(final File dir, final String name) {
return name.endsWith(".bdk"); return name.endsWith(".bdk");
} }
@@ -60,6 +58,7 @@ public class DeckManager {
/** Constant <code>DCKFileFilter</code>. */ /** Constant <code>DCKFileFilter</code>. */
public static final FilenameFilter DCK_FILE_FILTER = new FilenameFilter() { public static final FilenameFilter DCK_FILE_FILTER = new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) { public boolean accept(final File dir, final String name) {
return name.endsWith(".dck"); return name.endsWith(".dck");
} }
@@ -125,9 +124,9 @@ public class DeckManager {
} }
this.deckMap = new HashMap<String, Deck>(); this.deckMap = new HashMap<String, Deck>();
this.draftMap = new HashMap<String, Deck[]>(); this.draftMap = new HashMap<String, Deck[]>();
readAllDecks(); this.readAllDecks();
} }
} catch (IOException ex) { } catch (final IOException ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage()); throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage());
} }
@@ -143,7 +142,7 @@ public class DeckManager {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isUnique(final String deckName) { public final boolean isUnique(final String deckName) {
return !deckMap.containsKey(deckName); return !this.deckMap.containsKey(deckName);
} }
/** /**
@@ -156,7 +155,7 @@ public class DeckManager {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isUniqueDraft(final String deckName) { public final boolean isUniqueDraft(final String deckName) {
return !draftMap.keySet().contains(deckName); return !this.draftMap.keySet().contains(deckName);
} }
/** /**
@@ -169,7 +168,7 @@ public class DeckManager {
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
public final Deck getDeck(final String deckName) { public final Deck getDeck(final String deckName) {
return deckMap.get(deckName); return this.deckMap.get(deckName);
} }
/** /**
@@ -185,7 +184,7 @@ public class DeckManager {
throw new RuntimeException("DeckManager : addDeck() error, deck type is Draft"); throw new RuntimeException("DeckManager : addDeck() error, deck type is Draft");
} }
deckMap.put(deck.getName(), deck); this.deckMap.put(deck.getName(), deck);
} }
/** /**
@@ -197,7 +196,7 @@ public class DeckManager {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public final void deleteDeck(final String deckName) { public final void deleteDeck(final String deckName) {
deckMap.remove(deckName); this.deckMap.remove(deckName);
} }
/** /**
@@ -210,11 +209,11 @@ public class DeckManager {
* @return an array of {@link forge.deck.Deck} objects. * @return an array of {@link forge.deck.Deck} objects.
*/ */
public final Deck[] getDraftDeck(final String deckName) { public final Deck[] getDraftDeck(final String deckName) {
if (!draftMap.containsKey(deckName)) { if (!this.draftMap.containsKey(deckName)) {
throw new RuntimeException("DeckManager : getDraftDeck() error, deck name not found - " + deckName); throw new RuntimeException("DeckManager : getDraftDeck() error, deck name not found - " + deckName);
} }
return draftMap.get(deckName); return this.draftMap.get(deckName);
} }
/** /**
@@ -226,9 +225,9 @@ public class DeckManager {
* an array of {@link forge.deck.Deck} objects. * an array of {@link forge.deck.Deck} objects.
*/ */
public final void addDraftDeck(final Deck[] deck) { public final void addDraftDeck(final Deck[] deck) {
checkDraftDeck(deck); this.checkDraftDeck(deck);
draftMap.put(deck[0].toString(), deck); this.draftMap.put(deck[0].toString(), deck);
} }
/** /**
@@ -240,13 +239,13 @@ public class DeckManager {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public final void deleteDraftDeck(final String deckName) { public final void deleteDraftDeck(final String deckName) {
if (!draftMap.containsKey(deckName)) { if (!this.draftMap.containsKey(deckName)) {
throw new RuntimeException("DeckManager : deleteDraftDeck() error, deck name not found - " + deckName); throw new RuntimeException("DeckManager : deleteDraftDeck() error, deck name not found - " + deckName);
} }
draftMap.remove(deckName); this.draftMap.remove(deckName);
// delete from disk as well // delete from disk as well
File f = makeFileName(deckName, GameType.Draft); final File f = DeckManager.makeFileName(deckName, GameType.Draft);
f.delete(); f.delete();
} }
@@ -259,7 +258,7 @@ public class DeckManager {
* an array of {@link forge.deck.Deck} objects. * an array of {@link forge.deck.Deck} objects.
*/ */
private void checkDraftDeck(final Deck[] deck) { private void checkDraftDeck(final Deck[] deck) {
if (deck == null || deck.length != 8 || deck[0].getName().equals("") if ((deck == null) || (deck.length != 8) || deck[0].getName().equals("")
|| (!deck[0].getDeckType().equals(GameType.Draft))) { || (!deck[0].getDeckType().equals(GameType.Draft))) {
throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck"); throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck");
} }
@@ -272,7 +271,7 @@ public class DeckManager {
* @return a Collection<Deck> * @return a Collection<Deck>
*/ */
public final Collection<Deck> getDecks() { public final Collection<Deck> getDecks() {
return deckMap.values(); return this.deckMap.values();
} }
/** /**
@@ -282,7 +281,7 @@ public class DeckManager {
* @return a Map<String, Deck[]> * @return a Map<String, Deck[]>
*/ */
public final Map<String, Deck[]> getDraftDecks() { public final Map<String, Deck[]> getDraftDecks() {
return new HashMap<String, Deck[]>(draftMap); return new HashMap<String, Deck[]>(this.draftMap);
} }
/** /**
@@ -294,15 +293,15 @@ public class DeckManager {
* @return a ArrayList<String> * @return a ArrayList<String>
*/ */
public final ArrayList<String> getDeckNames(final GameType deckType) { public final ArrayList<String> getDeckNames(final GameType deckType) {
ArrayList<String> list = new ArrayList<String>(); final ArrayList<String> list = new ArrayList<String>();
// only get decks according to the OldGuiNewGame screen option // only get decks according to the OldGuiNewGame screen option
if (deckType.equals(GameType.Draft)) { if (deckType.equals(GameType.Draft)) {
for (String s : getDraftDecks().keySet()) { for (final String s : this.getDraftDecks().keySet()) {
list.add(s); list.add(s);
} }
} else { } else {
for (Deck deck : getDecks()) { for (final Deck deck : this.getDecks()) {
if (deckType.equals(deck.getDeckType())) { if (deckType.equals(deck.getDeckType())) {
list.add(deck.toString()); list.add(deck.toString());
} }
@@ -319,19 +318,20 @@ public class DeckManager {
* </p> * </p>
*/ */
public final void readAllDecks() { public final void readAllDecks() {
deckMap.clear(); this.deckMap.clear();
draftMap.clear(); this.draftMap.clear();
File[] files; File[] files;
List<String> decksThatFailedToLoad = new ArrayList<String>(); final List<String> decksThatFailedToLoad = new ArrayList<String>();
files = deckDir.listFiles(DCK_FILE_FILTER); files = this.deckDir.listFiles(DeckManager.DCK_FILE_FILTER);
for (File file : files) { for (final File file : files) {
try { try {
Deck newDeck = readDeck(file); final Deck newDeck = DeckManager.readDeck(file);
deckMap.put(newDeck.getName(), newDeck); this.deckMap.put(newDeck.getName(), newDeck);
} catch (NoSuchElementException ex) { } catch (final NoSuchElementException ex) {
String message = String.format("%s failed to load because ---- %s", file.getName(), ex.getMessage()); final String message = String.format("%s failed to load because ---- %s", file.getName(),
ex.getMessage());
decksThatFailedToLoad.add(message); decksThatFailedToLoad.add(message);
} }
} }
@@ -342,13 +342,13 @@ public class DeckManager {
"Some of your decks were not loaded.", JOptionPane.WARNING_MESSAGE); "Some of your decks were not loaded.", JOptionPane.WARNING_MESSAGE);
} }
files = deckDir.listFiles(bdkFileFilter); files = this.deckDir.listFiles(DeckManager.bdkFileFilter);
for (File file : files) { for (final File file : files) {
Deck[] d = new Deck[8]; final Deck[] d = new Deck[8];
boolean gotError = false; boolean gotError = false;
for (int i = 0; i < d.length; i++) { for (int i = 0; i < d.length; i++) {
d[i] = readDeck(new File(file, i + ".dck")); d[i] = DeckManager.readDeck(new File(file, i + ".dck"));
if (d[i] == null) { if (d[i] == null) {
gotError = true; gotError = true;
break; break;
@@ -356,7 +356,7 @@ public class DeckManager {
} }
if (!gotError) { if (!gotError) {
draftMap.put(d[0].getName(), d); this.draftMap.put(d[0].getName(), d);
} }
} }
} }
@@ -372,28 +372,28 @@ public class DeckManager {
*/ */
public static Deck readDeck(final File deckFile) { public static Deck readDeck(final File deckFile) {
List<String> lines = FileUtil.readFile(deckFile); final List<String> lines = FileUtil.readFile(deckFile);
if (lines.isEmpty()) { if (lines.isEmpty()) {
return null; return null;
} }
Deck d = new Deck(); final Deck d = new Deck();
String firstLine = lines.get(0); final String firstLine = lines.get(0);
if (!firstLine.startsWith("[") || firstLine.equalsIgnoreCase("[general]")) { if (!firstLine.startsWith("[") || firstLine.equalsIgnoreCase("[general]")) {
readDeckOldMetadata(lines.iterator(), d); DeckManager.readDeckOldMetadata(lines.iterator(), d);
} else { } else {
readDeckMetadata(findSection(lines, "metadata"), d); DeckManager.readDeckMetadata(DeckManager.findSection(lines, "metadata"), d);
} }
d.setMain(readCardList(findSection(lines, "main"))); d.setMain(DeckManager.readCardList(DeckManager.findSection(lines, "main")));
d.setSideboard(readCardList(findSection(lines, "sideboard"))); d.setSideboard(DeckManager.readCardList(DeckManager.findSection(lines, "sideboard")));
return d; return d;
} }
private static Iterator<String> findSection(final Iterable<String> lines, final String sectionName) { private static Iterator<String> findSection(final Iterable<String> lines, final String sectionName) {
Iterator<String> lineIterator = lines.iterator(); final Iterator<String> lineIterator = lines.iterator();
String toSearch = String.format("[%s]", sectionName); final String toSearch = String.format("[%s]", sectionName);
while (lineIterator.hasNext()) { while (lineIterator.hasNext()) {
if (toSearch.equalsIgnoreCase(lineIterator.next())) { if (toSearch.equalsIgnoreCase(lineIterator.next())) {
break; break;
@@ -405,32 +405,32 @@ public class DeckManager {
private static void readDeckMetadata(final Iterator<String> lineIterator, final Deck d) { private static void readDeckMetadata(final Iterator<String> lineIterator, final Deck d) {
while (lineIterator.hasNext()) { while (lineIterator.hasNext()) {
String line = lineIterator.next(); final String line = lineIterator.next();
if (line.startsWith("[")) { if (line.startsWith("[")) {
break; break;
} }
String[] linedata = line.split("=", 2); final String[] linedata = line.split("=", 2);
String field = linedata[0].toLowerCase(); final String field = linedata[0].toLowerCase();
String value = ""; String value = "";
if (linedata.length > 1) { if (linedata.length > 1) {
value = linedata[1]; value = linedata[1];
} }
if (NAME.equalsIgnoreCase(field)) { if (DeckManager.NAME.equalsIgnoreCase(field)) {
d.setName(value); d.setName(value);
} else if (COMMENT.equalsIgnoreCase(field)) { } else if (DeckManager.COMMENT.equalsIgnoreCase(field)) {
d.setComment(value); d.setComment(value);
} else if (DECK_TYPE.equalsIgnoreCase(field)) { } else if (DeckManager.DECK_TYPE.equalsIgnoreCase(field)) {
d.setDeckType(GameType.smartValueOf(value)); d.setDeckType(GameType.smartValueOf(value));
} else if (CSTM_POOL.equalsIgnoreCase(field)) { } else if (DeckManager.CSTM_POOL.equalsIgnoreCase(field)) {
d.setCustomPool(value.equalsIgnoreCase("true")); d.setCustomPool(value.equalsIgnoreCase("true"));
} else if (PLAYER.equalsIgnoreCase(field)) { } else if (DeckManager.PLAYER.equalsIgnoreCase(field)) {
if ("human".equalsIgnoreCase(value)) { if ("human".equalsIgnoreCase(value)) {
d.setPlayerType(PlayerType.HUMAN); d.setPlayerType(PlayerType.HUMAN);
@@ -454,11 +454,11 @@ public class DeckManager {
String line; String line;
// readDeck name // readDeck name
String name = iterator.next(); final String name = iterator.next();
// readDeck comments // readDeck comments
String comment = null; String comment = null;
while (iterator.hasNext() && (line = iterator.next()) != null && !line.equals("[general]")) { while (iterator.hasNext() && ((line = iterator.next()) != null) && !line.equals("[general]")) {
if (comment == null) { if (comment == null) {
comment = line; comment = line;
} else { } else {
@@ -468,7 +468,7 @@ public class DeckManager {
// readDeck deck type // readDeck deck type
GameType deckType = iterator.hasNext() ? GameType.smartValueOf(iterator.next()) : GameType.Constructed; final GameType deckType = iterator.hasNext() ? GameType.smartValueOf(iterator.next()) : GameType.Constructed;
d.setName(name); d.setName(name);
d.setComment(comment); d.setComment(comment);
@@ -477,24 +477,24 @@ public class DeckManager {
// Precondition: iterator should point at the first line of cards list // Precondition: iterator should point at the first line of cards list
private static List<String> readCardList(final Iterator<String> lineIterator) { private static List<String> readCardList(final Iterator<String> lineIterator) {
List<String> result = new ArrayList<String>(); final List<String> result = new ArrayList<String>();
Pattern p = Pattern.compile("((\\d+)\\s+)?(.*?)"); final Pattern p = Pattern.compile("((\\d+)\\s+)?(.*?)");
while (lineIterator.hasNext()) { while (lineIterator.hasNext()) {
String line = lineIterator.next(); final String line = lineIterator.next();
if (line.startsWith("[")) { if (line.startsWith("[")) {
break; break;
} // there comes another section } // there comes another section
Matcher m = p.matcher(line.trim()); final Matcher m = p.matcher(line.trim());
m.matches(); m.matches();
String sCnt = m.group(2); final String sCnt = m.group(2);
String cardName = m.group(3); final String cardName = m.group(3);
if (StringUtils.isBlank(cardName)) { if (StringUtils.isBlank(cardName)) {
continue; continue;
} }
int count = sCnt == null ? 1 : parseInt(sCnt); final int count = sCnt == null ? 1 : Integer.parseInt(sCnt);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
result.add(cardName); result.add(cardName);
} }
@@ -517,10 +517,10 @@ public class DeckManager {
* @return a String * @return a String
*/ */
public static String cleanDeckName(final String in) { public static String cleanDeckName(final String in) {
char[] c = in.toCharArray(); final char[] c = in.toCharArray();
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for (int i = 0; i < c.length && i < 20; i++) { for (int i = 0; (i < c.length) && (i < 20); i++) {
if (Character.isLetterOrDigit(c[i]) || c[i] == '-') { if (Character.isLetterOrDigit(c[i]) || (c[i] == '-')) {
sb.append(c[i]); sb.append(c[i]);
} }
} }
@@ -538,11 +538,11 @@ public class DeckManager {
* @return a File * @return a File
*/ */
public static File makeFileName(final String deckName, final GameType deckType) { public static File makeFileName(final String deckName, final GameType deckType) {
File path = ForgeProps.getFile(NewConstants.NEW_DECKS); final File path = ForgeProps.getFile(NewConstants.NEW_DECKS);
if (deckType == GameType.Draft) { if (deckType == GameType.Draft) {
return new File(path, deriveFileName(deckName) + ".bdk"); return new File(path, DeckManager.deriveFileName(deckName) + ".bdk");
} else { } else {
return new File(path, deriveFileName(deckName) + ".dck"); return new File(path, DeckManager.deriveFileName(deckName) + ".dck");
} }
} }
@@ -555,7 +555,7 @@ public class DeckManager {
* @return a File * @return a File
*/ */
public static File makeFileName(final Deck deck) { public static File makeFileName(final Deck deck) {
return makeFileName(deck.getName(), deck.getDeckType()); return DeckManager.makeFileName(deck.getName(), deck.getDeckType());
} }
/** /**
@@ -567,15 +567,15 @@ public class DeckManager {
*/ */
public static void writeDraftDecks(final Deck[] drafts) { public static void writeDraftDecks(final Deck[] drafts) {
try { try {
File f = makeFileName(drafts[0]); final File f = DeckManager.makeFileName(drafts[0]);
f.mkdir(); f.mkdir();
for (int i = 0; i < drafts.length; i++) { for (int i = 0; i < drafts.length; i++) {
BufferedWriter out = new BufferedWriter(new FileWriter(new File(f, i + ".dck"))); final BufferedWriter out = new BufferedWriter(new FileWriter(new File(f, i + ".dck")));
writeDeck(drafts[i], out); DeckManager.writeDeck(drafts[i], out);
out.close(); out.close();
} }
} catch (IOException ex) { } catch (final IOException ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage()); throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage());
} }
@@ -594,27 +594,27 @@ public class DeckManager {
* if any. * if any.
*/ */
private static void writeDeck(final Deck d, final BufferedWriter out) throws IOException { private static void writeDeck(final Deck d, final BufferedWriter out) throws IOException {
out.write(format("[metadata]%n")); out.write(String.format("[metadata]%n"));
out.write(format("%s=%s%n", NAME, d.getName().replaceAll("\n", ""))); out.write(String.format("%s=%s%n", DeckManager.NAME, d.getName().replaceAll("\n", "")));
out.write(format("%s=%s%n", DECK_TYPE, d.getDeckType())); out.write(String.format("%s=%s%n", DeckManager.DECK_TYPE, d.getDeckType()));
// these are optional // these are optional
if (d.getComment() != null) { if (d.getComment() != null) {
out.write(format("%s=%s%n", COMMENT, d.getComment().replaceAll("\n", ""))); out.write(String.format("%s=%s%n", DeckManager.COMMENT, d.getComment().replaceAll("\n", "")));
} }
if (d.getPlayerType() != null) { if (d.getPlayerType() != null) {
out.write(format("%s=%s%n", PLAYER, d.getPlayerType())); out.write(String.format("%s=%s%n", DeckManager.PLAYER, d.getPlayerType()));
} }
if (d.isCustomPool()) { if (d.isCustomPool()) {
out.write(format("%s=%s%n", CSTM_POOL, "true")); out.write(String.format("%s=%s%n", DeckManager.CSTM_POOL, "true"));
} }
out.write(format("%s%n", "[main]")); out.write(String.format("%s%n", "[main]"));
writeCardPool(d.getMain(), out); DeckManager.writeCardPool(d.getMain(), out);
out.write(format("%s%n", "[sideboard]")); out.write(String.format("%s%n", "[sideboard]"));
writeCardPool(d.getSideboard(), out); DeckManager.writeCardPool(d.getSideboard(), out);
} }
/** /**
@@ -631,12 +631,12 @@ public class DeckManager {
*/ */
private static void writeDeckHtml(final Deck d, final BufferedWriter out) throws IOException { private static void writeDeckHtml(final Deck d, final BufferedWriter out) throws IOException {
Template temp = null; Template temp = null;
int cardBorder = 0; final int cardBorder = 0;
int height = 319; final int height = 319;
int width = 222; final int width = 222;
/* Create and adjust the configuration */ /* Create and adjust the configuration */
Configuration cfg = new Configuration(); final Configuration cfg = new Configuration();
try { try {
cfg.setClassForTemplateLoading(d.getClass(), "/"); cfg.setClassForTemplateLoading(d.getClass(), "/");
cfg.setObjectWrapper(new DefaultObjectWrapper()); cfg.setObjectWrapper(new DefaultObjectWrapper());
@@ -654,10 +654,10 @@ public class DeckManager {
temp = cfg.getTemplate("proxy-template.ftl"); temp = cfg.getTemplate("proxy-template.ftl");
/* Create a data-model */ /* Create a data-model */
Map<String, Object> root = new HashMap<String, Object>(); final Map<String, Object> root = new HashMap<String, Object>();
root.put("title", d.getName()); root.put("title", d.getName());
List<String> list = new ArrayList<String>(); final List<String> list = new ArrayList<String>();
for (Card card : d.getMain().toForgeCardList().toArray()) { for (final Card card : d.getMain().toForgeCardList().toArray()) {
// System.out.println(card.getSets().get(card.getSets().size() - // System.out.println(card.getSets().get(card.getSets().size() -
// 1).URL); // 1).URL);
list.add(card.getSets().get(card.getSets().size() - 1).getUrl()); list.add(card.getSets().get(card.getSets().size() - 1).getUrl());
@@ -669,8 +669,8 @@ public class DeckManager {
* 1).URL); nameList.add(card.getName()); } * 1).URL); nameList.add(card.getName()); }
*/ */
TreeMap<String, Integer> map = new TreeMap<String, Integer>(); final TreeMap<String, Integer> map = new TreeMap<String, Integer>();
for (Entry<CardPrinted, Integer> entry : d.getMain().getOrderedList()) { for (final Entry<CardPrinted, Integer> entry : d.getMain().getOrderedList()) {
map.put(entry.getKey().getName(), entry.getValue()); map.put(entry.getKey().getName(), entry.getValue());
// System.out.println(entry.getValue() + " " + // System.out.println(entry.getValue() + " " +
// entry.getKey().getName()); // entry.getKey().getName());
@@ -688,24 +688,24 @@ public class DeckManager {
// StringWriter sw = new StringWriter(); // StringWriter sw = new StringWriter();
temp.process(root, out); temp.process(root, out);
out.flush(); out.flush();
} catch (IOException e) { } catch (final IOException e) {
System.out.println(e.toString()); System.out.println(e.toString());
} catch (TemplateException e) { } catch (final TemplateException e) {
System.out.println(e.toString()); System.out.println(e.toString());
} }
} }
private static void writeCardPool(final ItemPoolView<CardPrinted> pool, final BufferedWriter out) private static void writeCardPool(final ItemPoolView<CardPrinted> pool, final BufferedWriter out)
throws IOException { throws IOException {
List<Entry<CardPrinted, Integer>> main2sort = pool.getOrderedList(); final List<Entry<CardPrinted, Integer>> main2sort = pool.getOrderedList();
Collections.sort(main2sort, TableSorter.byNameThenSet); Collections.sort(main2sort, TableSorter.byNameThenSet);
for (Entry<CardPrinted, Integer> e : main2sort) { for (final Entry<CardPrinted, Integer> e : main2sort) {
CardPrinted card = e.getKey(); final CardPrinted card = e.getKey();
boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet()); final boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet());
if (hasBadSetInfo) { if (hasBadSetInfo) {
out.write(format("%d %s%n", e.getValue(), card.getName())); out.write(String.format("%d %s%n", e.getValue(), card.getName()));
} else { } else {
out.write(format("%d %s|%s%n", e.getValue(), card.getName(), card.getSet())); out.write(String.format("%d %s|%s%n", e.getValue(), card.getName(), card.getSet()));
} }
} }
} }
@@ -722,10 +722,10 @@ public class DeckManager {
*/ */
public static void writeDeck(final Deck d, final File f) { public static void writeDeck(final Deck d, final File f) {
try { try {
BufferedWriter writer = new BufferedWriter(new FileWriter(f)); final BufferedWriter writer = new BufferedWriter(new FileWriter(f));
writeDeck(d, writer); DeckManager.writeDeck(d, writer);
writer.close(); writer.close();
} catch (IOException e) { } catch (final IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -743,10 +743,10 @@ public class DeckManager {
*/ */
public static void writeDeckHtml(final Deck d, final File f) { public static void writeDeckHtml(final Deck d, final File f) {
try { try {
BufferedWriter writer = new BufferedWriter(new FileWriter(f)); final BufferedWriter writer = new BufferedWriter(new FileWriter(f));
writeDeckHtml(d, writer); DeckManager.writeDeckHtml(d, writer);
writer.close(); writer.close();
} catch (IOException e) { } catch (final IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }

View File

@@ -76,10 +76,10 @@ public class DeckRecognizer {
} }
private Token(final CardPrinted knownCard, final TokenType type1, final int count, final String message) { private Token(final CardPrinted knownCard, final TokenType type1, final int count, final String message) {
card = knownCard; this.card = knownCard;
number = count; this.number = count;
type = type1; this.type = type1;
text = message; this.text = message;
} }
/** /**
@@ -94,7 +94,7 @@ public class DeckRecognizer {
*/ */
public Token(final TokenType type1, final int count, final String message) { public Token(final TokenType type1, final int count, final String message) {
this(null, type1, count, message); this(null, type1, count, message);
if (type1 == TokenType.KnownCard || type1 == TokenType.UnknownCard) { if ((type1 == TokenType.KnownCard) || (type1 == TokenType.UnknownCard)) {
throw new IllegalArgumentException("Use factory methods for recognized card lines"); throw new IllegalArgumentException("Use factory methods for recognized card lines");
} }
} }
@@ -105,7 +105,7 @@ public class DeckRecognizer {
* @return the text * @return the text
*/ */
public final String getText() { public final String getText() {
return text; return this.text;
} }
/** /**
@@ -114,7 +114,7 @@ public class DeckRecognizer {
* @return the card * @return the card
*/ */
public final CardPrinted getCard() { public final CardPrinted getCard() {
return card; return this.card;
} }
/** /**
@@ -123,7 +123,7 @@ public class DeckRecognizer {
* @return the type * @return the type
*/ */
public final TokenType getType() { public final TokenType getType() {
return type; return this.type;
} }
/** /**
@@ -132,35 +132,35 @@ public class DeckRecognizer {
* @return the number * @return the number
*/ */
public final int getNumber() { public final int getNumber() {
return number; return this.number;
} }
} }
// Let's think about it numbers in the back later // Let's think about it numbers in the back later
// private static final Pattern searchNumbersInBack = // private static final Pattern searchNumbersInBack =
// Pattern.compile("(.*)[^A-Za-wyz]*\\s+([\\d]{1,2})"); // Pattern.compile("(.*)[^A-Za-wyz]*\\s+([\\d]{1,2})");
private static final Pattern searchNumbersInFront = Pattern.compile("([\\d]{1,2})[^A-Za-wyz]*\\s+(.*)"); private static final Pattern SEARCH_NUMBERS_IN_FRONT = Pattern.compile("([\\d]{1,2})[^A-Za-wyz]*\\s+(.*)");
/** /**
* Recognize line. * Recognize line.
* *
* @param raw_line * @param rawLine
* the raw_line * the raw_line
* @return the token * @return the token
*/ */
public static Token recognizeLine(final String raw_line) { public static Token recognizeLine(final String rawLine) {
if (StringUtils.isBlank(raw_line)) { if (StringUtils.isBlank(rawLine)) {
return new Token(TokenType.Comment, 0, raw_line); return new Token(TokenType.Comment, 0, rawLine);
} }
String line = raw_line.trim(); final String line = rawLine.trim();
Token result = null; Token result = null;
Matcher foundNumbersInFront = searchNumbersInFront.matcher(line); final Matcher foundNumbersInFront = DeckRecognizer.SEARCH_NUMBERS_IN_FRONT.matcher(line);
// Matcher foundNumbersInBack = searchNumbersInBack.matcher(line); // Matcher foundNumbersInBack = searchNumbersInBack.matcher(line);
if (foundNumbersInFront.matches()) { if (foundNumbersInFront.matches()) {
String cardName = foundNumbersInFront.group(2); final String cardName = foundNumbersInFront.group(2);
int amount = Integer.parseInt(foundNumbersInFront.group(1)); final int amount = Integer.parseInt(foundNumbersInFront.group(1));
result = recognizePossibleNameAndNumber(cardName, amount); result = DeckRecognizer.recognizePossibleNameAndNumber(cardName, amount);
} /* } /*
* else if (foundNumbersInBack.matches()) { String cardName = * else if (foundNumbersInBack.matches()) { String cardName =
* foundNumbersInBack.group(1); int amount = * foundNumbersInBack.group(1); int amount =
@@ -171,7 +171,7 @@ public class DeckRecognizer {
if (CardDb.instance().isCardSupported(line)) { if (CardDb.instance().isCardSupported(line)) {
return Token.knownCard(CardDb.instance().getCard(line), 1); return Token.knownCard(CardDb.instance().getCard(line), 1);
} }
result = recognizeNonCard(line, 1); result = DeckRecognizer.recognizeNonCard(line, 1);
} }
return result != null ? result : new Token(TokenType.UnknownText, 0, line); return result != null ? result : new Token(TokenType.UnknownText, 0, line);
} }
@@ -181,32 +181,32 @@ public class DeckRecognizer {
return Token.knownCard(CardDb.instance().getCard(name), n); return Token.knownCard(CardDb.instance().getCard(name), n);
} }
Token known = recognizeNonCard(name, n); final Token known = DeckRecognizer.recognizeNonCard(name, n);
return null == known ? Token.unknownCard(name, n) : known; return null == known ? Token.unknownCard(name, n) : known;
} }
private static Token recognizeNonCard(final String text, final int n) { private static Token recognizeNonCard(final String text, final int n) {
if (isDecoration(text)) { if (DeckRecognizer.isDecoration(text)) {
return new Token(TokenType.Comment, n, text); return new Token(TokenType.Comment, n, text);
} }
if (isSectionName(text)) { if (DeckRecognizer.isSectionName(text)) {
return new Token(TokenType.SectionName, n, text); return new Token(TokenType.SectionName, n, text);
} }
return null; return null;
} }
private static final String[] knownComments = new String[] { "land", "lands", "creatures", "creature", "spells", private static final String[] KNOWN_COMMENTS = new String[] { "land", "lands", "creatures", "creature", "spells",
"enchancements", "other spells", "artifacts" }; "enchancements", "other spells", "artifacts" };
private static final String[] knownCommentParts = new String[] { "card" }; private static final String[] KNOWN_COMMENT_PARTS = new String[] { "card" };
private static boolean isDecoration(final String lineAsIs) { private static boolean isDecoration(final String lineAsIs) {
String line = lineAsIs.toLowerCase(); final String line = lineAsIs.toLowerCase();
for (String s : knownCommentParts) { for (final String s : DeckRecognizer.KNOWN_COMMENT_PARTS) {
if (line.contains(s)) { if (line.contains(s)) {
return true; return true;
} }
} }
for (String s : knownComments) { for (final String s : DeckRecognizer.KNOWN_COMMENTS) {
if (line.equalsIgnoreCase(s)) { if (line.equalsIgnoreCase(s)) {
return true; return true;
} }

View File

@@ -44,46 +44,46 @@ public class Generate2ColorDeck {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public Generate2ColorDeck(final String Clr1, final String Clr2) { public Generate2ColorDeck(final String Clr1, final String Clr2) {
r = MyRandom.getRandom(); this.r = MyRandom.getRandom();
cardCounts = new HashMap<String, Integer>(); this.cardCounts = new HashMap<String, Integer>();
clrMap = new HashMap<String, String>(); this.clrMap = new HashMap<String, String>();
clrMap.put("white", "W"); this.clrMap.put("white", "W");
clrMap.put("blue", "U"); this.clrMap.put("blue", "U");
clrMap.put("black", "B"); this.clrMap.put("black", "B");
clrMap.put("red", "R"); this.clrMap.put("red", "R");
clrMap.put("green", "G"); this.clrMap.put("green", "G");
notColors = new ArrayList<String>(); this.notColors = new ArrayList<String>();
notColors.add("white"); this.notColors.add("white");
notColors.add("blue"); this.notColors.add("blue");
notColors.add("black"); this.notColors.add("black");
notColors.add("red"); this.notColors.add("red");
notColors.add("green"); this.notColors.add("green");
if (Clr1.equals("AI")) { if (Clr1.equals("AI")) {
// choose first color // choose first color
color1 = notColors.get(r.nextInt(5)); this.color1 = this.notColors.get(this.r.nextInt(5));
// choose second color // choose second color
String c2 = notColors.get(r.nextInt(5)); String c2 = this.notColors.get(this.r.nextInt(5));
while (c2.equals(color1)) { while (c2.equals(this.color1)) {
c2 = notColors.get(r.nextInt(5)); c2 = this.notColors.get(this.r.nextInt(5));
} }
color2 = c2; this.color2 = c2;
} else { } else {
color1 = Clr1; this.color1 = Clr1;
color2 = Clr2; this.color2 = Clr2;
} }
notColors.remove(color1); this.notColors.remove(this.color1);
notColors.remove(color2); this.notColors.remove(this.color2);
dL = GenerateDeckUtil.getDualLandList(clrMap.get(color1) + clrMap.get(color2)); this.dL = GenerateDeckUtil.getDualLandList(this.clrMap.get(this.color1) + this.clrMap.get(this.color2));
for (int i = 0; i < dL.size(); i++) { for (int i = 0; i < this.dL.size(); i++) {
cardCounts.put(dL.get(i), 0); this.cardCounts.put(this.dL.get(i), 0);
} }
} }
@@ -102,33 +102,36 @@ public class Generate2ColorDeck {
public final CardList get2ColorDeck(final int Size, final PlayerType pt) { public final CardList get2ColorDeck(final int Size, final PlayerType pt) {
int lc = 0; // loop counter to prevent infinite card selection loops int lc = 0; // loop counter to prevent infinite card selection loops
String tmpDeck = ""; String tmpDeck = "";
CardList tDeck = new CardList(); final CardList tDeck = new CardList();
int LandsPercentage = 42; final int LandsPercentage = 42;
int CreatPercentage = 34; final int CreatPercentage = 34;
int SpellPercentage = 24; final int SpellPercentage = 24;
// start with all cards // start with all cards
// remove cards that generated decks don't like // remove cards that generated decks don't like
CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { final CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
if (c.getSVar("RemRandomDeck").equals("True")) { if (c.getSVar("RemRandomDeck").equals("True")) {
return false; return false;
} }
return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN))); return (!c.getSVar("RemAIDeck").equals("True") || ((pt != null) && pt.equals(PlayerType.HUMAN)));
} }
}); });
// reduce to cards that match the colors // reduce to cards that match the colors
CardList CL1 = AllCards.getColor(color1); CardList CL1 = AllCards.getColor(this.color1);
CL1.addAll(AllCards.getColor(Constant.Color.COLORLESS)); CL1.addAll(AllCards.getColor(Constant.Color.COLORLESS));
CardList CL2 = AllCards.getColor(color2); CardList CL2 = AllCards.getColor(this.color2);
// remove multicolor cards that don't match the colors // remove multicolor cards that don't match the colors
CardListFilter clrF = new CardListFilter() { final CardListFilter clrF = new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
for (int i = 0; i < notColors.size(); i++) { for (int i = 0; i < Generate2ColorDeck.this.notColors.size(); i++) {
if (c.getManaCost().contains(clrMap.get(notColors.get(i)))) { if (c.getManaCost().contains(
Generate2ColorDeck.this.clrMap.get(Generate2ColorDeck.this.notColors.get(i)))) {
return false; return false;
} }
} }
@@ -139,49 +142,50 @@ public class Generate2ColorDeck {
CL2 = CL2.filter(clrF); CL2 = CL2.filter(clrF);
// build subsets based on type // build subsets based on type
CardList Cr1 = CL1.getType("Creature"); final CardList Cr1 = CL1.getType("Creature");
CardList Cr2 = CL2.getType("Creature"); final CardList Cr2 = CL2.getType("Creature");
String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; final String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" };
CardList Sp1 = CL1.getValidCards(ISE, null, null); final CardList Sp1 = CL1.getValidCards(ISE, null, null);
CardList Sp2 = CL2.getValidCards(ISE, null, null); final CardList Sp2 = CL2.getValidCards(ISE, null, null);
// final card pools // final card pools
CardList Cr12 = new CardList(); final CardList Cr12 = new CardList();
CardList Sp12 = new CardList(); final CardList Sp12 = new CardList();
// used for mana curve in the card pool // used for mana curve in the card pool
final int MinCMC[] = { 1 }, MaxCMC[] = { 2 }; final int MinCMC[] = { 1 }, MaxCMC[] = { 2 };
CardListFilter cmcF = new CardListFilter() { final CardListFilter cmcF = new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
int cCMC = c.getCMC(); final int cCMC = c.getCMC();
return (cCMC >= MinCMC[0]) && (cCMC <= MaxCMC[0]); return (cCMC >= MinCMC[0]) && (cCMC <= MaxCMC[0]);
} }
}; };
// select cards to build card pools using a mana curve // select cards to build card pools using a mana curve
for (int i = 4; i > 0; i--) { for (int i = 4; i > 0; i--) {
CardList Cr1CMC = Cr1.filter(cmcF); final CardList Cr1CMC = Cr1.filter(cmcF);
CardList Cr2CMC = Cr2.filter(cmcF); final CardList Cr2CMC = Cr2.filter(cmcF);
CardList Sp1CMC = Sp1.filter(cmcF); final CardList Sp1CMC = Sp1.filter(cmcF);
CardList Sp2CMC = Sp2.filter(cmcF); final CardList Sp2CMC = Sp2.filter(cmcF);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
Card c = Cr1CMC.get(r.nextInt(Cr1CMC.size())); Card c = Cr1CMC.get(this.r.nextInt(Cr1CMC.size()));
Cr12.add(c); Cr12.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Cr2CMC.get(r.nextInt(Cr2CMC.size())); c = Cr2CMC.get(this.r.nextInt(Cr2CMC.size()));
Cr12.add(c); Cr12.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Sp1CMC.get(r.nextInt(Sp1CMC.size())); c = Sp1CMC.get(this.r.nextInt(Sp1CMC.size()));
Sp12.add(c); Sp12.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Sp2CMC.get(r.nextInt(Sp2CMC.size())); c = Sp2CMC.get(this.r.nextInt(Sp2CMC.size()));
Sp12.add(c); Sp12.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
} }
MinCMC[0] += 2; MinCMC[0] += 2;
@@ -200,21 +204,21 @@ public class Generate2ColorDeck {
Sp12.shuffle(); Sp12.shuffle();
// calculate card counts // calculate card counts
float p = (float) ((float) CreatPercentage * .01); float p = (float) (CreatPercentage * .01);
int CreatCnt = (int) (p * (float) Size); final int CreatCnt = (int) (p * Size);
tmpDeck += "Creature Count:" + CreatCnt + "\n"; tmpDeck += "Creature Count:" + CreatCnt + "\n";
p = (float) ((float) SpellPercentage * .01); p = (float) (SpellPercentage * .01);
int SpellCnt = (int) (p * (float) Size); final int SpellCnt = (int) (p * Size);
tmpDeck += "Spell Count:" + SpellCnt + "\n"; tmpDeck += "Spell Count:" + SpellCnt + "\n";
// build deck from the card pools // build deck from the card pools
for (int i = 0; i < CreatCnt; i++) { for (int i = 0; i < CreatCnt; i++) {
Card c = Cr12.get(r.nextInt(Cr12.size())); Card c = Cr12.get(this.r.nextInt(Cr12.size()));
lc = 0; lc = 0;
while (cardCounts.get(c.getName()) > 3 || lc > 100) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) {
c = Cr12.get(r.nextInt(Cr12.size())); c = Cr12.get(this.r.nextInt(Cr12.size()));
lc++; lc++;
} }
if (lc > 100) { if (lc > 100) {
@@ -222,17 +226,17 @@ public class Generate2ColorDeck {
} }
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
int n = cardCounts.get(c.getName()); final int n = this.cardCounts.get(c.getName());
cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; tmpDeck += c.getName() + " " + c.getManaCost() + "\n";
} }
for (int i = 0; i < SpellCnt; i++) { for (int i = 0; i < SpellCnt; i++) {
Card c = Sp12.get(r.nextInt(Sp12.size())); Card c = Sp12.get(this.r.nextInt(Sp12.size()));
lc = 0; lc = 0;
while (cardCounts.get(c.getName()) > 3 || lc > 100) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) {
c = Sp12.get(r.nextInt(Sp12.size())); c = Sp12.get(this.r.nextInt(Sp12.size()));
lc++; lc++;
} }
if (lc > 100) { if (lc > 100) {
@@ -240,16 +244,16 @@ public class Generate2ColorDeck {
} }
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
int n = cardCounts.get(c.getName()); final int n = this.cardCounts.get(c.getName());
cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; tmpDeck += c.getName() + " " + c.getManaCost() + "\n";
} }
// Add lands // Add lands
int numLands = 0; int numLands = 0;
if (LandsPercentage > 0) { if (LandsPercentage > 0) {
p = (float) ((float) LandsPercentage * .01); p = (float) (LandsPercentage * .01);
numLands = (int) (p * (float) Size); numLands = (int) (p * Size);
} else { // otherwise, just fill in the rest of the deck with basic } else { // otherwise, just fill in the rest of the deck with basic
// lands // lands
numLands = Size - tDeck.size(); numLands = Size - tDeck.size();
@@ -257,13 +261,13 @@ public class Generate2ColorDeck {
tmpDeck += "numLands:" + numLands + "\n"; tmpDeck += "numLands:" + numLands + "\n";
int nDLands = (numLands / 6); final int nDLands = (numLands / 6);
for (int i = 0; i < nDLands; i++) { for (int i = 0; i < nDLands; i++) {
String s = dL.get(r.nextInt(dL.size())); String s = this.dL.get(this.r.nextInt(this.dL.size()));
lc = 0; lc = 0;
while (cardCounts.get(s) > 3 || lc > 20) { while ((this.cardCounts.get(s) > 3) || (lc > 20)) {
s = dL.get(r.nextInt(dL.size())); s = this.dL.get(this.r.nextInt(this.dL.size()));
lc++; lc++;
} }
if (lc > 20) { if (lc > 20) {
@@ -271,27 +275,27 @@ public class Generate2ColorDeck {
} }
tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer())); tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer()));
int n = cardCounts.get(s); final int n = this.cardCounts.get(s);
cardCounts.put(s, n + 1); this.cardCounts.put(s, n + 1);
tmpDeck += s + "\n"; tmpDeck += s + "\n";
} }
numLands -= nDLands; numLands -= nDLands;
if (numLands > 0) // attempt to optimize basic land counts according to if (numLands > 0) {
// attempt to optimize basic land counts according to
// color representation // color representation
{ final CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
new CCnt("Mountain", 0), new CCnt("Forest", 0) }; new CCnt("Mountain", 0), new CCnt("Forest", 0) };
// count each card color using mana costs // count each card color using mana costs
// TODO count hybrid mana differently? // TODO count hybrid mana differently?
for (int i = 0; i < tDeck.size(); i++) { for (int i = 0; i < tDeck.size(); i++) {
String mc = tDeck.get(i).getManaCost(); final String mc = tDeck.get(i).getManaCost();
// count each mana symbol in the mana cost // count each mana symbol in the mana cost
for (int j = 0; j < mc.length(); j++) { for (int j = 0; j < mc.length(); j++) {
char c = mc.charAt(j); final char c = mc.charAt(j);
if (c == 'W') { if (c == 'W') {
ClrCnts[0].Count++; ClrCnts[0].Count++;
@@ -320,12 +324,12 @@ public class Generate2ColorDeck {
if (ClrCnts[i].Count > 0) { // calculate number of lands for if (ClrCnts[i].Count > 0) { // calculate number of lands for
// each color // each color
p = (float) ClrCnts[i].Count / (float) totalColor; p = (float) ClrCnts[i].Count / (float) totalColor;
int nLand = (int) ((float) numLands * p); final int nLand = (int) (numLands * p);
tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n"; tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n";
// just to prevent a null exception by the deck size fixing // just to prevent a null exception by the deck size fixing
// code // code
cardCounts.put(ClrCnts[i].Color, nLand); this.cardCounts.put(ClrCnts[i].Color, nLand);
for (int j = 0; j <= nLand; j++) { for (int j = 0; j <= nLand; j++) {
tDeck.add(AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer()));
@@ -337,33 +341,33 @@ public class Generate2ColorDeck {
// fix under-sized or over-sized decks, due to integer arithmetic // fix under-sized or over-sized decks, due to integer arithmetic
if (tDeck.size() < Size) { if (tDeck.size() < Size) {
int diff = Size - tDeck.size(); final int diff = Size - tDeck.size();
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(r.nextInt(tDeck.size())); Card c = tDeck.get(this.r.nextInt(tDeck.size()));
lc = 0; lc = 0;
while (cardCounts.get(c.getName()) > 3 || lc > Size) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > Size)) {
c = tDeck.get(r.nextInt(tDeck.size())); c = tDeck.get(this.r.nextInt(tDeck.size()));
lc++; lc++;
} }
if (lc > Size) { if (lc > Size) {
throw new RuntimeException("Generate2ColorDeck : get2ColorDeck -- looped too much -- undersize"); throw new RuntimeException("Generate2ColorDeck : get2ColorDeck -- looped too much -- undersize");
} }
int n = cardCounts.get(c.getName()); final int n = this.cardCounts.get(c.getName());
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += "Added:" + c.getName() + "\n"; tmpDeck += "Added:" + c.getName() + "\n";
} }
} else if (tDeck.size() > Size) { } else if (tDeck.size() > Size) {
int diff = tDeck.size() - Size; final int diff = tDeck.size() - Size;
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(r.nextInt(tDeck.size())); Card c = tDeck.get(this.r.nextInt(tDeck.size()));
while (c.isBasicLand()) { // don't remove basic lands while (c.isBasicLand()) { // don't remove basic lands
c = tDeck.get(r.nextInt(tDeck.size())); c = tDeck.get(this.r.nextInt(tDeck.size()));
} }
tDeck.remove(c); tDeck.remove(c);
@@ -384,8 +388,8 @@ public class Generate2ColorDeck {
public int Count; public int Count;
public CCnt(final String clr, final int cnt) { public CCnt(final String clr, final int cnt) {
Color = clr; this.Color = clr;
Count = cnt; this.Count = cnt;
} }
} }
} }

View File

@@ -47,54 +47,55 @@ public class Generate3ColorDeck {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public Generate3ColorDeck(final String Clr1, final String Clr2, final String Clr3) { public Generate3ColorDeck(final String Clr1, final String Clr2, final String Clr3) {
r = MyRandom.getRandom(); this.r = MyRandom.getRandom();
cardCounts = new HashMap<String, Integer>(); this.cardCounts = new HashMap<String, Integer>();
crMap = new HashMap<String, String>(); this.crMap = new HashMap<String, String>();
crMap.put("white", "W"); this.crMap.put("white", "W");
crMap.put("blue", "U"); this.crMap.put("blue", "U");
crMap.put("black", "B"); this.crMap.put("black", "B");
crMap.put("red", "R"); this.crMap.put("red", "R");
crMap.put("green", "G"); this.crMap.put("green", "G");
notColors = new ArrayList<String>(); this.notColors = new ArrayList<String>();
notColors.add("white"); this.notColors.add("white");
notColors.add("blue"); this.notColors.add("blue");
notColors.add("black"); this.notColors.add("black");
notColors.add("red"); this.notColors.add("red");
notColors.add("green"); this.notColors.add("green");
if (Clr1.equals("AI")) { if (Clr1.equals("AI")) {
// choose first color // choose first color
color1 = notColors.get(r.nextInt(5)); this.color1 = this.notColors.get(this.r.nextInt(5));
// choose second color // choose second color
String c2 = notColors.get(r.nextInt(5)); String c2 = this.notColors.get(this.r.nextInt(5));
while (c2.equals(color1)) { while (c2.equals(this.color1)) {
c2 = notColors.get(r.nextInt(5)); c2 = this.notColors.get(this.r.nextInt(5));
} }
color2 = c2; this.color2 = c2;
String c3 = notColors.get(r.nextInt(5)); String c3 = this.notColors.get(this.r.nextInt(5));
while (c3.equals(color1) || c3.equals(color2)) { while (c3.equals(this.color1) || c3.equals(this.color2)) {
c3 = notColors.get(r.nextInt(5)); c3 = this.notColors.get(this.r.nextInt(5));
} }
color3 = c3; this.color3 = c3;
} else { } else {
color1 = Clr1; this.color1 = Clr1;
color2 = Clr2; this.color2 = Clr2;
color3 = Clr3; this.color3 = Clr3;
} }
notColors.remove(color1); this.notColors.remove(this.color1);
notColors.remove(color2); this.notColors.remove(this.color2);
notColors.remove(color3); this.notColors.remove(this.color3);
dL = GenerateDeckUtil.getDualLandList(crMap.get(color1) + crMap.get(color2) + crMap.get(color3)); this.dL = GenerateDeckUtil.getDualLandList(this.crMap.get(this.color1) + this.crMap.get(this.color2)
+ this.crMap.get(this.color3));
for (int i = 0; i < dL.size(); i++) { for (int i = 0; i < this.dL.size(); i++) {
cardCounts.put(dL.get(i), 0); this.cardCounts.put(this.dL.get(i), 0);
} }
} }
@@ -113,34 +114,37 @@ public class Generate3ColorDeck {
public final CardList get3ColorDeck(final int Size, final PlayerType pt) { public final CardList get3ColorDeck(final int Size, final PlayerType pt) {
int lc = 0; // loop counter to prevent infinite card selection loops int lc = 0; // loop counter to prevent infinite card selection loops
String tmpDeck = ""; String tmpDeck = "";
CardList tDeck = new CardList(); final CardList tDeck = new CardList();
int LandsPercentage = 44; final int LandsPercentage = 44;
int CreatPercentage = 34; final int CreatPercentage = 34;
int SpellPercentage = 22; final int SpellPercentage = 22;
// start with all cards // start with all cards
// remove cards that generated decks don't like // remove cards that generated decks don't like
CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { final CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
if (c.getSVar("RemRandomDeck").equals("True")) { if (c.getSVar("RemRandomDeck").equals("True")) {
return false; return false;
} }
return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN))); return (!c.getSVar("RemAIDeck").equals("True") || ((pt != null) && pt.equals(PlayerType.HUMAN)));
} }
}); });
// reduce to cards that match the colors // reduce to cards that match the colors
CardList CL1 = AllCards.getColor(color1); CardList CL1 = AllCards.getColor(this.color1);
CL1.addAll(AllCards.getColor(Constant.Color.COLORLESS)); CL1.addAll(AllCards.getColor(Constant.Color.COLORLESS));
CardList CL2 = AllCards.getColor(color2); CardList CL2 = AllCards.getColor(this.color2);
CardList CL3 = AllCards.getColor(color3); CardList CL3 = AllCards.getColor(this.color3);
// remove multicolor cards that don't match the colors // remove multicolor cards that don't match the colors
CardListFilter clrF = new CardListFilter() { final CardListFilter clrF = new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
for (int i = 0; i < notColors.size(); i++) { for (int i = 0; i < Generate3ColorDeck.this.notColors.size(); i++) {
if (c.getManaCost().contains(crMap.get(notColors.get(i)))) { if (c.getManaCost().contains(
Generate3ColorDeck.this.crMap.get(Generate3ColorDeck.this.notColors.get(i)))) {
return false; return false;
} }
} }
@@ -152,62 +156,63 @@ public class Generate3ColorDeck {
CL3 = CL3.filter(clrF); CL3 = CL3.filter(clrF);
// build subsets based on type // build subsets based on type
CardList Cr1 = CL1.getType("Creature"); final CardList Cr1 = CL1.getType("Creature");
CardList Cr2 = CL2.getType("Creature"); final CardList Cr2 = CL2.getType("Creature");
CardList Cr3 = CL3.getType("Creature"); final CardList Cr3 = CL3.getType("Creature");
String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; final String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" };
CardList Sp1 = CL1.getValidCards(ISE, null, null); final CardList Sp1 = CL1.getValidCards(ISE, null, null);
CardList Sp2 = CL2.getValidCards(ISE, null, null); final CardList Sp2 = CL2.getValidCards(ISE, null, null);
CardList Sp3 = CL3.getValidCards(ISE, null, null); final CardList Sp3 = CL3.getValidCards(ISE, null, null);
// final card pools // final card pools
CardList Cr123 = new CardList(); final CardList Cr123 = new CardList();
CardList Sp123 = new CardList(); final CardList Sp123 = new CardList();
// used for mana curve in the card pool // used for mana curve in the card pool
final int MinCMC[] = { 1 }, MaxCMC[] = { 3 }; final int MinCMC[] = { 1 }, MaxCMC[] = { 3 };
CardListFilter cmcF = new CardListFilter() { final CardListFilter cmcF = new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
int cCMC = c.getCMC(); final int cCMC = c.getCMC();
return (cCMC >= MinCMC[0]) && (cCMC <= MaxCMC[0]); return (cCMC >= MinCMC[0]) && (cCMC <= MaxCMC[0]);
} }
}; };
// select cards to build card pools using a mana curve // select cards to build card pools using a mana curve
for (int i = 3; i > 0; i--) { for (int i = 3; i > 0; i--) {
CardList Cr1CMC = Cr1.filter(cmcF); final CardList Cr1CMC = Cr1.filter(cmcF);
CardList Cr2CMC = Cr2.filter(cmcF); final CardList Cr2CMC = Cr2.filter(cmcF);
CardList Cr3CMC = Cr3.filter(cmcF); final CardList Cr3CMC = Cr3.filter(cmcF);
CardList Sp1CMC = Sp1.filter(cmcF); final CardList Sp1CMC = Sp1.filter(cmcF);
CardList Sp2CMC = Sp2.filter(cmcF); final CardList Sp2CMC = Sp2.filter(cmcF);
CardList Sp3CMC = Sp3.filter(cmcF); final CardList Sp3CMC = Sp3.filter(cmcF);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
Card c = Cr1CMC.get(r.nextInt(Cr1CMC.size())); Card c = Cr1CMC.get(this.r.nextInt(Cr1CMC.size()));
Cr123.add(c); Cr123.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Cr2CMC.get(r.nextInt(Cr2CMC.size())); c = Cr2CMC.get(this.r.nextInt(Cr2CMC.size()));
Cr123.add(c); Cr123.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Cr3CMC.get(r.nextInt(Cr3CMC.size())); c = Cr3CMC.get(this.r.nextInt(Cr3CMC.size()));
Cr123.add(c); Cr123.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Sp1CMC.get(r.nextInt(Sp1CMC.size())); c = Sp1CMC.get(this.r.nextInt(Sp1CMC.size()));
Sp123.add(c); Sp123.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Sp2CMC.get(r.nextInt(Sp2CMC.size())); c = Sp2CMC.get(this.r.nextInt(Sp2CMC.size()));
Sp123.add(c); Sp123.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = Sp3CMC.get(r.nextInt(Sp3CMC.size())); c = Sp3CMC.get(this.r.nextInt(Sp3CMC.size()));
Sp123.add(c); Sp123.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
} }
MinCMC[0] += 2; MinCMC[0] += 2;
@@ -225,21 +230,21 @@ public class Generate3ColorDeck {
Sp123.shuffle(); Sp123.shuffle();
// calculate card counts // calculate card counts
float p = (float) ((float) CreatPercentage * .01); float p = (float) (CreatPercentage * .01);
int CreatCnt = (int) (p * (float) Size); final int CreatCnt = (int) (p * Size);
tmpDeck += "Creature Count:" + CreatCnt + "\n"; tmpDeck += "Creature Count:" + CreatCnt + "\n";
p = (float) ((float) SpellPercentage * .01); p = (float) (SpellPercentage * .01);
int SpellCnt = (int) (p * (float) Size); final int SpellCnt = (int) (p * Size);
tmpDeck += "Spell Count:" + SpellCnt + "\n"; tmpDeck += "Spell Count:" + SpellCnt + "\n";
// build deck from the card pools // build deck from the card pools
for (int i = 0; i < CreatCnt; i++) { for (int i = 0; i < CreatCnt; i++) {
Card c = Cr123.get(r.nextInt(Cr123.size())); Card c = Cr123.get(this.r.nextInt(Cr123.size()));
lc = 0; lc = 0;
while (cardCounts.get(c.getName()) > 3 || lc > 100) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) {
c = Cr123.get(r.nextInt(Cr123.size())); c = Cr123.get(this.r.nextInt(Cr123.size()));
lc++; lc++;
} }
if (lc > 100) { if (lc > 100) {
@@ -247,17 +252,17 @@ public class Generate3ColorDeck {
} }
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
int n = cardCounts.get(c.getName()); final int n = this.cardCounts.get(c.getName());
cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; tmpDeck += c.getName() + " " + c.getManaCost() + "\n";
} }
for (int i = 0; i < SpellCnt; i++) { for (int i = 0; i < SpellCnt; i++) {
Card c = Sp123.get(r.nextInt(Sp123.size())); Card c = Sp123.get(this.r.nextInt(Sp123.size()));
lc = 0; lc = 0;
while (cardCounts.get(c.getName()) > 3 || lc > 100) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) {
c = Sp123.get(r.nextInt(Sp123.size())); c = Sp123.get(this.r.nextInt(Sp123.size()));
lc++; lc++;
} }
if (lc > 100) { if (lc > 100) {
@@ -265,16 +270,16 @@ public class Generate3ColorDeck {
} }
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
int n = cardCounts.get(c.getName()); final int n = this.cardCounts.get(c.getName());
cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; tmpDeck += c.getName() + " " + c.getManaCost() + "\n";
} }
// Add lands // Add lands
int numLands = 0; int numLands = 0;
if (LandsPercentage > 0) { if (LandsPercentage > 0) {
p = (float) ((float) LandsPercentage * .01); p = (float) (LandsPercentage * .01);
numLands = (int) (p * (float) Size); numLands = (int) (p * Size);
} else { } else {
// otherwise, just fill in the rest of the deck with basic lands // otherwise, just fill in the rest of the deck with basic lands
numLands = Size - tDeck.size(); numLands = Size - tDeck.size();
@@ -282,13 +287,13 @@ public class Generate3ColorDeck {
tmpDeck += "numLands:" + numLands + "\n"; tmpDeck += "numLands:" + numLands + "\n";
int ndLands = (numLands / 4); final int ndLands = (numLands / 4);
for (int i = 0; i < ndLands; i++) { for (int i = 0; i < ndLands; i++) {
String s = dL.get(r.nextInt(dL.size())); String s = this.dL.get(this.r.nextInt(this.dL.size()));
lc = 0; lc = 0;
while (cardCounts.get(s) > 3 || lc > 20) { while ((this.cardCounts.get(s) > 3) || (lc > 20)) {
s = dL.get(r.nextInt(dL.size())); s = this.dL.get(this.r.nextInt(this.dL.size()));
lc++; lc++;
} }
if (lc > 20) { if (lc > 20) {
@@ -296,8 +301,8 @@ public class Generate3ColorDeck {
} }
tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer())); tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer()));
int n = cardCounts.get(s); final int n = this.cardCounts.get(s);
cardCounts.put(s, n + 1); this.cardCounts.put(s, n + 1);
tmpDeck += s + "\n"; tmpDeck += s + "\n";
} }
@@ -306,17 +311,17 @@ public class Generate3ColorDeck {
if (numLands > 0) // attempt to optimize basic land counts according to if (numLands > 0) // attempt to optimize basic land counts according to
// color representation // color representation
{ {
CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), final CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
new CCnt("Mountain", 0), new CCnt("Forest", 0) }; new CCnt("Mountain", 0), new CCnt("Forest", 0) };
// count each card color using mana costs // count each card color using mana costs
// TODO count hybrid mana differently? // TODO count hybrid mana differently?
for (int i = 0; i < tDeck.size(); i++) { for (int i = 0; i < tDeck.size(); i++) {
String mc = tDeck.get(i).getManaCost(); final String mc = tDeck.get(i).getManaCost();
// count each mana symbol in the mana cost // count each mana symbol in the mana cost
for (int j = 0; j < mc.length(); j++) { for (int j = 0; j < mc.length(); j++) {
char c = mc.charAt(j); final char c = mc.charAt(j);
if (c == 'W') { if (c == 'W') {
ClrCnts[0].Count++; ClrCnts[0].Count++;
@@ -345,12 +350,12 @@ public class Generate3ColorDeck {
if (ClrCnts[i].Count > 0) { // calculate number of lands for if (ClrCnts[i].Count > 0) { // calculate number of lands for
// each color // each color
p = (float) ClrCnts[i].Count / (float) totalColor; p = (float) ClrCnts[i].Count / (float) totalColor;
int nLand = (int) ((float) numLands * p); final int nLand = (int) (numLands * p);
tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n"; tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n";
// just to prevent a null exception by the deck size fixing // just to prevent a null exception by the deck size fixing
// code // code
cardCounts.put(ClrCnts[i].Color, nLand); this.cardCounts.put(ClrCnts[i].Color, nLand);
for (int j = 0; j <= nLand; j++) { for (int j = 0; j <= nLand; j++) {
tDeck.add(AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer()));
@@ -362,34 +367,34 @@ public class Generate3ColorDeck {
// fix under-sized or over-sized decks, due to integer arithmetic // fix under-sized or over-sized decks, due to integer arithmetic
if (tDeck.size() < Size) { if (tDeck.size() < Size) {
int diff = Size - tDeck.size(); final int diff = Size - tDeck.size();
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(r.nextInt(tDeck.size())); Card c = tDeck.get(this.r.nextInt(tDeck.size()));
lc = 0; lc = 0;
while (cardCounts.get(c.getName()) > 3 || lc > Size) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > Size)) {
c = tDeck.get(r.nextInt(tDeck.size())); c = tDeck.get(this.r.nextInt(tDeck.size()));
lc++; lc++;
} }
if (lc > Size) { if (lc > Size) {
throw new RuntimeException("Generate3ColorDeck : get3ColorDeck -- looped too much -- undersize"); throw new RuntimeException("Generate3ColorDeck : get3ColorDeck -- looped too much -- undersize");
} }
int n = cardCounts.get(c.getName()); final int n = this.cardCounts.get(c.getName());
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += "Added:" + c.getName() + "\n"; tmpDeck += "Added:" + c.getName() + "\n";
} }
} else if (tDeck.size() > Size) { } else if (tDeck.size() > Size) {
int diff = tDeck.size() - Size; final int diff = tDeck.size() - Size;
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(r.nextInt(tDeck.size())); Card c = tDeck.get(this.r.nextInt(tDeck.size()));
while (c.isBasicLand()) { while (c.isBasicLand()) {
// don't remove basic lands // don't remove basic lands
c = tDeck.get(r.nextInt(tDeck.size())); c = tDeck.get(this.r.nextInt(tDeck.size()));
} }
tDeck.remove(c); tDeck.remove(c);
@@ -410,8 +415,8 @@ public class Generate3ColorDeck {
public int Count; public int Count;
public CCnt(final String clr, final int cnt) { public CCnt(final String clr, final int cnt) {
Color = clr; this.Color = clr;
Count = cnt; this.Count = cnt;
} }
} }
} }

View File

@@ -61,40 +61,40 @@ public class Generate5ColorDeck {
*/ */
public Generate5ColorDeck(final String clr1, final String clr2, final String clr3, final String clr4, public Generate5ColorDeck(final String clr1, final String clr2, final String clr3, final String clr4,
final String clr5) { final String clr5) {
r = MyRandom.getRandom(); this.r = MyRandom.getRandom();
cardCounts = new HashMap<String, Integer>(); this.cardCounts = new HashMap<String, Integer>();
clrMap = new HashMap<String, String>(); this.clrMap = new HashMap<String, String>();
clrMap.put("white", "W"); this.clrMap.put("white", "W");
clrMap.put("blue", "U"); this.clrMap.put("blue", "U");
clrMap.put("black", "B"); this.clrMap.put("black", "B");
clrMap.put("red", "R"); this.clrMap.put("red", "R");
clrMap.put("green", "G"); this.clrMap.put("green", "G");
notColors = new ArrayList<String>(); this.notColors = new ArrayList<String>();
notColors.add("white"); this.notColors.add("white");
notColors.add("blue"); this.notColors.add("blue");
notColors.add("black"); this.notColors.add("black");
notColors.add("red"); this.notColors.add("red");
notColors.add("green"); this.notColors.add("green");
color1 = clr1; this.color1 = clr1;
color2 = clr2; this.color2 = clr2;
color3 = clr3; this.color3 = clr3;
color4 = clr4; this.color4 = clr4;
color5 = clr5; this.color5 = clr5;
notColors.remove(color1); this.notColors.remove(this.color1);
notColors.remove(color2); this.notColors.remove(this.color2);
notColors.remove(color3); this.notColors.remove(this.color3);
notColors.remove(color4); this.notColors.remove(this.color4);
notColors.remove(color5); this.notColors.remove(this.color5);
dl = GenerateDeckUtil.getDualLandList("WUBRG"); this.dl = GenerateDeckUtil.getDualLandList("WUBRG");
for (int i = 0; i < dl.size(); i++) { for (int i = 0; i < this.dl.size(); i++) {
cardCounts.put(dl.get(i), 0); this.cardCounts.put(this.dl.get(i), 0);
} }
} }
@@ -112,36 +112,39 @@ public class Generate5ColorDeck {
public final CardList get5ColorDeck(final int size, final PlayerType pt) { public final CardList get5ColorDeck(final int size, final PlayerType pt) {
int lc = 0; // loop counter to prevent infinite card selection loops int lc = 0; // loop counter to prevent infinite card selection loops
String tmpDeck = ""; String tmpDeck = "";
CardList tDeck = new CardList(); final CardList tDeck = new CardList();
int landsPercentage = 44; final int landsPercentage = 44;
int creatPercentage = 34; final int creatPercentage = 34;
int spellPercentage = 22; final int spellPercentage = 22;
// start with all cards // start with all cards
// remove cards that generated decks don't like // remove cards that generated decks don't like
CardList allCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { final CardList allCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
if (c.getSVar("RemRandomDeck").equals("True")) { if (c.getSVar("RemRandomDeck").equals("True")) {
return false; return false;
} }
return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN))); return (!c.getSVar("RemAIDeck").equals("True") || ((pt != null) && pt.equals(PlayerType.HUMAN)));
} }
}); });
// reduce to cards that match the colors // reduce to cards that match the colors
CardList cL1 = allCards.getColor(color1); CardList cL1 = allCards.getColor(this.color1);
cL1.addAll(allCards.getColor(Constant.Color.COLORLESS)); cL1.addAll(allCards.getColor(Constant.Color.COLORLESS));
CardList cL2 = allCards.getColor(color2); CardList cL2 = allCards.getColor(this.color2);
CardList cL3 = allCards.getColor(color3); CardList cL3 = allCards.getColor(this.color3);
CardList cL4 = allCards.getColor(color4); CardList cL4 = allCards.getColor(this.color4);
CardList cL5 = allCards.getColor(color5); CardList cL5 = allCards.getColor(this.color5);
// remove multicolor cards that don't match the colors // remove multicolor cards that don't match the colors
CardListFilter clrF = new CardListFilter() { final CardListFilter clrF = new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
for (int i = 0; i < notColors.size(); i++) { for (int i = 0; i < Generate5ColorDeck.this.notColors.size(); i++) {
if (c.getManaCost().contains(clrMap.get(notColors.get(i)))) { if (c.getManaCost().contains(
Generate5ColorDeck.this.clrMap.get(Generate5ColorDeck.this.notColors.get(i)))) {
return false; return false;
} }
} }
@@ -155,87 +158,88 @@ public class Generate5ColorDeck {
cL5 = cL5.filter(clrF); cL5 = cL5.filter(clrF);
// build subsets based on type // build subsets based on type
CardList cr1 = cL1.getType("Creature"); final CardList cr1 = cL1.getType("Creature");
CardList cr2 = cL2.getType("Creature"); final CardList cr2 = cL2.getType("Creature");
CardList cr3 = cL3.getType("Creature"); final CardList cr3 = cL3.getType("Creature");
CardList cr4 = cL4.getType("Creature"); final CardList cr4 = cL4.getType("Creature");
CardList cr5 = cL5.getType("Creature"); final CardList cr5 = cL5.getType("Creature");
String[] ise = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; final String[] ise = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" };
CardList sp1 = cL1.getValidCards(ise, null, null); final CardList sp1 = cL1.getValidCards(ise, null, null);
CardList sp2 = cL2.getValidCards(ise, null, null); final CardList sp2 = cL2.getValidCards(ise, null, null);
CardList sp3 = cL3.getValidCards(ise, null, null); final CardList sp3 = cL3.getValidCards(ise, null, null);
CardList sp4 = cL4.getValidCards(ise, null, null); final CardList sp4 = cL4.getValidCards(ise, null, null);
CardList sp5 = cL5.getValidCards(ise, null, null); final CardList sp5 = cL5.getValidCards(ise, null, null);
// final card pools // final card pools
CardList cr12345 = new CardList(); final CardList cr12345 = new CardList();
CardList sp12345 = new CardList(); final CardList sp12345 = new CardList();
// used for mana curve in the card pool // used for mana curve in the card pool
final int[] minCMC = { 1 }; final int[] minCMC = { 1 };
final int[] maxCMC = { 3 }; final int[] maxCMC = { 3 };
CardListFilter cmcF = new CardListFilter() { final CardListFilter cmcF = new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
int cCMC = c.getCMC(); final int cCMC = c.getCMC();
return (cCMC >= minCMC[0]) && (cCMC <= maxCMC[0]); return (cCMC >= minCMC[0]) && (cCMC <= maxCMC[0]);
} }
}; };
// select cards to build card pools using a mana curve // select cards to build card pools using a mana curve
for (int i = 3; i > 0; i--) { for (int i = 3; i > 0; i--) {
CardList cr1CMC = cr1.filter(cmcF); final CardList cr1CMC = cr1.filter(cmcF);
CardList cr2CMC = cr2.filter(cmcF); final CardList cr2CMC = cr2.filter(cmcF);
CardList cr3CMC = cr3.filter(cmcF); final CardList cr3CMC = cr3.filter(cmcF);
CardList cr4CMC = cr4.filter(cmcF); final CardList cr4CMC = cr4.filter(cmcF);
CardList cr5CMC = cr5.filter(cmcF); final CardList cr5CMC = cr5.filter(cmcF);
CardList sp1CMC = sp1.filter(cmcF); final CardList sp1CMC = sp1.filter(cmcF);
CardList sp2CMC = sp2.filter(cmcF); final CardList sp2CMC = sp2.filter(cmcF);
CardList sp3CMC = sp3.filter(cmcF); final CardList sp3CMC = sp3.filter(cmcF);
CardList sp4CMC = sp4.filter(cmcF); final CardList sp4CMC = sp4.filter(cmcF);
CardList sp5CMC = sp5.filter(cmcF); final CardList sp5CMC = sp5.filter(cmcF);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
Card c = cr1CMC.get(r.nextInt(cr1CMC.size())); Card c = cr1CMC.get(this.r.nextInt(cr1CMC.size()));
cr12345.add(c); cr12345.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = cr2CMC.get(r.nextInt(cr2CMC.size())); c = cr2CMC.get(this.r.nextInt(cr2CMC.size()));
cr12345.add(c); cr12345.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = cr3CMC.get(r.nextInt(cr3CMC.size())); c = cr3CMC.get(this.r.nextInt(cr3CMC.size()));
cr12345.add(c); cr12345.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = cr4CMC.get(r.nextInt(cr4CMC.size())); c = cr4CMC.get(this.r.nextInt(cr4CMC.size()));
cr12345.add(c); cr12345.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = cr5CMC.get(r.nextInt(cr5CMC.size())); c = cr5CMC.get(this.r.nextInt(cr5CMC.size()));
cr12345.add(c); cr12345.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = sp1CMC.get(r.nextInt(sp1CMC.size())); c = sp1CMC.get(this.r.nextInt(sp1CMC.size()));
sp12345.add(c); sp12345.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = sp2CMC.get(r.nextInt(sp2CMC.size())); c = sp2CMC.get(this.r.nextInt(sp2CMC.size()));
sp12345.add(c); sp12345.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = sp3CMC.get(r.nextInt(sp3CMC.size())); c = sp3CMC.get(this.r.nextInt(sp3CMC.size()));
sp12345.add(c); sp12345.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = sp4CMC.get(r.nextInt(sp4CMC.size())); c = sp4CMC.get(this.r.nextInt(sp4CMC.size()));
sp12345.add(c); sp12345.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
c = sp5CMC.get(r.nextInt(sp5CMC.size())); c = sp5CMC.get(this.r.nextInt(sp5CMC.size()));
sp12345.add(c); sp12345.add(c);
cardCounts.put(c.getName(), 0); this.cardCounts.put(c.getName(), 0);
} }
minCMC[0] += 2; minCMC[0] += 2;
@@ -253,21 +257,21 @@ public class Generate5ColorDeck {
sp12345.shuffle(); sp12345.shuffle();
// calculate card counts // calculate card counts
float p = (float) ((float) creatPercentage * .01); float p = (float) (creatPercentage * .01);
int creatCnt = (int) (p * (float) size); final int creatCnt = (int) (p * size);
tmpDeck += "Creature Count:" + creatCnt + "\n"; tmpDeck += "Creature Count:" + creatCnt + "\n";
p = (float) ((float) spellPercentage * .01); p = (float) (spellPercentage * .01);
int spellCnt = (int) (p * (float) size); final int spellCnt = (int) (p * size);
tmpDeck += "Spell Count:" + spellCnt + "\n"; tmpDeck += "Spell Count:" + spellCnt + "\n";
// build deck from the card pools // build deck from the card pools
for (int i = 0; i < creatCnt; i++) { for (int i = 0; i < creatCnt; i++) {
Card c = cr12345.get(r.nextInt(cr12345.size())); Card c = cr12345.get(this.r.nextInt(cr12345.size()));
lc = 0; lc = 0;
while (cardCounts.get(c.getName()) > 3 || lc > 100) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) {
c = cr12345.get(r.nextInt(cr12345.size())); c = cr12345.get(this.r.nextInt(cr12345.size()));
lc++; lc++;
} }
if (lc > 100) { if (lc > 100) {
@@ -275,17 +279,17 @@ public class Generate5ColorDeck {
} }
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
int n = cardCounts.get(c.getName()); final int n = this.cardCounts.get(c.getName());
cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; tmpDeck += c.getName() + " " + c.getManaCost() + "\n";
} }
for (int i = 0; i < spellCnt; i++) { for (int i = 0; i < spellCnt; i++) {
Card c = sp12345.get(r.nextInt(sp12345.size())); Card c = sp12345.get(this.r.nextInt(sp12345.size()));
lc = 0; lc = 0;
while (cardCounts.get(c.getName()) > 3 || lc > 100) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) {
c = sp12345.get(r.nextInt(sp12345.size())); c = sp12345.get(this.r.nextInt(sp12345.size()));
lc++; lc++;
} }
if (lc > 100) { if (lc > 100) {
@@ -293,16 +297,16 @@ public class Generate5ColorDeck {
} }
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
int n = cardCounts.get(c.getName()); final int n = this.cardCounts.get(c.getName());
cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; tmpDeck += c.getName() + " " + c.getManaCost() + "\n";
} }
// Add lands // Add lands
int numLands = 0; int numLands = 0;
if (landsPercentage > 0) { if (landsPercentage > 0) {
p = (float) ((float) landsPercentage * .01); p = (float) (landsPercentage * .01);
numLands = (int) (p * (float) size); numLands = (int) (p * size);
} else { // otherwise, just fill in the rest of the deck with basic } else { // otherwise, just fill in the rest of the deck with basic
// lands // lands
numLands = size - tDeck.size(); numLands = size - tDeck.size();
@@ -310,13 +314,13 @@ public class Generate5ColorDeck {
tmpDeck += "numLands:" + numLands + "\n"; tmpDeck += "numLands:" + numLands + "\n";
int nDLands = (numLands / 4); final int nDLands = (numLands / 4);
for (int i = 0; i < nDLands; i++) { for (int i = 0; i < nDLands; i++) {
String s = dl.get(r.nextInt(dl.size())); String s = this.dl.get(this.r.nextInt(this.dl.size()));
lc = 0; lc = 0;
while (cardCounts.get(s) > 3 || lc > 20) { while ((this.cardCounts.get(s) > 3) || (lc > 20)) {
s = dl.get(r.nextInt(dl.size())); s = this.dl.get(this.r.nextInt(this.dl.size()));
lc++; lc++;
} }
if (lc > 20) { if (lc > 20) {
@@ -324,8 +328,8 @@ public class Generate5ColorDeck {
} }
tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer())); tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer()));
int n = cardCounts.get(s); final int n = this.cardCounts.get(s);
cardCounts.put(s, n + 1); this.cardCounts.put(s, n + 1);
tmpDeck += s + "\n"; tmpDeck += s + "\n";
} }
@@ -334,17 +338,17 @@ public class Generate5ColorDeck {
if (numLands > 0) // attempt to optimize basic land counts according to if (numLands > 0) // attempt to optimize basic land counts according to
// color representation // color representation
{ {
CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
new CCnt("Mountain", 0), new CCnt("Forest", 0) }; new CCnt("Mountain", 0), new CCnt("Forest", 0) };
// count each card color using mana costs // count each card color using mana costs
// TODO: count hybrid mana differently? // TODO: count hybrid mana differently?
for (int i = 0; i < tDeck.size(); i++) { for (int i = 0; i < tDeck.size(); i++) {
String mc = tDeck.get(i).getManaCost(); final String mc = tDeck.get(i).getManaCost();
// count each mana symbol in the mana cost // count each mana symbol in the mana cost
for (int j = 0; j < mc.length(); j++) { for (int j = 0; j < mc.length(); j++) {
char c = mc.charAt(j); final char c = mc.charAt(j);
if (c == 'W') { if (c == 'W') {
clrCnts[0].setCount(clrCnts[0].getCount() + 1); clrCnts[0].setCount(clrCnts[0].getCount() + 1);
@@ -373,12 +377,12 @@ public class Generate5ColorDeck {
if (clrCnts[i].getCount() > 0) { // calculate number of lands if (clrCnts[i].getCount() > 0) { // calculate number of lands
// for each color // for each color
p = (float) clrCnts[i].getCount() / (float) totalColor; p = (float) clrCnts[i].getCount() / (float) totalColor;
int nLand = (int) ((float) numLands * p); final int nLand = (int) (numLands * p);
tmpDeck += "nLand-" + clrCnts[i].getColor() + ":" + nLand + "\n"; tmpDeck += "nLand-" + clrCnts[i].getColor() + ":" + nLand + "\n";
// just to prevent a null exception by the deck size fixing // just to prevent a null exception by the deck size fixing
// code // code
cardCounts.put(clrCnts[i].getColor(), nLand); this.cardCounts.put(clrCnts[i].getColor(), nLand);
for (int j = 0; j <= nLand; j++) { for (int j = 0; j <= nLand; j++) {
tDeck.add(AllZone.getCardFactory().getCard(clrCnts[i].getColor(), AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(clrCnts[i].getColor(), AllZone.getComputerPlayer()));
@@ -390,33 +394,33 @@ public class Generate5ColorDeck {
// fix under-sized or over-sized decks, due to integer arithmetic // fix under-sized or over-sized decks, due to integer arithmetic
if (tDeck.size() < size) { if (tDeck.size() < size) {
int diff = size - tDeck.size(); final int diff = size - tDeck.size();
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(r.nextInt(tDeck.size())); Card c = tDeck.get(this.r.nextInt(tDeck.size()));
lc = 0; lc = 0;
while (cardCounts.get(c.getName()) > 3 || lc > size) { while ((this.cardCounts.get(c.getName()) > 3) || (lc > size)) {
c = tDeck.get(r.nextInt(tDeck.size())); c = tDeck.get(this.r.nextInt(tDeck.size()));
lc++; lc++;
} }
if (lc > size) { if (lc > size) {
throw new RuntimeException("Generate5ColorDeck : get5ColorDeck -- looped too much -- undersize"); throw new RuntimeException("Generate5ColorDeck : get5ColorDeck -- looped too much -- undersize");
} }
int n = cardCounts.get(c.getName()); final int n = this.cardCounts.get(c.getName());
tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer()));
cardCounts.put(c.getName(), n + 1); this.cardCounts.put(c.getName(), n + 1);
tmpDeck += "Added:" + c.getName() + "\n"; tmpDeck += "Added:" + c.getName() + "\n";
} }
} else if (tDeck.size() > size) { } else if (tDeck.size() > size) {
int diff = tDeck.size() - size; final int diff = tDeck.size() - size;
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(r.nextInt(tDeck.size())); Card c = tDeck.get(this.r.nextInt(tDeck.size()));
while (c.isBasicLand()) { // don't remove basic lands while (c.isBasicLand()) { // don't remove basic lands
c = tDeck.get(r.nextInt(tDeck.size())); c = tDeck.get(this.r.nextInt(tDeck.size()));
} }
tDeck.remove(c); tDeck.remove(c);
@@ -433,7 +437,7 @@ public class Generate5ColorDeck {
} }
private class CCnt { private class CCnt {
private String color; private final String color;
private int count; private int count;
public CCnt(final String clr, final int cnt) { public CCnt(final String clr, final int cnt) {

View File

@@ -26,7 +26,7 @@ public class GenerateConstructedDeck {
private String color1; private String color1;
private String color2; private String color2;
private Map<String, String> map = new HashMap<String, String>(); private final Map<String, String> map = new HashMap<String, String>();
/** /**
* <p> * <p>
@@ -34,7 +34,7 @@ public class GenerateConstructedDeck {
* </p> * </p>
*/ */
public GenerateConstructedDeck() { public GenerateConstructedDeck() {
setupMap(); this.setupMap();
} }
/** /**
@@ -43,11 +43,11 @@ public class GenerateConstructedDeck {
* </p> * </p>
*/ */
private void setupMap() { private void setupMap() {
map.put(Constant.Color.BLACK, "Swamp"); this.map.put(Constant.Color.BLACK, "Swamp");
map.put(Constant.Color.BLUE, "Island"); this.map.put(Constant.Color.BLUE, "Island");
map.put(Constant.Color.GREEN, "Forest"); this.map.put(Constant.Color.GREEN, "Forest");
map.put(Constant.Color.RED, "Mountain"); this.map.put(Constant.Color.RED, "Mountain");
map.put(Constant.Color.WHITE, "Plains"); this.map.put(Constant.Color.WHITE, "Plains");
} }
/** /**
@@ -63,12 +63,12 @@ public class GenerateConstructedDeck {
int check; int check;
do { do {
deck = get2ColorDeck(); deck = this.get2ColorDeck();
check = deck.getType("Creature").size(); check = deck.getType("Creature").size();
} while (check < 16 || 24 < check); } while ((check < 16) || (24 < check));
addLand(deck); this.addLand(deck);
if (deck.size() != 60) { if (deck.size() != 60) {
throw new RuntimeException( throw new RuntimeException(
@@ -90,10 +90,10 @@ public class GenerateConstructedDeck {
private void addLand(final CardList list) { private void addLand(final CardList list) {
Card land; Card land;
for (int i = 0; i < 13; i++) { for (int i = 0; i < 13; i++) {
land = AllZone.getCardFactory().getCard(map.get(color1).toString(), AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.map.get(this.color1).toString(), AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(map.get(color2).toString(), AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.map.get(this.color2).toString(), AllZone.getComputerPlayer());
list.add(land); list.add(land);
} }
} // addLand() } // addLand()
@@ -109,7 +109,7 @@ public class GenerateConstructedDeck {
* never null * never null
*/ */
private CardList getCards() { private CardList getCards() {
return filterBadCards(AllZone.getCardFactory()); return this.filterBadCards(AllZone.getCardFactory());
} // getCards() } // getCards()
/** /**
@@ -120,14 +120,14 @@ public class GenerateConstructedDeck {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
private CardList get2ColorDeck() { private CardList get2ColorDeck() {
CardList deck = get2Colors(getCards()); final CardList deck = this.get2Colors(this.getCards());
CardList out = new CardList(); final CardList out = new CardList();
deck.shuffle(); deck.shuffle();
// trim deck size down to 34 cards, presumes 26 land, for a total of 60 // trim deck size down to 34 cards, presumes 26 land, for a total of 60
// cards // cards
for (int i = 0; i < 34 && i < deck.size(); i++) { for (int i = 0; (i < 34) && (i < deck.size()); i++) {
out.add(deck.get(i)); out.add(deck.get(i));
} }
return out; return out;
@@ -151,15 +151,16 @@ public class GenerateConstructedDeck {
b = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS); b = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS);
} while (a == b); // do not want to get the same color twice } while (a == b); // do not want to get the same color twice
color1 = Constant.Color.ONLY_COLORS[a]; this.color1 = Constant.Color.ONLY_COLORS[a];
color2 = Constant.Color.ONLY_COLORS[b]; this.color2 = Constant.Color.ONLY_COLORS[b];
CardList out = new CardList(); CardList out = new CardList();
out.addAll(CardListUtil.getColor(in, color1)); out.addAll(CardListUtil.getColor(in, this.color1));
out.addAll(CardListUtil.getColor(in, color2)); out.addAll(CardListUtil.getColor(in, this.color2));
out.shuffle(); out.shuffle();
CardList artifact = in.filter(new CardListFilter() { final CardList artifact = in.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
// is this really a colorless artifact and not something // is this really a colorless artifact and not something
// weird like Sarcomite Myr which is a colored artifact // weird like Sarcomite Myr which is a colored artifact
@@ -170,8 +171,9 @@ public class GenerateConstructedDeck {
out.addAll(artifact); out.addAll(artifact);
out = out.filter(new CardListFilter() { out = out.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
if (c.isCreature() && c.getNetAttack() <= 1 && Singletons.getModel().getPreferences().deckGenRmvSmall) { if (c.isCreature() && (c.getNetAttack() <= 1) && Singletons.getModel().getPreferences().deckGenRmvSmall) {
return false; return false;
} }
@@ -179,7 +181,7 @@ public class GenerateConstructedDeck {
} }
}); });
out = filterBadCards(out); out = this.filterBadCards(out);
return out; return out;
} }
@@ -197,18 +199,21 @@ public class GenerateConstructedDeck {
final ArrayList<Card> goodLand = new ArrayList<Card>(); final ArrayList<Card> goodLand = new ArrayList<Card>();
CardList out = CardFilter.filter(sequence, new CardListFilter() { final CardList out = CardFilter.filter(sequence, new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
ArrayList<String> list = CardUtil.getColors(c); final ArrayList<String> list = CardUtil.getColors(c);
if (list.size() == 2) { if (list.size() == 2) {
if (!(list.contains(color1) && list.contains(color2))) { if (!(list.contains(GenerateConstructedDeck.this.color1) && list
.contains(GenerateConstructedDeck.this.color2))) {
return false; return false;
} }
} }
return CardUtil.getColors(c).size() <= 2 // only dual colored return ((CardUtil.getColors(c).size() <= 2 // only dual colored
)
// gold cards // gold cards
&& !c.isLand() // no land && !c.isLand() // no land
&& !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True") && !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True"))
// OR very important // OR very important
|| goodLand.contains(c.getName()); || goodLand.contains(c.getName());
} }

View File

@@ -29,8 +29,8 @@ public class GenerateConstructedMultiColorDeck {
private String color4; private String color4;
private String color5; private String color5;
private Map<String, String> map = new HashMap<String, String>(); private final Map<String, String> map = new HashMap<String, String>();
private Map<String, String[]> multiMap = new HashMap<String, String[]>(); private final Map<String, String[]> multiMap = new HashMap<String, String[]>();
/** /**
* <p> * <p>
@@ -38,8 +38,8 @@ public class GenerateConstructedMultiColorDeck {
* </p> * </p>
*/ */
public GenerateConstructedMultiColorDeck() { public GenerateConstructedMultiColorDeck() {
setupBasicLandMap(); this.setupBasicLandMap();
setupMultiMap(); this.setupMultiMap();
} }
/** /**
@@ -48,11 +48,11 @@ public class GenerateConstructedMultiColorDeck {
* </p> * </p>
*/ */
private void setupBasicLandMap() { private void setupBasicLandMap() {
map.put(Constant.Color.BLACK, "Swamp"); this.map.put(Constant.Color.BLACK, "Swamp");
map.put(Constant.Color.BLUE, "Island"); this.map.put(Constant.Color.BLUE, "Island");
map.put(Constant.Color.GREEN, "Forest"); this.map.put(Constant.Color.GREEN, "Forest");
map.put(Constant.Color.RED, "Mountain"); this.map.put(Constant.Color.RED, "Mountain");
map.put(Constant.Color.WHITE, "Plains"); this.map.put(Constant.Color.WHITE, "Plains");
} }
/** /**
@@ -61,26 +61,30 @@ public class GenerateConstructedMultiColorDeck {
* </p> * </p>
*/ */
private void setupMultiMap() { private void setupMultiMap() {
multiMap.put(Constant.Color.BLACK + Constant.Color.BLUE, new String[] { "Underground Sea", "Watery Grave" }); this.multiMap.put(Constant.Color.BLACK + Constant.Color.BLUE,
multiMap.put(Constant.Color.BLACK + Constant.Color.GREEN, new String[] { "Bayou", "Overgrown Tomb" }); new String[] { "Underground Sea", "Watery Grave" });
multiMap.put(Constant.Color.BLACK + Constant.Color.RED, new String[] { "Badlands", "Blood Crypt" }); this.multiMap.put(Constant.Color.BLACK + Constant.Color.GREEN, new String[] { "Bayou", "Overgrown Tomb" });
multiMap.put(Constant.Color.BLACK + Constant.Color.WHITE, new String[] { "Scrubland", "Godless Shrine" }); this.multiMap.put(Constant.Color.BLACK + Constant.Color.RED, new String[] { "Badlands", "Blood Crypt" });
multiMap.put(Constant.Color.BLUE + Constant.Color.BLACK, new String[] { "Underground Sea", "Watery Grave" }); this.multiMap.put(Constant.Color.BLACK + Constant.Color.WHITE, new String[] { "Scrubland", "Godless Shrine" });
multiMap.put(Constant.Color.BLUE + Constant.Color.GREEN, new String[] { "Tropical Island", "Breeding Pool" }); this.multiMap.put(Constant.Color.BLUE + Constant.Color.BLACK,
multiMap.put(Constant.Color.BLUE + Constant.Color.RED, new String[] { "Volcanic Island", "Steam Vents" }); new String[] { "Underground Sea", "Watery Grave" });
multiMap.put(Constant.Color.BLUE + Constant.Color.WHITE, new String[] { "Tundra", "Hallowed Fountain" }); this.multiMap.put(Constant.Color.BLUE + Constant.Color.GREEN,
multiMap.put(Constant.Color.GREEN + Constant.Color.BLACK, new String[] { "Bayou", "Overgrown Tomb" }); new String[] { "Tropical Island", "Breeding Pool" });
multiMap.put(Constant.Color.GREEN + Constant.Color.BLUE, new String[] { "Tropical Island", "Breeding Pool" }); this.multiMap.put(Constant.Color.BLUE + Constant.Color.RED, new String[] { "Volcanic Island", "Steam Vents" });
multiMap.put(Constant.Color.GREEN + Constant.Color.RED, new String[] { "Taiga", "Stomping Ground" }); this.multiMap.put(Constant.Color.BLUE + Constant.Color.WHITE, new String[] { "Tundra", "Hallowed Fountain" });
multiMap.put(Constant.Color.GREEN + Constant.Color.WHITE, new String[] { "Savannah", "Temple Garden" }); this.multiMap.put(Constant.Color.GREEN + Constant.Color.BLACK, new String[] { "Bayou", "Overgrown Tomb" });
multiMap.put(Constant.Color.RED + Constant.Color.BLACK, new String[] { "Badlands", "Blood Crypt" }); this.multiMap.put(Constant.Color.GREEN + Constant.Color.BLUE,
multiMap.put(Constant.Color.RED + Constant.Color.BLUE, new String[] { "Volcanic Island", "Steam Vents" }); new String[] { "Tropical Island", "Breeding Pool" });
multiMap.put(Constant.Color.RED + Constant.Color.GREEN, new String[] { "Taiga", "Stomping Ground" }); this.multiMap.put(Constant.Color.GREEN + Constant.Color.RED, new String[] { "Taiga", "Stomping Ground" });
multiMap.put(Constant.Color.RED + Constant.Color.WHITE, new String[] { "Plateau", "Sacred Foundry" }); this.multiMap.put(Constant.Color.GREEN + Constant.Color.WHITE, new String[] { "Savannah", "Temple Garden" });
multiMap.put(Constant.Color.WHITE + Constant.Color.BLACK, new String[] { "Scrubland", "Godless Shrine" }); this.multiMap.put(Constant.Color.RED + Constant.Color.BLACK, new String[] { "Badlands", "Blood Crypt" });
multiMap.put(Constant.Color.WHITE + Constant.Color.BLUE, new String[] { "Tundra", "Hallowed Fountain" }); this.multiMap.put(Constant.Color.RED + Constant.Color.BLUE, new String[] { "Volcanic Island", "Steam Vents" });
multiMap.put(Constant.Color.WHITE + Constant.Color.GREEN, new String[] { "Savannah", "Temple Garden" }); this.multiMap.put(Constant.Color.RED + Constant.Color.GREEN, new String[] { "Taiga", "Stomping Ground" });
multiMap.put(Constant.Color.WHITE + Constant.Color.RED, new String[] { "Plateau", "Sacred Foundry" }); this.multiMap.put(Constant.Color.RED + Constant.Color.WHITE, new String[] { "Plateau", "Sacred Foundry" });
this.multiMap.put(Constant.Color.WHITE + Constant.Color.BLACK, new String[] { "Scrubland", "Godless Shrine" });
this.multiMap.put(Constant.Color.WHITE + Constant.Color.BLUE, new String[] { "Tundra", "Hallowed Fountain" });
this.multiMap.put(Constant.Color.WHITE + Constant.Color.GREEN, new String[] { "Savannah", "Temple Garden" });
this.multiMap.put(Constant.Color.WHITE + Constant.Color.RED, new String[] { "Plateau", "Sacred Foundry" });
} }
/** /**
@@ -96,12 +100,12 @@ public class GenerateConstructedMultiColorDeck {
int check; int check;
do { do {
deck = get3ColorDeck(); deck = this.get3ColorDeck();
check = deck.getType("Creature").size(); check = deck.getType("Creature").size();
} while (check < 16 || 24 < check); } while ((check < 16) || (24 < check));
addLand(deck, 3); this.addLand(deck, 3);
if (deck.size() != 60) { if (deck.size() != 60) {
throw new RuntimeException( throw new RuntimeException(
@@ -122,9 +126,9 @@ public class GenerateConstructedMultiColorDeck {
public final CardList generate5ColorDeck() { public final CardList generate5ColorDeck() {
CardList deck; CardList deck;
deck = get5ColorDeck(); deck = this.get5ColorDeck();
addLand(deck, 5); this.addLand(deck, 5);
if (deck.size() != 60) { if (deck.size() != 60) {
throw new RuntimeException( throw new RuntimeException(
@@ -147,92 +151,116 @@ public class GenerateConstructedMultiColorDeck {
*/ */
private void addLand(final CardList list, final int colors) { private void addLand(final CardList list, final int colors) {
if (colors == 3) { if (colors == 3) {
int numberBasic = 2; final int numberBasic = 2;
Card land; Card land;
for (int i = 0; i < numberBasic; i++) { for (int i = 0; i < numberBasic; i++) {
land = AllZone.getCardFactory().getCard(map.get(color1).toString(), AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.map.get(this.color1).toString(),
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(map.get(color2).toString(), AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.map.get(this.color2).toString(),
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(map.get(color3).toString(), AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.map.get(this.color3).toString(),
AllZone.getComputerPlayer());
list.add(land); list.add(land);
} }
int numberDual = 4; final int numberDual = 4;
for (int i = 0; i < numberDual; i++) { for (int i = 0; i < numberDual; i++) {
land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color2)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color2)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color3)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color3)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color2 + color3)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color3)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
} }
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color2)[1], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color2)[1],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color3)[1], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color3)[1],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color2 + color3)[1], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color3)[1],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
} }
} else if (colors == 5) { } else if (colors == 5) {
int numberBasic = 1; final int numberBasic = 1;
Card land; Card land;
for (int i = 0; i < numberBasic; i++) { for (int i = 0; i < numberBasic; i++) {
land = AllZone.getCardFactory().getCard(map.get(color1).toString(), AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.map.get(this.color1).toString(),
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(map.get(color2).toString(), AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.map.get(this.color2).toString(),
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(map.get(color3).toString(), AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.map.get(this.color3).toString(),
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(map.get(color4).toString(), AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.map.get(this.color4).toString(),
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(map.get(color5).toString(), AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.map.get(this.color5).toString(),
AllZone.getComputerPlayer());
list.add(land); list.add(land);
} }
int numberDual = 2; final int numberDual = 2;
for (int i = 0; i < numberDual; i++) { for (int i = 0; i < numberDual; i++) {
land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color2)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color2)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color3)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color3)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color4)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color4)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color5)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color5)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color2 + color3)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color3)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color2 + color4)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color4)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color2 + color5)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color5)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color3 + color4)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color3 + this.color4)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color3 + color5)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color3 + this.color5)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
land = AllZone.getCardFactory().getCard(multiMap.get(color4 + color5)[0], AllZone.getComputerPlayer()); land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color4 + this.color5)[0],
AllZone.getComputerPlayer());
list.add(land); list.add(land);
} }
@@ -251,7 +279,7 @@ public class GenerateConstructedMultiColorDeck {
* empty, but never null * empty, but never null
*/ */
private CardList getCards(final int colors) { private CardList getCards(final int colors) {
return filterBadCards(AllZone.getCardFactory(), colors); return this.filterBadCards(AllZone.getCardFactory(), colors);
} // getCards() } // getCards()
/** /**
@@ -262,14 +290,14 @@ public class GenerateConstructedMultiColorDeck {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
private CardList get3ColorDeck() { private CardList get3ColorDeck() {
CardList deck = get3Colors(getCards(3)); final CardList deck = this.get3Colors(this.getCards(3));
CardList out = new CardList(); final CardList out = new CardList();
deck.shuffle(); deck.shuffle();
// trim deck size down to 36 cards, presumes 24 land, for a total of 60 // trim deck size down to 36 cards, presumes 24 land, for a total of 60
// cards // cards
for (int i = 0; i < 36 && i < deck.size(); i++) { for (int i = 0; (i < 36) && (i < deck.size()); i++) {
out.add(deck.get(i)); out.add(deck.get(i));
} }
@@ -284,14 +312,14 @@ public class GenerateConstructedMultiColorDeck {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
private CardList get5ColorDeck() { private CardList get5ColorDeck() {
CardList deck = get5Colors(getCards(5)); final CardList deck = this.get5Colors(this.getCards(5));
CardList out = new CardList(); final CardList out = new CardList();
deck.shuffle(); deck.shuffle();
// trim deck size down to 36 cards, presumes 24 land, for a total of 60 // trim deck size down to 36 cards, presumes 24 land, for a total of 60
// cards // cards
for (int i = 0; i < 36 && i < deck.size(); i++) { for (int i = 0; (i < 36) && (i < deck.size()); i++) {
out.add(deck.get(i)); out.add(deck.get(i));
} }
@@ -316,20 +344,22 @@ public class GenerateConstructedMultiColorDeck {
do { do {
b = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS); b = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS);
c = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS); c = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS);
} while (a == b || a == c || b == c); // do not want to get the same } while ((a == b) || (a == c) || (b == c)); // do not want to get the
// same
// color thrice // color thrice
color1 = Constant.Color.ONLY_COLORS[a]; this.color1 = Constant.Color.ONLY_COLORS[a];
color2 = Constant.Color.ONLY_COLORS[b]; this.color2 = Constant.Color.ONLY_COLORS[b];
color3 = Constant.Color.ONLY_COLORS[c]; this.color3 = Constant.Color.ONLY_COLORS[c];
CardList out = new CardList(); CardList out = new CardList();
out.addAll(CardListUtil.getColor(in, color1)); out.addAll(CardListUtil.getColor(in, this.color1));
out.addAll(CardListUtil.getColor(in, color2)); out.addAll(CardListUtil.getColor(in, this.color2));
out.addAll(CardListUtil.getColor(in, color3)); out.addAll(CardListUtil.getColor(in, this.color3));
out.shuffle(); out.shuffle();
CardList artifact = in.filter(new CardListFilter() { final CardList artifact = in.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
// is this really a colorless artifact and not something // is this really a colorless artifact and not something
// wierd like Sarcomite Myr which is a colored artifact // wierd like Sarcomite Myr which is a colored artifact
@@ -340,8 +370,9 @@ public class GenerateConstructedMultiColorDeck {
out.addAll(artifact); out.addAll(artifact);
out = out.filter(new CardListFilter() { out = out.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
if (c.isCreature() && c.getNetAttack() <= 1 && Singletons.getModel().getPreferences().deckGenRmvSmall) { if (c.isCreature() && (c.getNetAttack() <= 1) && Singletons.getModel().getPreferences().deckGenRmvSmall) {
return false; return false;
} }
@@ -349,7 +380,7 @@ public class GenerateConstructedMultiColorDeck {
} }
}); });
out = filterBadCards(out, 3); out = this.filterBadCards(out, 3);
return out; return out;
} }
@@ -364,11 +395,11 @@ public class GenerateConstructedMultiColorDeck {
*/ */
private CardList get5Colors(final CardList in) { private CardList get5Colors(final CardList in) {
color1 = Constant.Color.BLACK; this.color1 = Constant.Color.BLACK;
color2 = Constant.Color.BLUE; this.color2 = Constant.Color.BLUE;
color3 = Constant.Color.GREEN; this.color3 = Constant.Color.GREEN;
color4 = Constant.Color.RED; this.color4 = Constant.Color.RED;
color5 = Constant.Color.WHITE; this.color5 = Constant.Color.WHITE;
CardList out = new CardList(); CardList out = new CardList();
/* /*
@@ -381,7 +412,8 @@ public class GenerateConstructedMultiColorDeck {
out.addAll(CardListUtil.getGoldCards(in)); out.addAll(CardListUtil.getGoldCards(in));
out.shuffle(); out.shuffle();
CardList artifact = in.filter(new CardListFilter() { final CardList artifact = in.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
// is this really a colorless artifact and not something // is this really a colorless artifact and not something
// wierd like Sarcomite Myr which is a colored artifact // wierd like Sarcomite Myr which is a colored artifact
@@ -392,8 +424,9 @@ public class GenerateConstructedMultiColorDeck {
out.addAll(artifact); out.addAll(artifact);
out = out.filter(new CardListFilter() { out = out.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
if (c.isCreature() && c.getNetAttack() <= 1 && Singletons.getModel().getPreferences().deckGenRmvSmall) { if (c.isCreature() && (c.getNetAttack() <= 1) && Singletons.getModel().getPreferences().deckGenRmvSmall) {
return false; return false;
} }
@@ -401,7 +434,7 @@ public class GenerateConstructedMultiColorDeck {
} }
}); });
out = filterBadCards(out, 3); out = this.filterBadCards(out, 3);
return out; return out;
} }
@@ -429,36 +462,43 @@ public class GenerateConstructedMultiColorDeck {
if (colors == 3) { if (colors == 3) {
out = CardFilter.filter(sequence, new CardListFilter() { out = CardFilter.filter(sequence, new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
ArrayList<String> list = CardUtil.getColors(c); final ArrayList<String> list = CardUtil.getColors(c);
if (list.size() == 3) { if (list.size() == 3) {
if (!list.contains(color1) || !list.contains(color2) || !list.contains(color3)) { if (!list.contains(GenerateConstructedMultiColorDeck.this.color1)
|| !list.contains(GenerateConstructedMultiColorDeck.this.color2)
|| !list.contains(GenerateConstructedMultiColorDeck.this.color3)) {
return false; return false;
} }
} else if (list.size() == 2) { } else if (list.size() == 2) {
if (!(list.contains(color1) && list.contains(color2)) if (!(list.contains(GenerateConstructedMultiColorDeck.this.color1) && list
&& !(list.contains(color1) && list.contains(color3)) .contains(GenerateConstructedMultiColorDeck.this.color2))
&& !(list.contains(color2) && list.contains(color3))) { && !(list.contains(GenerateConstructedMultiColorDeck.this.color1) && list
.contains(GenerateConstructedMultiColorDeck.this.color3))
&& !(list.contains(GenerateConstructedMultiColorDeck.this.color2) && list
.contains(GenerateConstructedMultiColorDeck.this.color3))) {
return false; return false;
} }
} }
return CardUtil.getColors(c).size() <= 3 && !c.isLand() && // no return ((CardUtil.getColors(c).size() <= 3) && !c.isLand() && // no
// land // land
!c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True") || !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) ||
// OR very important // OR very important
goodLand.contains(c.getName()); goodLand.contains(c.getName());
} }
}); });
} else if (colors == 5) { } else if (colors == 5) {
out = CardFilter.filter(sequence, new CardListFilter() { out = CardFilter.filter(sequence, new CardListFilter() {
@Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
return CardUtil.getColors(c).size() >= 2 && // only get return ((CardUtil.getColors(c).size() >= 2) && // only get
// multicolored // multicolored
// cards // cards
!c.isLand() && // no land !c.isLand() && // no land
!c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True") || !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) ||
// OR very important // OR very important
goodLand.contains(c.getName()); goodLand.contains(c.getName());
} }

View File

@@ -22,7 +22,7 @@ public class GenerateDeckUtil {
*/ */
public static ArrayList<String> getDualLandList(final String colors) { public static ArrayList<String> getDualLandList(final String colors) {
ArrayList<String> dLands = new ArrayList<String>(); final ArrayList<String> dLands = new ArrayList<String>();
if (colors.length() > 3) { if (colors.length() > 3) {
dLands.add("Rupture Spire"); dLands.add("Rupture Spire");

View File

@@ -43,9 +43,9 @@ public class GenerateThemeDeck {
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
*/ */
public final ArrayList<String> getThemeNames() { public final ArrayList<String> getThemeNames() {
ArrayList<String> ltNames = new ArrayList<String>(); final ArrayList<String> ltNames = new ArrayList<String>();
File file = new File("res/quest/themes/"); final File file = new File("res/quest/themes/");
if (!file.exists()) { if (!file.exists()) {
throw new RuntimeException("GenerateThemeDeck : getThemeNames error -- file not found -- filename is " throw new RuntimeException("GenerateThemeDeck : getThemeNames error -- file not found -- filename is "
@@ -57,10 +57,10 @@ public class GenerateThemeDeck {
+ file.getAbsolutePath()); + file.getAbsolutePath());
} }
String[] fileList = file.list(); final String[] fileList = file.list();
for (int i = 0; i < fileList.length; i++) { for (final String element : fileList) {
if (fileList[i].endsWith(".thm")) { if (element.endsWith(".thm")) {
ltNames.add(fileList[i].substring(0, fileList[i].indexOf(".thm"))); ltNames.add(element.substring(0, element.indexOf(".thm")));
} }
} }
@@ -79,55 +79,55 @@ public class GenerateThemeDeck {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final CardList getThemeDeck(final String themeName, final int size) { public final CardList getThemeDeck(final String themeName, final int size) {
CardList tDeck = new CardList(); final CardList tDeck = new CardList();
ArrayList<Grp> groups = new ArrayList<Grp>(); final ArrayList<Grp> groups = new ArrayList<Grp>();
Map<String, Integer> cardCounts = new HashMap<String, Integer>(); final Map<String, Integer> cardCounts = new HashMap<String, Integer>();
String s = ""; String s = "";
int bLandPercentage = 0; int bLandPercentage = 0;
boolean testing = false; boolean testing = false;
// read theme file // read theme file
String tFileName = "res/quest/themes/" + themeName + ".thm"; final String tFileName = "res/quest/themes/" + themeName + ".thm";
File tFile = new File(tFileName); final File tFile = new File(tFileName);
if (!tFile.exists()) { if (!tFile.exists()) {
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file not found -- filename is " throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file not found -- filename is "
+ tFile.getAbsolutePath()); + tFile.getAbsolutePath());
} }
try { try {
in = new BufferedReader(new FileReader(tFile)); this.in = new BufferedReader(new FileReader(tFile));
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex, "File \"%s\" exception", tFile.getAbsolutePath()); ErrorViewer.showError(ex, "File \"%s\" exception", tFile.getAbsolutePath());
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file exception -- filename is " throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file exception -- filename is "
+ tFile.getPath()); + tFile.getPath());
} }
s = readLine(); s = this.readLine();
while (!s.equals("End")) { while (!s.equals("End")) {
if (s.startsWith("[Group")) { if (s.startsWith("[Group")) {
Grp g = new Grp(); final Grp g = new Grp();
String[] ss = s.replaceAll("[\\[\\]]", "").split(" "); final String[] ss = s.replaceAll("[\\[\\]]", "").split(" ");
for (int i = 0; i < ss.length; i++) { for (final String element : ss) {
if (ss[i].startsWith("Percentage")) { if (element.startsWith("Percentage")) {
String p = ss[i].substring("Percentage".length() + 1); final String p = element.substring("Percentage".length() + 1);
g.Percentage = Integer.parseInt(p); g.Percentage = Integer.parseInt(p);
} }
if (ss[i].startsWith("MaxCnt")) { if (element.startsWith("MaxCnt")) {
String m = ss[i].substring("MaxCnt".length() + 1); final String m = element.substring("MaxCnt".length() + 1);
g.MaxCnt = Integer.parseInt(m); g.MaxCnt = Integer.parseInt(m);
} }
} }
s = readLine(); s = this.readLine();
while (!s.equals("[/Group]")) { while (!s.equals("[/Group]")) {
g.Cardnames.add(s); g.Cardnames.add(s);
cardCounts.put(s, 0); cardCounts.put(s, 0);
s = readLine(); s = this.readLine();
} }
groups.add(g); groups.add(g);
@@ -141,12 +141,12 @@ public class GenerateThemeDeck {
testing = true; testing = true;
} }
s = readLine(); s = this.readLine();
} }
try { try {
in.close(); this.in.close();
} catch (IOException ex) { } catch (final IOException ex) {
ErrorViewer.showError(ex, "File \"%s\" exception", tFile.getAbsolutePath()); ErrorViewer.showError(ex, "File \"%s\" exception", tFile.getAbsolutePath());
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file exception -- filename is " throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file exception -- filename is "
+ tFile.getPath()); + tFile.getPath());
@@ -155,20 +155,21 @@ public class GenerateThemeDeck {
String tmpDeck = ""; String tmpDeck = "";
// begin assigning cards to the deck // begin assigning cards to the deck
Random r = MyRandom.getRandom(); final Random r = MyRandom.getRandom();
for (int i = 0; i < groups.size(); i++) { for (int i = 0; i < groups.size(); i++) {
Grp g = groups.get(i); final Grp g = groups.get(i);
float p = (float) ((float) g.Percentage * .01); final float p = (float) (g.Percentage * .01);
int grpCnt = (int) (p * (float) size); final int grpCnt = (int) (p * size);
int cnSize = g.Cardnames.size(); final int cnSize = g.Cardnames.size();
tmpDeck += "Group" + i + ":" + grpCnt + "\n"; tmpDeck += "Group" + i + ":" + grpCnt + "\n";
for (int j = 0; j < grpCnt; j++) { for (int j = 0; j < grpCnt; j++) {
s = g.Cardnames.get(r.nextInt(cnSize)); s = g.Cardnames.get(r.nextInt(cnSize));
int lc = 0; int lc = 0;
while (cardCounts.get(s) >= g.MaxCnt || lc > size) // don't keep while ((cardCounts.get(s) >= g.MaxCnt) || (lc > size)) // don't
// keep
// looping // looping
// forever // forever
{ {
@@ -180,7 +181,7 @@ public class GenerateThemeDeck {
+ tFile.getAbsolutePath()); + tFile.getAbsolutePath());
} }
int n = cardCounts.get(s); final int n = cardCounts.get(s);
tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer()));
cardCounts.put(s, n + 1); cardCounts.put(s, n + 1);
tmpDeck += s + "\n"; tmpDeck += s + "\n";
@@ -190,8 +191,8 @@ public class GenerateThemeDeck {
int numBLands = 0; int numBLands = 0;
if (bLandPercentage > 0) { // if theme explicitly defines this if (bLandPercentage > 0) { // if theme explicitly defines this
float p = (float) ((float) bLandPercentage * .01); final float p = (float) (bLandPercentage * .01);
numBLands = (int) (p * (float) size); numBLands = (int) (p * size);
} else { // otherwise, just fill in the rest of the deck with basic } else { // otherwise, just fill in the rest of the deck with basic
// lands // lands
numBLands = size - tDeck.size(); numBLands = size - tDeck.size();
@@ -202,16 +203,16 @@ public class GenerateThemeDeck {
if (numBLands > 0) // attempt to optimize basic land counts according to if (numBLands > 0) // attempt to optimize basic land counts according to
// color representation // color representation
{ {
CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
new CCnt("Mountain", 0), new CCnt("Forest", 0) }; new CCnt("Mountain", 0), new CCnt("Forest", 0) };
// count each instance of a color in mana costs // count each instance of a color in mana costs
// TODO count hybrid mana differently? // TODO count hybrid mana differently?
for (int i = 0; i < tDeck.size(); i++) { for (int i = 0; i < tDeck.size(); i++) {
String mc = tDeck.get(i).getManaCost(); final String mc = tDeck.get(i).getManaCost();
for (int j = 0; j < mc.length(); j++) { for (int j = 0; j < mc.length(); j++) {
char c = mc.charAt(j); final char c = mc.charAt(j);
if (c == 'W') { if (c == 'W') {
clrCnts[0].Count++; clrCnts[0].Count++;
@@ -238,8 +239,8 @@ public class GenerateThemeDeck {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (clrCnts[i].Count > 0) { // calculate number of lands for if (clrCnts[i].Count > 0) { // calculate number of lands for
// each color // each color
float p = (float) clrCnts[i].Count / (float) totalColor; final float p = (float) clrCnts[i].Count / (float) totalColor;
int nLand = (int) ((float) numBLands * p); final int nLand = (int) (numBLands * p);
tmpDeck += "numLand-" + clrCnts[i].Color + ":" + nLand + "\n"; tmpDeck += "numLand-" + clrCnts[i].Color + ":" + nLand + "\n";
cardCounts.put(clrCnts[i].Color, 2); cardCounts.put(clrCnts[i].Color, 2);
@@ -252,7 +253,7 @@ public class GenerateThemeDeck {
tmpDeck += "DeckSize:" + tDeck.size() + "\n"; tmpDeck += "DeckSize:" + tDeck.size() + "\n";
if (tDeck.size() < size) { if (tDeck.size() < size) {
int diff = size - tDeck.size(); final int diff = size - tDeck.size();
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
s = tDeck.get(r.nextInt(tDeck.size())).getName(); s = tDeck.get(r.nextInt(tDeck.size())).getName();
@@ -261,13 +262,13 @@ public class GenerateThemeDeck {
s = tDeck.get(r.nextInt(tDeck.size())).getName(); s = tDeck.get(r.nextInt(tDeck.size())).getName();
} }
int n = cardCounts.get(s); final int n = cardCounts.get(s);
tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer())); tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer()));
cardCounts.put(s, n + 1); cardCounts.put(s, n + 1);
tmpDeck += "Added:" + s + "\n"; tmpDeck += "Added:" + s + "\n";
} }
} else if (tDeck.size() > size) { } else if (tDeck.size() > size) {
int diff = tDeck.size() - size; final int diff = tDeck.size() - size;
for (int i = 0; i < diff; i++) { for (int i = 0; i < diff; i++) {
Card c = tDeck.get(r.nextInt(tDeck.size())); Card c = tDeck.get(r.nextInt(tDeck.size()));
@@ -299,12 +300,12 @@ public class GenerateThemeDeck {
private String readLine() { private String readLine() {
// makes the checked exception, into an unchecked runtime exception // makes the checked exception, into an unchecked runtime exception
try { try {
String s = in.readLine(); String s = this.in.readLine();
if (s != null) { if (s != null) {
s = s.trim(); s = s.trim();
} }
return s; return s;
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("GenerateThemeDeck : readLine error"); throw new RuntimeException("GenerateThemeDeck : readLine error");
} }
@@ -332,8 +333,8 @@ public class GenerateThemeDeck {
* the cnt * the cnt
*/ */
public CCnt(final String clr, final int cnt) { public CCnt(final String clr, final int cnt) {
Color = clr; this.Color = clr;
Count = cnt; this.Count = cnt;
} }
} }

View File

@@ -1,2 +1,3 @@
/** Forge Card Game. */ /** Forge Card Game. */
package forge.deck.generate; package forge.deck.generate;

View File

@@ -1,2 +1,3 @@
/** Forge Card Game. */ /** Forge Card Game. */
package forge.deck; package forge.deck;