- Implemented AI for more Converge cards

This commit is contained in:
excessum
2015-10-11 09:31:41 +00:00
parent 94b6f67815
commit 71e417dd8a
7 changed files with 37 additions and 7 deletions

View File

@@ -667,10 +667,26 @@ public class AiController {
if (mana.countX() > 0) {
// Set PayX here to maximum value.
final int xPay = ComputerUtilMana.determineLeftoverMana(sa, player);
if (xPay <= 0) {
return AiPlayDecision.CantAffordX;
final Card source = sa.getHostCard();
if (source.hasConverge()) {
card.setSVar("PayX", Integer.toString(0));
int nColors = ComputerUtilMana.getConvergeCount(sa, player);
for (int i = 1; i <= xPay; i++) {
card.setSVar("PayX", Integer.toString(i));
int newColors = ComputerUtilMana.getConvergeCount(sa, player);
if (newColors > nColors) {
nColors = newColors;
} else {
card.setSVar("PayX", Integer.toString(i - 1));
break;
}
}
} else {
if (xPay <= 0) {
return AiPlayDecision.CantAffordX;
}
card.setSVar("PayX", Integer.toString(xPay));
}
card.setSVar("PayX", Integer.toString(xPay));
}
// Check for valid targets before casting

View File

@@ -58,6 +58,18 @@ public class ComputerUtilMana {
public static boolean canPayManaCost(final SpellAbility sa, final Player ai, final int extraMana) {
return payManaCost(sa, ai, true, extraMana, true);
}
/**
* Return the number of colors used for payment for Converge
*/
public static int getConvergeCount(final SpellAbility sa, final Player ai) {
ManaCostBeingPaid cost = ComputerUtilMana.calculateManaCost(sa, true, 0);
if (payManaCost(cost, sa, ai, true, true)) {
return cost.getSunburst();
} else {
return 0;
}
}
// Does not check if mana sources can be used right now, just checks for potential chance.
public static boolean hasEnoughManaSourcesToCast(final SpellAbility sa, final Player ai) {

View File

@@ -29,7 +29,9 @@ public class DamageAllAi extends SpellAbilityAi {
final String damage = sa.getParam("NumDmg");
int dmg = AbilityUtils.calculateAmount(sa.getHostCard(), damage, sa);
if (damage.equals("X") && sa.getSVar(damage).equals("Count$Converge")) {
dmg = ComputerUtilMana.getConvergeCount(sa, ai);
}
if (damage.equals("X") && sa.getSVar(damage).equals("Count$xPaid")) {
// Set PayX here to maximum value.
dmg = ComputerUtilMana.determineLeftoverMana(sa, ai);

View File

@@ -235,6 +235,9 @@ public class TokenAi extends SpellAbilityAi {
if (this.tokenAmount.equals("X") || this.tokenPower.equals("X") || this.tokenToughness.equals("X")) {
int x = AbilityUtils.calculateAmount(sa.getHostCard(), this.tokenAmount, sa);
if (source.getSVar("X").equals("Count$Converge")) {
x = ComputerUtilMana.getConvergeCount(sa, ai);
}
if (source.getSVar("X").equals("Count$xPaid")) {
// Set PayX here to maximum value.
x = ComputerUtilMana.determineLeftoverMana(sa, ai);