Fix shard sort order when deciding if a mana cost is payable.

Prior to this change, the logic would conclude that a {1}{W} cost is not payable with an untapped Scoured Barrens (w/b) and Jungle Hollow (b/g) on the field.

The code is unfortunately too tangled (has too many dependencies) to write a unit test for this. Ideally, we should refactor so it wouldn't depend on the player, etc and just take parameters that can be fed test data.
This commit is contained in:
Myrd
2014-12-16 20:26:41 +00:00
parent 8c25bfd8b7
commit 6be85a1741
2 changed files with 9 additions and 7 deletions

View File

@@ -697,11 +697,7 @@ public class ComputerUtilMana {
// * pay hybrids
// * pay phyrexian, keep mana for colorless
// * pay colorless
Iterator<ManaCostShard> shards = cost.getDistinctShards().iterator();
if (shards.hasNext()) {
return shards.next();
}
return null;
return cost.getShardToPayByPriority(cost.getDistinctShards(), MagicColor.ALL_COLORS);
}
private static void adjustManaCostToAvoidNegEffects(ManaCostBeingPaid cost, final Card card, Player ai) {

View File

@@ -360,7 +360,7 @@ public class ManaCostBeingPaid {
return tryPayMana(color, Iterables.filter(unpaidShards.keySet(), predCanBePaid), (byte)0xFF);
}
private ManaCostShard tryPayMana(final byte colorMask, Iterable<ManaCostShard> payableShards, byte possibleUses) {
public ManaCostShard getShardToPayByPriority(Iterable<ManaCostShard> payableShards, byte possibleUses) {
Set<ManaCostShard> choice = EnumSet.noneOf(ManaCostShard.class);
int priority = Integer.MIN_VALUE;
for (ManaCostShard toPay : payableShards) {
@@ -378,8 +378,14 @@ public class ManaCostBeingPaid {
return null;
}
ManaCostShard chosenShard = Iterables.getFirst(choice, null);
return Iterables.getFirst(choice, null);
}
private ManaCostShard tryPayMana(final byte colorMask, Iterable<ManaCostShard> payableShards, byte possibleUses) {
ManaCostShard chosenShard = getShardToPayByPriority(payableShards, possibleUses);
if (chosenShard == null) {
return null;
}
ShardCount sc = unpaidShards.get(chosenShard);
if (sc != null && sc.xCount > 0) {
//if there's any X part of the cost for the chosen shard, pay it off first and track what color was spent to pay X