- The AI can now use mana abilities that produce the chosen color.

- Refactoring to prevent duplicate code in AbilityMana. 
- Commented out two unused functions in ComputerUtil.
This commit is contained in:
Sloth
2012-02-20 09:48:20 +00:00
parent 33d5d7d080
commit 61b4ea4eb1
8 changed files with 38 additions and 27 deletions

View File

@@ -3,11 +3,10 @@ ManaCost:4
Types:Artifact Types:Artifact
Text:no text Text:no text
T:Mode$ ChangesZone | Origin$ Any | Destination$ Battlefield | ValidCard$ Card.Self | Static$ True | Execute$ TrigChooseColor | TriggerDescription$ As CARDNAME enters the battlefield, choose a color. T:Mode$ ChangesZone | Origin$ Any | Destination$ Battlefield | ValidCard$ Card.Self | Static$ True | Execute$ TrigChooseColor | TriggerDescription$ As CARDNAME enters the battlefield, choose a color.
SVar:TrigChooseColor:AB$ ChooseColor | Cost$ 0 SVar:TrigChooseColor:AB$ ChooseColor | Cost$ 0 | AILogic$ MostProminentInComputerDeck
T:Mode$ SpellCast | ValidCard$ Card.ChosenColor | OptionalDecider$ You | Execute$ TrigGainLife | TriggerZones$ Battlefield | TriggerDescription$ Whenever a player casts a spell of the chosen color, you may gain 1 life. T:Mode$ SpellCast | ValidCard$ Card.ChosenColor | OptionalDecider$ You | Execute$ TrigGainLife | TriggerZones$ Battlefield | TriggerDescription$ Whenever a player casts a spell of the chosen color, you may gain 1 life.
SVar:TrigGainLife:AB$ GainLife | Cost$ 0 | LifeAmount$ 1 SVar:TrigGainLife:AB$ GainLife | Cost$ 0 | LifeAmount$ 1
A:AB$ Mana | Cost$ T | Produced$ Chosen | SpellDescription$ Add one mana of the chosen color to your mana pool. A:AB$ Mana | Cost$ T | Produced$ Chosen | SpellDescription$ Add one mana of the chosen color to your mana pool.
SVar:RemAIDeck:True
SVar:Rarity:Uncommon SVar:Rarity:Uncommon
SVar:Picture:http://www.wizards.com/global/images/magic/general/paradise_plume.jpg SVar:Picture:http://www.wizards.com/global/images/magic/general/paradise_plume.jpg
SetInfo:TSP|Uncommon|http://magiccards.info/scans/en/ts/260.jpg SetInfo:TSP|Uncommon|http://magiccards.info/scans/en/ts/260.jpg

View File

@@ -5,9 +5,8 @@ Text:no text
PT:1/3 PT:1/3
K:Reach K:Reach
T:Mode$ ChangesZone | ValidCard$ Card.Self | Origin$ Any | Destination$ Battlefield | Execute$ ChooseColor | Static$ True | TriggerDescription$ As CARDNAME enters the battlefield, choose a color. T:Mode$ ChangesZone | ValidCard$ Card.Self | Origin$ Any | Destination$ Battlefield | Execute$ ChooseColor | Static$ True | TriggerDescription$ As CARDNAME enters the battlefield, choose a color.
SVar:ChooseColor:DB$ ChooseColor | Defined$ You SVar:ChooseColor:DB$ ChooseColor | Defined$ You | AILogic$ MostProminentInComputerDeck
A:AB$ Mana | Cost$ T | Produced$ Chosen | SpellDescription$ Add one mana of the chosen color to your mana pool. A:AB$ Mana | Cost$ T | Produced$ Chosen | SpellDescription$ Add one mana of the chosen color to your mana pool.
SVar:RemAIDeck:True
SVar:Rarity:Common SVar:Rarity:Common
SVar:Picture:http://www.wizards.com/global/images/magic/general/silhana_starfletcher.jpg SVar:Picture:http://www.wizards.com/global/images/magic/general/silhana_starfletcher.jpg
SetInfo:GPT|Common|http://magiccards.info/scans/en/gp/95.jpg SetInfo:GPT|Common|http://magiccards.info/scans/en/gp/95.jpg

View File

@@ -920,7 +920,7 @@ public class ComputerUtil {
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
* @since 1.0.15 * @since 1.0.15
*/ */
public static ArrayList<String> getProduceableColors(final AbilityMana m, final Player player) { /*public static ArrayList<String> getProduceableColors(final AbilityMana m, final Player player) {
final ArrayList<String> colors = new ArrayList<String>(); final ArrayList<String> colors = new ArrayList<String>();
// if the mana ability is not avaiable move to the next one // if the mana ability is not avaiable move to the next one
@@ -949,7 +949,7 @@ public class ComputerUtil {
} }
return colors; return colors;
} }*/
/** /**
* <p> * <p>
@@ -1094,7 +1094,7 @@ public class ComputerUtil {
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
* @since 1.0.15 * @since 1.0.15
*/ */
public static ArrayList<AbilityMana> sortForNeeded(final ManaCost cost, final ArrayList<AbilityMana> manaAbilities, /*public static ArrayList<AbilityMana> sortForNeeded(final ManaCost cost, final ArrayList<AbilityMana> manaAbilities,
final Player player) { final Player player) {
ArrayList<String> colors; ArrayList<String> colors;
@@ -1145,7 +1145,7 @@ public class ComputerUtil {
} }
return res; return res;
} }*/
/** /**
* <p> * <p>
@@ -1189,19 +1189,19 @@ public class ComputerUtil {
colorlessSources.add(m); colorlessSources.add(m);
// find possible colors // find possible colors
if (m.canProduce("W") || m.isAnyMana()) { if (m.canProduce("W")) {
whiteSources.add(m); whiteSources.add(m);
} }
if (m.canProduce("U") || m.isAnyMana()) { if (m.canProduce("U")) {
blueSources.add(m); blueSources.add(m);
} }
if (m.canProduce("B") || m.isAnyMana()) { if (m.canProduce("B")) {
blackSources.add(m); blackSources.add(m);
} }
if (m.canProduce("R") || m.isAnyMana()) { if (m.canProduce("R")) {
redSources.add(m); redSources.add(m);
} }
if (m.canProduce("G") || m.isAnyMana()) { if (m.canProduce("G")) {
greenSources.add(m); greenSources.add(m);
} }
if (m.isSnow()) { if (m.isSnow()) {

View File

@@ -670,6 +670,9 @@ public final class AbilityFactoryChoose {
if (logic.equals("MostProminentInHumanDeck")) { if (logic.equals("MostProminentInHumanDeck")) {
chosen = CardFactoryUtil.getMostProminentColor(AllZoneUtil.getCardsInGame().getController( chosen = CardFactoryUtil.getMostProminentColor(AllZoneUtil.getCardsInGame().getController(
AllZone.getHumanPlayer())); AllZone.getHumanPlayer()));
} else if (logic.equals("MostProminentInComputerDeck")) {
chosen = CardFactoryUtil.getMostProminentColor(AllZoneUtil.getCardsInGame().getController(
AllZone.getComputerPlayer()));
} }
else if (logic.equals("MostProminentInGame")) { else if (logic.equals("MostProminentInGame")) {
chosen = CardFactoryUtil.getMostProminentColor(AllZoneUtil.getCardsInGame()); chosen = CardFactoryUtil.getMostProminentColor(AllZoneUtil.getCardsInGame());

View File

@@ -391,7 +391,6 @@ public class AbilityFactoryMana {
private static String generatedMana(final AbilityMana abMana, final AbilityFactory af, final SpellAbility sa) { private static String generatedMana(final AbilityMana abMana, final AbilityFactory af, final SpellAbility sa) {
// Calculate generated mana here for stack description and resolving // Calculate generated mana here for stack description and resolving
final HashMap<String, String> params = af.getMapParams(); final HashMap<String, String> params = af.getMapParams();
final Card card = sa.getSourceCard();
int amount = params.containsKey("Amount") ? AbilityFactory.calculateAmount(af.getHostCard(), int amount = params.containsKey("Amount") ? AbilityFactory.calculateAmount(af.getHostCard(),
params.get("Amount"), sa) : 1; params.get("Amount"), sa) : 1;
@@ -405,11 +404,6 @@ public class AbilityFactoryMana {
baseMana = abMana.mana(); baseMana = abMana.mana();
} }
if (baseMana.equals("Chosen")) {
// this will only support 1 chosen color for now.
baseMana = InputPayManaCostUtil.getShortColorString(card.getChosenColor().get(0));
}
if (params.containsKey("Bonus")) { if (params.containsKey("Bonus")) {
// For mana abilities that get a bonus // For mana abilities that get a bonus
// Bonus currently MULTIPLIES the base amount. Base Amounts should // Bonus currently MULTIPLIES the base amount. Base Amounts should
@@ -769,7 +763,7 @@ public class AbilityFactoryMana {
final ArrayList<String> colors) { final ArrayList<String> colors) {
for (final String col : Constant.Color.ONLY_COLORS) { for (final String col : Constant.Color.ONLY_COLORS) {
final String s = InputPayManaCostUtil.getShortColorString(col); final String s = InputPayManaCostUtil.getShortColorString(col);
if ((ab.canProduce(s) || ab.isAnyMana()) && !colors.contains(col)) { if (ab.canProduce(s) && !colors.contains(col)) {
colors.add(col); colors.add(col);
} }
} }

View File

@@ -25,6 +25,7 @@ import forge.Card;
import forge.Player; import forge.Player;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.mana.ManaPool; import forge.card.mana.ManaPool;
import forge.control.input.InputPayManaCostUtil;
/** /**
* <p> * <p>
@@ -228,7 +229,7 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
if (i != 0) { if (i != 0) {
sb.append(" "); sb.append(" ");
} }
sb.append(this.origProduced); sb.append(mana());
} }
} }
} }
@@ -243,6 +244,12 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public final String mana() { public final String mana() {
if (this.origProduced.contains("Chosen")) {
if (this.getSourceCard() != null && !this.getSourceCard().getChosenColor().isEmpty()) {
return InputPayManaCostUtil.getShortColorString(this.getSourceCard()
.getChosenColor().get(0));
}
}
return this.origProduced; return this.origProduced;
} }
@@ -367,7 +374,17 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
* @return a boolean. * @return a boolean.
*/ */
public final boolean canProduce(final String s) { public final boolean canProduce(final String s) {
//TODO: look at where this called from and take "Any" into account if (isAnyMana()) {
return true;
}
if (this.origProduced.contains("Chosen")) {
if (this.getSourceCard() != null && !this.getSourceCard().getChosenColor().isEmpty()
&& InputPayManaCostUtil.getShortColorString(this.getSourceCard().getChosenColor().get(0))
.contains(s)) {
return true;
}
}
return this.origProduced.contains(s); return this.origProduced.contains(s);
} }
@@ -379,7 +396,8 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
* @return a boolean. * @return a boolean.
*/ */
public final boolean isBasic() { public final boolean isBasic() {
if (this.origProduced.length() != 1 && !this.origProduced.contains("Any")) { if (this.origProduced.length() != 1 && !this.origProduced.contains("Any")
&& !this.origProduced.contains("Chosen")) {
return false; return false;
} }

View File

@@ -230,8 +230,7 @@ public class BoosterDraftAI {
final ArrayList<AbilityMana> maList = typeList.get(i).getManaAbility(); final ArrayList<AbilityMana> maList = typeList.get(i).getManaAbility();
for (int j = 0; j < maList.size(); j++) { for (int j = 0; j < maList.size(); j++) {
if (maList.get(j).canProduce(this.playerColors.get(player).getMana1()) if (maList.get(j).canProduce(this.playerColors.get(player).getMana1())
|| maList.get(j).canProduce(this.playerColors.get(player).getMana2()) || maList.get(j).canProduce(this.playerColors.get(player).getMana2())) {
|| maList.get(j).isAnyMana()) {
wouldPick.add(typeList.get(i)); wouldPick.add(typeList.get(i));
} }
} }

View File

@@ -325,8 +325,7 @@ public class SealedDeck {
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
final ArrayList<AbilityMana> maList = c.getManaAbility(); final ArrayList<AbilityMana> maList = c.getManaAbility();
for (int j = 0; j < maList.size(); j++) { for (int j = 0; j < maList.size(); j++) {
if (maList.get(j).canProduce(aiDC.mana1) || maList.get(j).canProduce(aiDC.mana2) if (maList.get(j).canProduce(aiDC.mana1) || maList.get(j).canProduce(aiDC.mana2)) {
|| maList.get(j).isAnyMana()) {
return true; return true;
} }
} }