Checkstyle fixes in several files

This commit is contained in:
slapshot5
2011-09-02 05:57:44 +00:00
parent 24277f161c
commit e24da28385
12 changed files with 285 additions and 182 deletions

View File

@@ -22,7 +22,7 @@ class CCnt {
* @param clr a {@link java.lang.String} object. * @param clr a {@link java.lang.String} object.
* @param cnt a int. * @param cnt a int.
*/ */
public CCnt(String clr, int cnt) { public CCnt(final String clr, final int cnt) {
Color = clr; Color = clr;
Count = cnt; Count = cnt;
} }

View File

@@ -19,12 +19,12 @@ public interface CardContainer {
* *
* @param card a {@link forge.Card} object. * @param card a {@link forge.Card} object.
*/ */
public void setCard(Card card); void setCard(Card card);
/** /**
* <p>getCard.</p> * <p>getCard.</p>
* *
* @return a {@link forge.Card} object. * @return a {@link forge.Card} object.
*/ */
public Card getCard(); Card getCard();
} }

View File

@@ -11,7 +11,7 @@ import java.util.ArrayList;
*/ */
public class Card_Type implements Comparable<Card_Type> { public class Card_Type implements Comparable<Card_Type> {
// takes care of individual card types // takes care of individual card types
private ArrayList<String> type = new ArrayList<String>(); private ArrayList<String> type = new ArrayList<String>();
private boolean removeSuperTypes; private boolean removeSuperTypes;
private boolean removeCardTypes; private boolean removeCardTypes;
private boolean removeSubTypes; private boolean removeSubTypes;
@@ -23,57 +23,84 @@ public class Card_Type implements Comparable<Card_Type> {
* *
* @return a long. * @return a long.
*/ */
public long getTimestamp() { public final long getTimestamp() {
return timeStamp; return timeStamp;
} }
/** /**
* *
* @param types * @param types an ArrayList<String>
* @param removeSuperType * @param removeSuperType a boolean
* @param removeCardType * @param removeCardType a boolean
* @param removeSubType * @param removeSubType a boolean
* @param removeCreatureType * @param removeCreatureType a boolean
* @param stamp * @param stamp a long
*/ */
Card_Type(ArrayList<String> types, boolean removeSuperType, boolean removeCardType, boolean removeSubType, Card_Type(final ArrayList<String> types, final boolean removeSuperType, final boolean removeCardType,
boolean removeCreatureType, long stamp) { final boolean removeSubType, final boolean removeCreatureType, final long stamp)
type = types; {
removeSuperTypes = removeSuperType; type = types;
removeSuperTypes = removeSuperType;
removeCardTypes = removeCardType; removeCardTypes = removeCardType;
removeSubTypes = removeSubType; removeSubTypes = removeSubType;
removeCreatureTypes = removeCreatureType; removeCreatureTypes = removeCreatureType;
timeStamp = stamp; timeStamp = stamp;
}
/**
*
* TODO Write javadoc for this method.
* @return type
*/
public final ArrayList<String> getType() {
return type;
} }
public ArrayList<String> getType() { /**
return type; *
* TODO Write javadoc for this method.
* @return removeSuperTypes
*/
public final boolean isRemoveSuperTypes() {
return removeSuperTypes;
} }
public boolean isRemoveSuperTypes() { /**
return removeSuperTypes; *
* TODO Write javadoc for this method.
* @return removeCardTypes
*/
public final boolean isRemoveCardTypes() {
return removeCardTypes;
} }
public boolean isRemoveCardTypes() { /**
return removeCardTypes; *
* TODO Write javadoc for this method.
* @return removeSubTypes
*/
public final boolean isRemoveSubTypes() {
return removeSubTypes;
} }
public boolean isRemoveSubTypes() { /**
return removeSubTypes; *
} * TODO Write javadoc for this method.
* @return removeCreatureTypes
public boolean isRemoveCreatureTypes() { */
return removeCreatureTypes; public final boolean isRemoveCreatureTypes() {
return removeCreatureTypes;
} }
@Override @Override
public int compareTo(final Card_Type anotherCardType) { public final int compareTo(final Card_Type anotherCardType) {
int returnValue = 0; int returnValue = 0;
long anotherTimeStamp = anotherCardType.getTimestamp(); long anotherTimeStamp = anotherCardType.getTimestamp();
if (this.timeStamp < anotherTimeStamp) if (this.timeStamp < anotherTimeStamp) {
returnValue = -1; returnValue = -1;
else if (this.timeStamp > anotherTimeStamp) } else if (this.timeStamp > anotherTimeStamp) {
returnValue = 1; returnValue = 1;
}
return returnValue; return returnValue;
} }

View File

@@ -26,7 +26,7 @@ public enum Color {
* *
* @param c a int. * @param c a int.
*/ */
Color(int c) { Color(final int c) {
flag = c; flag = c;
} }
@@ -53,8 +53,9 @@ public enum Color {
colors.add(ConvertFromString(s[i])); colors.add(ConvertFromString(s[i]));
} }
if (colors.size() > 1) if (colors.size() > 1) {
colors.remove(Color.Colorless); colors.remove(Color.Colorless);
}
return colors; return colors;
} }
@@ -67,16 +68,17 @@ public enum Color {
*/ */
public static Color ConvertFromString(String s) { public static Color ConvertFromString(String s) {
{ {
if (s.equals(Constant.Color.White)) if (s.equals(Constant.Color.White)) {
return Color.White; return Color.White;
else if (s.equals(Constant.Color.Green)) } else if (s.equals(Constant.Color.Green)) {
return Color.Green; return Color.Green;
else if (s.equals(Constant.Color.Red)) } else if (s.equals(Constant.Color.Red)) {
return Color.Red; return Color.Red;
else if (s.equals(Constant.Color.Black)) } else if (s.equals(Constant.Color.Black)) {
return Color.Black; return Color.Black;
else if (s.equals(Constant.Color.Blue)) } else if (s.equals(Constant.Color.Blue)) {
return Color.Blue; return Color.Blue;
}
return Color.Colorless; return Color.Colorless;
} }
@@ -88,22 +90,28 @@ public enum Color {
* @param m a {@link forge.card.mana.ManaCost} object. * @param m a {@link forge.card.mana.ManaCost} object.
* @return a {@link java.util.EnumSet} object. * @return a {@link java.util.EnumSet} object.
*/ */
public static EnumSet<Color> ConvertManaCostToColor(ManaCost m) { public static EnumSet<Color> ConvertManaCostToColor(final ManaCost m) {
EnumSet<Color> colors = EnumSet.of(Color.Colorless); EnumSet<Color> colors = EnumSet.of(Color.Colorless);
if (m.isColor("W")) if (m.isColor("W")) {
colors.add(Color.White); colors.add(Color.White);
if (m.isColor("G")) }
if (m.isColor("G")) {
colors.add(Color.Green); colors.add(Color.Green);
if (m.isColor("R")) }
if (m.isColor("R")) {
colors.add(Color.Red); colors.add(Color.Red);
if (m.isColor("B")) }
if (m.isColor("B")) {
colors.add(Color.Black); colors.add(Color.Black);
if (m.isColor("U")) }
if (m.isColor("U")) {
colors.add(Color.Blue); colors.add(Color.Blue);
}
if (colors.size() > 1) if (colors.size() > 1) {
colors.remove(Color.Colorless); colors.remove(Color.Colorless);
}
return colors; return colors;
} }
@@ -114,17 +122,18 @@ public enum Color {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public String toString() { public String toString() {
if (this.equals(Color.White)) if (this.equals(Color.White)) {
return Constant.Color.White; return Constant.Color.White;
else if (this.equals(Color.Green)) } else if (this.equals(Color.Green)) {
return Constant.Color.Green; return Constant.Color.Green;
else if (this.equals(Color.Red)) } else if (this.equals(Color.Red)) {
return Constant.Color.Red; return Constant.Color.Red;
else if (this.equals(Color.Black)) } else if (this.equals(Color.Black)) {
return Constant.Color.Black; return Constant.Color.Black;
else if (this.equals(Color.Blue)) } else if (this.equals(Color.Blue)) {
return Constant.Color.Blue; return Constant.Color.Blue;
else } else {
return Constant.Color.Colorless; return Constant.Color.Colorless;
}
} }
} }

View File

@@ -4,6 +4,11 @@ import java.util.ArrayList;
import forge.card.mana.ManaCost; import forge.card.mana.ManaCost;
/**
* class ColorChanger.
* TODO Write javadoc for this type.
*
*/
public class ColorChanger { public class ColorChanger {
private ArrayList<Card_Color> globalColorChanges = new ArrayList<Card_Color>(); private ArrayList<Card_Color> globalColorChanges = new ArrayList<Card_Color>();
@@ -17,7 +22,9 @@ public class ColorChanger {
* @param bIncrease a boolean. * @param bIncrease a boolean.
* @return a long. * @return a long.
*/ */
public long addColorChanges(String s, Card c, boolean addToColors, boolean bIncrease) { public final long addColorChanges(final String s, final Card c, final boolean addToColors,
final boolean bIncrease)
{
if (bIncrease) { if (bIncrease) {
Card_Color.increaseTimestamp(); Card_Color.increaseTimestamp();
} }
@@ -33,7 +40,7 @@ public class ColorChanger {
* @param addTo a boolean. * @param addTo a boolean.
* @param timestamp a long. * @param timestamp a long.
*/ */
public final void removeColorChanges(String s, Card c, boolean addTo, long timestamp) { public final void removeColorChanges(final String s, final Card c, final boolean addTo, final long timestamp) {
Card_Color removeCol = null; Card_Color removeCol = null;
for (Card_Color cc : globalColorChanges) { for (Card_Color cc : globalColorChanges) {
if (cc.equals(s, c, addTo, timestamp)) { if (cc.equals(s, c, addTo, timestamp)) {

View File

@@ -12,5 +12,5 @@ public interface CommandArgs extends java.io.Serializable {
* *
* @param o a {@link java.lang.Object} object. * @param o a {@link java.lang.Object} object.
*/ */
public void execute(Object o); void execute(Object o);
} }

View File

@@ -10,17 +10,26 @@ import java.util.Iterator;
* @version $Id$ * @version $Id$
*/ */
public class CommandList implements java.io.Serializable, Command, Iterable<Command> { public class CommandList implements java.io.Serializable, Command, Iterable<Command> {
/** Constant <code>serialVersionUID=-1532687201812613302L</code> */ /** Constant <code>serialVersionUID=-1532687201812613302L</code>. */
private static final long serialVersionUID = -1532687201812613302L; private static final long serialVersionUID = -1532687201812613302L;
private ArrayList<Command> a = new ArrayList<Command>(); private ArrayList<Command> a = new ArrayList<Command>();
/**
* default constructor
* TODO Write javadoc for Constructor.
*/
public CommandList() { public CommandList() {
; //nothing to do
} }
public CommandList(Command c) { /**
a.add(c); * constructor
* TODO Write javadoc for Constructor.
* @param c a Command
*/
public CommandList(final Command c) {
a.add(c);
} }
/** /**
@@ -28,7 +37,7 @@ public class CommandList implements java.io.Serializable, Command, Iterable<Comm
* *
* @return a {@link java.util.Iterator} object. * @return a {@link java.util.Iterator} object.
*/ */
public Iterator<Command> iterator() { public final Iterator<Command> iterator() {
return a.iterator(); return a.iterator();
} }
@@ -40,7 +49,7 @@ public class CommandList implements java.io.Serializable, Command, Iterable<Comm
* *
* @param c a {@link forge.Command} object. * @param c a {@link forge.Command} object.
*/ */
public void add(Command c) { public final void add(final Command c) {
a.add(0, c); a.add(0, c);
} }
@@ -51,7 +60,7 @@ public class CommandList implements java.io.Serializable, Command, Iterable<Comm
* @param i a int. * @param i a int.
* @return a {@link forge.Command} object. * @return a {@link forge.Command} object.
*/ */
public Command get(int i) { public final Command get(final int i) {
return (Command) a.get(i); return (Command) a.get(i);
} }
@@ -61,7 +70,7 @@ public class CommandList implements java.io.Serializable, Command, Iterable<Comm
* @param i a int. * @param i a int.
* @return a {@link forge.Command} object. * @return a {@link forge.Command} object.
*/ */
public Command remove(int i) { public final Command remove(final int i) {
return (Command) a.remove(i); return (Command) a.remove(i);
} }
@@ -70,23 +79,24 @@ public class CommandList implements java.io.Serializable, Command, Iterable<Comm
* *
* @return a int. * @return a int.
*/ */
public int size() { public final int size() {
return a.size(); return a.size();
} }
/** /**
* <p>clear.</p> * <p>clear.</p>
*/ */
public void clear() { public final void clear() {
a.clear(); a.clear();
} }
/** /**
* <p>execute.</p> * <p>execute.</p>
*/ */
public void execute() { public final void execute() {
for (int i = 0; i < size(); i++) for (int i = 0; i < size(); i++) {
get(i).execute(); get(i).execute();
}
} }
} }

View File

@@ -12,5 +12,5 @@ public interface CommandReturn {
* *
* @return a {@link java.lang.Object} object. * @return a {@link java.lang.Object} object.
*/ */
public Object execute(); Object execute();
} }

View File

@@ -10,51 +10,51 @@ public interface Computer {
/** /**
* <p>main1.</p> * <p>main1.</p>
*/ */
public void main1(); void main1();
/** /**
* <p>begin_combat.</p> * <p>begin_combat.</p>
*/ */
public void begin_combat(); void begin_combat();
/** /**
* <p>declare_attackers.</p> * <p>declare_attackers.</p>
*/ */
public void declare_attackers(); void declare_attackers();
/** /**
* <p>declare_attackers_after.</p> * <p>declare_attackers_after.</p>
*/ */
public void declare_attackers_after(); //can play Instants and Abilities void declare_attackers_after(); //can play Instants and Abilities
/** /**
* <p>declare_blockers.</p> * <p>declare_blockers.</p>
*/ */
public void declare_blockers();//this is called after when the Human or Computer blocks void declare_blockers(); //this is called after when the Human or Computer blocks
/** /**
* <p>declare_blockers_after.</p> * <p>declare_blockers_after.</p>
*/ */
public void declare_blockers_after();//can play Instants and Abilities void declare_blockers_after(); //can play Instants and Abilities
/** /**
* <p>end_of_combat.</p> * <p>end_of_combat.</p>
*/ */
public void end_of_combat(); void end_of_combat();
/** /**
* <p>main2.</p> * <p>main2.</p>
*/ */
public void main2(); void main2();
/** /**
* <p>end_of_turn.</p> * <p>end_of_turn.</p>
*/ */
public void end_of_turn();//end of Human's turn void end_of_turn();//end of Human's turn
/** /**
* <p>stack_not_empty.</p> * <p>stack_not_empty.</p>
*/ */
public void stack_not_empty(); void stack_not_empty();
} }

View File

@@ -28,25 +28,27 @@ public class ComputerAI_General implements Computer {
/** /**
* <p>main1.</p> * <p>main1.</p>
*/ */
public void main1() { public final void main1() {
ComputerUtil.chooseLandsToPlay(); ComputerUtil.chooseLandsToPlay();
if (AllZone.getStack().size() == 0) if (AllZone.getStack().size() == 0) {
playCards(Constant.Phase.Main1); playCards(Constant.Phase.Main1);
else } else {
stackResponse(); stackResponse();
}//main1() }
} //main1()
/** /**
* <p>main2.</p> * <p>main2.</p>
*/ */
public void main2() { public final void main2() {
ComputerUtil.chooseLandsToPlay(); ComputerUtil.chooseLandsToPlay();
if (AllZone.getStack().size() == 0) if (AllZone.getStack().size() == 0) {
playCards(Constant.Phase.Main2); playCards(Constant.Phase.Main2);
else } else {
stackResponse(); stackResponse();
}
} }
/** /**
@@ -62,7 +64,7 @@ public class ComputerAI_General implements Computer {
if (nextPhase) { if (nextPhase) {
AllZone.getPhase().passPriority(); AllZone.getPhase().passPriority();
} }
}//playCards() } //playCards()
/** /**
* <p>getMain1.</p> * <p>getMain1.</p>
@@ -73,40 +75,52 @@ public class ComputerAI_General implements Computer {
//Card list of all cards to consider //Card list of all cards to consider
CardList hand = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer()); CardList hand = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer());
if (AllZone.getComputerManaPool().isEmpty()) if (AllZone.getComputerManaPool().isEmpty()) {
hand = hand.filter(new CardListFilter() { hand = hand.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
if (c.getSVar("PlayMain1").equals("TRUE")) if (c.getSVar("PlayMain1").equals("TRUE")) {
return true; return true;
}
if (c.isSorcery() || c.isAura()) //timing should be handled by the AF's //timing should be handled by the AF's
if (c.isSorcery() || c.isAura()) {
return true; return true;
}
if (c.isCreature() if (c.isCreature() && (c.hasKeyword("Haste")) || c.hasKeyword("Exalted")) {
&& (c.hasKeyword("Haste")) || c.hasKeyword("Exalted")) return true; return true;
}
CardList buffed = AllZoneUtil.getPlayerCardsInPlay(AllZone.getComputerPlayer()); //get all cards the computer controls with BuffedBy //get all cards the computer controls with BuffedBy
CardList buffed = AllZoneUtil.getPlayerCardsInPlay(AllZone.getComputerPlayer());
for (int j = 0; j < buffed.size(); j++) { for (int j = 0; j < buffed.size(); j++) {
Card buffedcard = buffed.get(j); Card buffedcard = buffed.get(j);
if (buffedcard.getSVar("BuffedBy").length() > 0) { if (buffedcard.getSVar("BuffedBy").length() > 0) {
String buffedby = buffedcard.getSVar("BuffedBy"); String buffedby = buffedcard.getSVar("BuffedBy");
String bffdby[] = buffedby.split(","); String[] bffdby = buffedby.split(",");
if (c.isValidCard(bffdby, c.getController(), c)) return true; if (c.isValidCard(bffdby, c.getController(), c)) {
return true;
}
} }
}//BuffedBy } //BuffedBy
CardList antibuffed = AllZoneUtil.getPlayerCardsInPlay(AllZone.getHumanPlayer()); //get all cards the human controls with AntiBuffedBy //get all cards the human controls with AntiBuffedBy
CardList antibuffed = AllZoneUtil.getPlayerCardsInPlay(AllZone.getHumanPlayer());
for (int k = 0; k < antibuffed.size(); k++) { for (int k = 0; k < antibuffed.size(); k++) {
Card buffedcard = antibuffed.get(k); Card buffedcard = antibuffed.get(k);
if (buffedcard.getSVar("AntiBuffedBy").length() > 0) { if (buffedcard.getSVar("AntiBuffedBy").length() > 0) {
String buffedby = buffedcard.getSVar("AntiBuffedBy"); String buffedby = buffedcard.getSVar("AntiBuffedBy");
String bffdby[] = buffedby.split(","); String[] bffdby = buffedby.split(",");
if (c.isValidCard(bffdby, c.getController(), c)) return true; if (c.isValidCard(bffdby, c.getController(), c)) {
return true;
}
} }
}//AntiBuffedBy } //AntiBuffedBy
if (c.isLand()) return false; if (c.isLand()) {
return false;
}
CardList vengevines = AllZoneUtil.getPlayerGraveyard(AllZone.getComputerPlayer(), "Vengevine"); CardList vengevines = AllZoneUtil.getPlayerGraveyard(AllZone.getComputerPlayer(), "Vengevine");
if (vengevines.size() > 0) { if (vengevines.size() > 0) {
@@ -120,18 +134,21 @@ public class ComputerAI_General implements Computer {
} }
if (creatures2.size() + Phase.getComputerCreatureSpellCount() > 1 if (creatures2.size() + Phase.getComputerCreatureSpellCount() > 1
&& c.isCreature() && c.isCreature()
&& CardUtil.getConvertedManaCost(c.getManaCost()) <= 3) return true; && CardUtil.getConvertedManaCost(c.getManaCost()) <= 3) {
return true;
}
} // AI Improvement for Vengevine } // AI Improvement for Vengevine
// Beached As End // Beached As End
return false; return false;
} }
}); });
}
CardList all = AllZoneUtil.getPlayerCardsInPlay(AllZone.getComputerPlayer()); CardList all = AllZoneUtil.getPlayerCardsInPlay(AllZone.getComputerPlayer());
all.addAll(hand); all.addAll(hand);
CardList humanPlayable = AllZoneUtil.getPlayerCardsInPlay(AllZone.getHumanPlayer()); CardList humanPlayable = AllZoneUtil.getPlayerCardsInPlay(AllZone.getHumanPlayer());
humanPlayable = humanPlayable.filter(new CardListFilter() { humanPlayable = humanPlayable.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
return (c.canAnyPlayerActivate()); return (c.canAnyPlayerActivate());
} }
}); });
@@ -139,7 +156,7 @@ public class ComputerAI_General implements Computer {
all.addAll(humanPlayable); all.addAll(humanPlayable);
return getPlayable(all); return getPlayable(all);
}//getMain1() } //getMain1()
/** /**
@@ -152,12 +169,14 @@ public class ComputerAI_General implements Computer {
CardList all = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer()); CardList all = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer());
//Don't play permanents with Flash before humans declare attackers step //Don't play permanents with Flash before humans declare attackers step
all = all.filter(new CardListFilter() { all = all.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
if (c.isPermanent() if (c.isPermanent()
&& c.hasKeyword("Flash") && c.hasKeyword("Flash")
&& (AllZone.getPhase().isPlayerTurn(AllZone.getComputerPlayer()) && (AllZone.getPhase().isPlayerTurn(AllZone.getComputerPlayer())
|| AllZone.getPhase().isBefore(Constant.Phase.Combat_Declare_Attackers_InstantAbility))) || AllZone.getPhase().isBefore(Constant.Phase.Combat_Declare_Attackers_InstantAbility)))
{
return false; return false;
}
return true; return true;
} }
}); });
@@ -168,22 +187,24 @@ public class ComputerAI_General implements Computer {
all = all.getNotKeyword("At the beginning of the end step, sacrifice CARDNAME."); all = all.getNotKeyword("At the beginning of the end step, sacrifice CARDNAME.");
all = all.filter(new CardListFilter() { all = all.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
if (c.isLand()) return false; if (c.isLand()) {
return false;
}
return true; return true;
} }
}); });
CardList humanPlayable = AllZoneUtil.getPlayerCardsInPlay(AllZone.getHumanPlayer()); CardList humanPlayable = AllZoneUtil.getPlayerCardsInPlay(AllZone.getHumanPlayer());
humanPlayable = humanPlayable.filter(new CardListFilter() { humanPlayable = humanPlayable.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
return (c.canAnyPlayerActivate()); return (c.canAnyPlayerActivate());
} }
}); });
all.addAll(humanPlayable); all.addAll(humanPlayable);
return getPlayable(all); return getPlayable(all);
}//getMain2() } //getMain2()
/** /**
* <p>getAvailableSpellAbilities.</p> * <p>getAvailableSpellAbilities.</p>
@@ -194,12 +215,14 @@ public class ComputerAI_General implements Computer {
CardList all = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer()); CardList all = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer());
//Don't play permanents with Flash before humans declare attackers step //Don't play permanents with Flash before humans declare attackers step
all = all.filter(new CardListFilter() { all = all.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
if (c.isPermanent() if (c.isPermanent()
&& c.hasKeyword("Flash") && c.hasKeyword("Flash")
&& (AllZone.getPhase().isPlayerTurn(AllZone.getComputerPlayer()) && (AllZone.getPhase().isPlayerTurn(AllZone.getComputerPlayer())
|| AllZone.getPhase().isBefore(Constant.Phase.Combat_Declare_Attackers_InstantAbility))) || AllZone.getPhase().isBefore(Constant.Phase.Combat_Declare_Attackers_InstantAbility)))
{
return false; return false;
}
return true; return true;
} }
}); });
@@ -209,7 +232,7 @@ public class ComputerAI_General implements Computer {
CardList humanPlayable = AllZoneUtil.getPlayerCardsInPlay(AllZone.getHumanPlayer()); CardList humanPlayable = AllZoneUtil.getPlayerCardsInPlay(AllZone.getHumanPlayer());
humanPlayable = humanPlayable.filter(new CardListFilter() { humanPlayable = humanPlayable.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
return (c.canAnyPlayerActivate()); return (c.canAnyPlayerActivate());
} }
}); });
@@ -245,15 +268,15 @@ public class ComputerAI_General implements Computer {
} }
/** /**
* Returns the spellAbilities from the card list that the computer is able to play * Returns the spellAbilities from the card list that the computer is able to play.
* *
* @param l a {@link forge.CardList} object. * @param l a {@link forge.CardList} object.
* @return an array of {@link forge.card.spellability.SpellAbility} objects. * @return an array of {@link forge.card.spellability.SpellAbility} objects.
*/ */
private SpellAbility[] getPlayable(CardList l) { private SpellAbility[] getPlayable(final CardList l) {
ArrayList<SpellAbility> spellAbility = new ArrayList<SpellAbility>(); ArrayList<SpellAbility> spellAbility = new ArrayList<SpellAbility>();
for (Card c : l) for (Card c : l) {
for (SpellAbility sa : c.getSpellAbility()) for (SpellAbility sa : c.getSpellAbility()) {
// if SA is from AF_Counter don't add to getPlayable // if SA is from AF_Counter don't add to getPlayable
//This try/catch should fix the "computer is thinking" bug //This try/catch should fix the "computer is thinking" bug
try { try {
@@ -264,6 +287,8 @@ public class ComputerAI_General implements Computer {
} catch (Exception ex) { } catch (Exception ex) {
showError(ex, "There is an error in the card code for %s:%n", c.getName(), ex.getMessage()); showError(ex, "There is an error in the card code for %s:%n", c.getName(), ex.getMessage());
} }
}
}
return spellAbility.toArray(new SpellAbility[spellAbility.size()]); return spellAbility.toArray(new SpellAbility[spellAbility.size()]);
} }
@@ -273,13 +298,14 @@ public class ComputerAI_General implements Computer {
* @param l a {@link forge.CardList} object. * @param l a {@link forge.CardList} object.
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
*/ */
private ArrayList<SpellAbility> getPlayableCounters(CardList l) { private ArrayList<SpellAbility> getPlayableCounters(final CardList l) {
ArrayList<SpellAbility> spellAbility = new ArrayList<SpellAbility>(); ArrayList<SpellAbility> spellAbility = new ArrayList<SpellAbility>();
for (Card c : l) { for (Card c : l) {
for (SpellAbility sa : c.getSpellAbility()) { for (SpellAbility sa : c.getSpellAbility()) {
// Check if this AF is a Counterpsell // Check if this AF is a Counterpsell
if (sa.getAbilityFactory() != null && sa.getAbilityFactory().getAPI().equals("Counter")) if (sa.getAbilityFactory() != null && sa.getAbilityFactory().getAPI().equals("Counter")) {
spellAbility.add(sa); spellAbility.add(sa);
}
} }
} }
@@ -292,14 +318,15 @@ public class ComputerAI_General implements Computer {
* @param l a {@link forge.CardList} object. * @param l a {@link forge.CardList} object.
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
*/ */
private ArrayList<SpellAbility> getETBCounters(CardList l) { private ArrayList<SpellAbility> getETBCounters(final CardList l) {
ArrayList<SpellAbility> spellAbility = new ArrayList<SpellAbility>(); ArrayList<SpellAbility> spellAbility = new ArrayList<SpellAbility>();
for (Card c : l) { for (Card c : l) {
for (SpellAbility sa : c.getSpellAbility()) { for (SpellAbility sa : c.getSpellAbility()) {
// Or if this Permanent has an ETB ability with Counter // Or if this Permanent has an ETB ability with Counter
if (sa instanceof Spell_Permanent) { if (sa instanceof Spell_Permanent) {
if (Spell_Permanent.checkETBEffects(c, sa, "Counter")) if (Spell_Permanent.checkETBEffects(c, sa, "Counter")) {
spellAbility.add(sa); spellAbility.add(sa);
}
} }
} }
} }
@@ -310,21 +337,22 @@ public class ComputerAI_General implements Computer {
/** /**
* <p>begin_combat.</p> * <p>begin_combat.</p>
*/ */
public void begin_combat() { public final void begin_combat() {
stackResponse(); stackResponse();
} }
/** /**
* <p>declare_attackers.</p> * <p>declare_attackers.</p>
*/ */
public void declare_attackers() { public final void declare_attackers() {
// 12/2/10(sol) the decision making here has moved to getAttackers() // 12/2/10(sol) the decision making here has moved to getAttackers()
AllZone.setCombat(ComputerUtil.getAttackers()); AllZone.setCombat(ComputerUtil.getAttackers());
Card[] att = AllZone.getCombat().getAttackers(); Card[] att = AllZone.getCombat().getAttackers();
if (att.length > 0) if (att.length > 0) {
AllZone.getPhase().setCombat(true); AllZone.getPhase().setCombat(true);
}
for (int i = 0; i < att.length; i++) { for (int i = 0; i < att.length; i++) {
// tapping of attackers happens after Propaganda is paid for // tapping of attackers happens after Propaganda is paid for
@@ -341,14 +369,14 @@ public class ComputerAI_General implements Computer {
/** /**
* <p>declare_attackers_after.</p> * <p>declare_attackers_after.</p>
*/ */
public void declare_attackers_after() { public final void declare_attackers_after() {
stackResponse(); stackResponse();
} }
/** /**
* <p>declare_blockers.</p> * <p>declare_blockers.</p>
*/ */
public void declare_blockers() { public final void declare_blockers() {
CardList blockers = AllZoneUtil.getCreaturesInPlay(AllZone.getComputerPlayer()); CardList blockers = AllZoneUtil.getCreaturesInPlay(AllZone.getComputerPlayer());
AllZone.setCombat(ComputerUtil_Block2.getBlockers(AllZone.getCombat(), blockers)); AllZone.setCombat(ComputerUtil_Block2.getBlockers(AllZone.getCombat(), blockers));
@@ -361,14 +389,14 @@ public class ComputerAI_General implements Computer {
/** /**
* <p>declare_blockers_after.</p> * <p>declare_blockers_after.</p>
*/ */
public void declare_blockers_after() { public final void declare_blockers_after() {
stackResponse(); stackResponse();
} }
/** /**
* <p>end_of_combat.</p> * <p>end_of_combat.</p>
*/ */
public void end_of_combat() { public final void end_of_combat() {
stackResponse(); stackResponse();
} }
@@ -376,35 +404,37 @@ public class ComputerAI_General implements Computer {
/** /**
* <p>end_of_turn.</p> * <p>end_of_turn.</p>
*/ */
public void end_of_turn() { public final void end_of_turn() {
stackResponse(); stackResponse();
} }
/** /**
* <p>stack_not_empty.</p> * <p>stack_not_empty.</p>
*/ */
public void stack_not_empty() { public final void stack_not_empty() {
stackResponse(); stackResponse();
} }
/** /**
* <p>stackResponse.</p> * <p>stackResponse.</p>
*/ */
public void stackResponse() { public final void stackResponse() {
// if top of stack is empty // if top of stack is empty
SpellAbility[] sas = null; SpellAbility[] sas = null;
if (AllZone.getStack().size() == 0) { if (AllZone.getStack().size() == 0) {
sas = getOtherPhases(); sas = getOtherPhases();
boolean pass = (sas.length == 0) || AllZone.getPhase().is(Constant.Phase.Upkeep, AllZone.getComputerPlayer()) || boolean pass = (sas.length == 0)
AllZone.getPhase().is(Constant.Phase.Draw, AllZone.getComputerPlayer()) || || AllZone.getPhase().is(Constant.Phase.Upkeep, AllZone.getComputerPlayer())
AllZone.getPhase().is(Constant.Phase.End_Of_Turn, AllZone.getComputerPlayer()); || AllZone.getPhase().is(Constant.Phase.Draw, AllZone.getComputerPlayer())
|| AllZone.getPhase().is(Constant.Phase.End_Of_Turn, AllZone.getComputerPlayer());
if (!pass) { // Each AF should check the phase individually if (!pass) { // Each AF should check the phase individually
pass = ComputerUtil.playCards(sas); pass = ComputerUtil.playCards(sas);
} }
if (pass) if (pass) {
AllZone.getPhase().passPriority(); AllZone.getPhase().passPriority();
}
return; return;
} }
@@ -435,8 +465,9 @@ public class ComputerAI_General implements Computer {
sas = getOtherPhases(); sas = getOtherPhases();
if (sas.length > 0) { if (sas.length > 0) {
// Spell not Countered // Spell not Countered
if (!ComputerUtil.playCards(sas)) if (!ComputerUtil.playCards(sas)) {
return; return;
}
} }
// if this hasn't been covered above, just PassPriority() // if this hasn't been covered above, just PassPriority()
AllZone.getPhase().passPriority(); AllZone.getPhase().passPriority();

View File

@@ -11,7 +11,7 @@ import forge.gui.input.Input;
* @version $Id$ * @version $Id$
*/ */
public class ComputerAI_Input extends Input { public class ComputerAI_Input extends Input {
/** Constant <code>serialVersionUID=-3091338639571662216L</code> */ /** Constant <code>serialVersionUID=-3091338639571662216L</code>. */
private static final long serialVersionUID = -3091338639571662216L; private static final long serialVersionUID = -3091338639571662216L;
private final Computer computer; private final Computer computer;
@@ -19,10 +19,10 @@ public class ComputerAI_Input extends Input {
/** /**
* <p>Constructor for ComputerAI_Input.</p> * <p>Constructor for ComputerAI_Input.</p>
* *
* @param i_computer a {@link forge.Computer} object. * @param iComputer a {@link forge.Computer} object.
*/ */
public ComputerAI_Input(Computer i_computer) { public ComputerAI_Input(final Computer iComputer) {
computer = i_computer; computer = iComputer;
} }
//wrapper method that ComputerAI_StackNotEmpty class calls //wrapper method that ComputerAI_StackNotEmpty class calls
@@ -30,29 +30,30 @@ public class ComputerAI_Input extends Input {
/** /**
* <p>stackNotEmpty.</p> * <p>stackNotEmpty.</p>
*/ */
public void stackNotEmpty() { public final void stackNotEmpty() {
computer.stack_not_empty(); computer.stack_not_empty();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void showMessage() { public final void showMessage() {
/* /*
* //put this back in * //put this back in
ButtonUtil.disableAll(); ButtonUtil.disableAll();
AllZone.getDisplay().showMessage("Phase: " AllZone.getDisplay().showMessage("Phase: "
+ AllZone.getPhase().getPhase() + AllZone.getPhase().getPhase()
+ "\nAn error may have occurred. Please send the \"Stack Report\" and the \"Detailed Error Trace\" to the Forge forum."); + "\nAn error may have occurred. Please send the \"Stack Report\" and the
\"Detailed Error Trace\" to the Forge forum.");
*/ */
think(); think();
}//getMessage(); } //getMessage();
/** /**
* <p>Getter for the field <code>computer</code>.</p> * <p>Getter for the field <code>computer</code>.</p>
* *
* @return a {@link forge.Computer} object. * @return a {@link forge.Computer} object.
*/ */
public Computer getComputer() { public final Computer getComputer() {
return computer; return computer;
} }
@@ -60,12 +61,12 @@ public class ComputerAI_Input extends Input {
* <p>think.</p> * <p>think.</p>
*/ */
private void think() { private void think() {
//TODO: instead of setNextPhase, pass priority //TODO instead of setNextPhase, pass priority
final String phase = AllZone.getPhase().getPhase(); final String phase = AllZone.getPhase().getPhase();
if (AllZone.getStack().size() > 0) if (AllZone.getStack().size() > 0) {
computer.stack_not_empty(); computer.stack_not_empty();
else if (phase.equals(Constant.Phase.Main1)) { } else if (phase.equals(Constant.Phase.Main1)) {
Log.debug("Computer main1"); Log.debug("Computer main1");
computer.main1(); computer.main1();
} else if (phase.equals(Constant.Phase.Combat_Begin)) { } else if (phase.equals(Constant.Phase.Combat_Begin)) {
@@ -81,8 +82,9 @@ public class ComputerAI_Input extends Input {
} else if (phase.equals(Constant.Phase.Main2)) { } else if (phase.equals(Constant.Phase.Main2)) {
Log.debug("Computer main2"); Log.debug("Computer main2");
computer.main2(); computer.main2();
} else } else {
computer.stack_not_empty(); computer.stack_not_empty();
}
}//think } //think
} }

View File

@@ -26,7 +26,7 @@ public class ComputerUtil_Attack2 {
private final int randomInt = random.nextInt(); private final int randomInt = random.nextInt();
private CardList humanList; //holds human player creatures private CardList humanList; //holds human player creatures
private CardList computerList;//holds computer creatures private CardList computerList; //holds computer creatures
private int aiAggression = 0; // added by Masher, how aggressive the ai attack will be depending on circumstances private int aiAggression = 0; // added by Masher, how aggressive the ai attack will be depending on circumstances
@@ -48,7 +48,7 @@ public class ComputerUtil_Attack2 {
* @param possibleBlockers a {@link forge.CardList} object. * @param possibleBlockers a {@link forge.CardList} object.
* @param blockerLife a int. * @param blockerLife a int.
*/ */
public ComputerUtil_Attack2(CardList possibleAttackers, CardList possibleBlockers, int blockerLife) { public ComputerUtil_Attack2(final CardList possibleAttackers, CardList possibleBlockers, int blockerLife) {
humanList = new CardList(possibleBlockers.toArray()); humanList = new CardList(possibleBlockers.toArray());
humanList = humanList.getType("Creature"); humanList = humanList.getType("Creature");
@@ -60,7 +60,7 @@ public class ComputerUtil_Attack2 {
attackers = getPossibleAttackers(possibleAttackers); attackers = getPossibleAttackers(possibleAttackers);
blockers = getPossibleBlockers(possibleBlockers, attackers); blockers = getPossibleBlockers(possibleBlockers, attackers);
this.blockerLife = blockerLife; this.blockerLife = blockerLife;
}//constructor } //constructor
/** /**
* <p>sortAttackers.</p> * <p>sortAttackers.</p>
@@ -68,7 +68,7 @@ public class ComputerUtil_Attack2 {
* @param in a {@link forge.CardList} object. * @param in a {@link forge.CardList} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public CardList sortAttackers(CardList in) { public final CardList sortAttackers(final CardList in) {
CardList list = new CardList(); CardList list = new CardList();
//Cards with triggers should come first (for Battle Cry) //Cards with triggers should come first (for Battle Cry)
@@ -76,17 +76,20 @@ public class ComputerUtil_Attack2 {
ArrayList<Trigger> registeredTriggers = AllZone.getTriggerHandler().getRegisteredTriggers(); ArrayList<Trigger> registeredTriggers = AllZone.getTriggerHandler().getRegisteredTriggers();
for (Trigger trigger : registeredTriggers) { for (Trigger trigger : registeredTriggers) {
HashMap<String, String> trigParams = trigger.getMapParams(); HashMap<String, String> trigParams = trigger.getMapParams();
if (trigParams.get("Mode").equals("Attacks") && trigger.getHostCard().equals(attacker)) if (trigParams.get("Mode").equals("Attacks") && trigger.getHostCard().equals(attacker)) {
list.add(attacker); list.add(attacker);
}
} }
} }
for (Card attacker : in) { for (Card attacker : in) {
if (!list.contains(attacker)) list.add(attacker); if (!list.contains(attacker)) {
list.add(attacker);
}
} }
return list; return list;
}//sortAttackers() } //sortAttackers()
//Is there any reward for attacking? (for 0/1 creatures there is not) //Is there any reward for attacking? (for 0/1 creatures there is not)
/** /**
@@ -96,19 +99,27 @@ public class ComputerUtil_Attack2 {
* @param combat a {@link forge.Combat} object. * @param combat a {@link forge.Combat} object.
* @return a boolean. * @return a boolean.
*/ */
public boolean isEffectiveAttacker(Card attacker, Combat combat) { public final boolean isEffectiveAttacker(final Card attacker, Combat combat) {
//if the attacker will die when attacking don't attack //if the attacker will die when attacking don't attack
if (attacker.getNetDefense() + CombatUtil.predictToughnessBonusOfAttacker(attacker, null, combat) <= 0) if (attacker.getNetDefense() + CombatUtil.predictToughnessBonusOfAttacker(attacker, null, combat) <= 0) {
return false; return false;
}
if (CombatUtil.damageIfUnblocked(attacker, AllZone.getHumanPlayer(), combat) > 0) return true; if (CombatUtil.damageIfUnblocked(attacker, AllZone.getHumanPlayer(), combat) > 0) {
if (CombatUtil.poisonIfUnblocked(attacker, AllZone.getHumanPlayer(), combat) > 0) return true; return true;
}
if (CombatUtil.poisonIfUnblocked(attacker, AllZone.getHumanPlayer(), combat) > 0) {
return true;
}
ArrayList<Trigger> registeredTriggers = AllZone.getTriggerHandler().getRegisteredTriggers(); ArrayList<Trigger> registeredTriggers = AllZone.getTriggerHandler().getRegisteredTriggers();
for (Trigger trigger : registeredTriggers) for (Trigger trigger : registeredTriggers) {
if (CombatUtil.combatTriggerWillTrigger(attacker, null, trigger, combat) if (CombatUtil.combatTriggerWillTrigger(attacker, null, trigger, combat)
&& trigger.getHostCard().getController().isComputer()) return true; && trigger.getHostCard().getController().isComputer()) {
return true;
}
}
return false; return false;
} }
@@ -122,12 +133,12 @@ public class ComputerUtil_Attack2 {
public CardList getPossibleAttackers(CardList in) { public CardList getPossibleAttackers(CardList in) {
CardList list = new CardList(in.toArray()); CardList list = new CardList(in.toArray());
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
return CombatUtil.canAttack(c); return CombatUtil.canAttack(c);
} }
}); });
return list; return list;
}//getPossibleAttackers() } //getPossibleAttackers()
/** /**
* <p>getPossibleBlockers.</p> * <p>getPossibleBlockers.</p>
@@ -136,14 +147,18 @@ public class ComputerUtil_Attack2 {
* @param attackers a {@link forge.CardList} object. * @param attackers a {@link forge.CardList} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public CardList getPossibleBlockers(CardList blockers, CardList attackers) { public final CardList getPossibleBlockers(CardList blockers, CardList attackers) {
CardList possibleBlockers = new CardList(blockers.toArray()); CardList possibleBlockers = new CardList(blockers.toArray());
final CardList attackerList = new CardList(attackers.toArray()); final CardList attackerList = new CardList(attackers.toArray());
possibleBlockers = possibleBlockers.filter(new CardListFilter() { possibleBlockers = possibleBlockers.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
if (!c.isCreature()) return false; if (!c.isCreature()) {
return false;
}
for (Card attacker : attackerList) { for (Card attacker : attackerList) {
if (CombatUtil.canBlock(attacker, c)) return true; if (CombatUtil.canBlock(attacker, c)) {
return true;
}
} }
return false; return false;
} }
@@ -161,7 +176,7 @@ public class ComputerUtil_Attack2 {
* @param combat a {@link forge.Combat} object. * @param combat a {@link forge.Combat} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public CardList notNeededAsBlockers(CardList attackers, Combat combat) { public final CardList notNeededAsBlockers(CardList attackers, Combat combat) {
CardList notNeededAsBlockers = new CardList(attackers.toArray()); CardList notNeededAsBlockers = new CardList(attackers.toArray());
CardListUtil.sortAttackLowFirst(attackers); CardListUtil.sortAttackLowFirst(attackers);
int blockersNeeded = attackers.size(); int blockersNeeded = attackers.size();
@@ -173,7 +188,9 @@ public class ComputerUtil_Attack2 {
if (!doesHumanAttackAndWin(i)) { if (!doesHumanAttackAndWin(i)) {
blockersNeeded = i; blockersNeeded = i;
break; break;
} else notNeededAsBlockers.remove(list.get(i)); } else {
notNeededAsBlockers.remove(list.get(i));
}
} }
if (blockersNeeded == list.size()) { if (blockersNeeded == list.size()) {