diff --git a/forge-ai/src/main/java/forge/ai/simulation/GameStateEvaluator.java b/forge-ai/src/main/java/forge/ai/simulation/GameStateEvaluator.java index 03f6f4bd1dc..e95f45365ca 100644 --- a/forge-ai/src/main/java/forge/ai/simulation/GameStateEvaluator.java +++ b/forge-ai/src/main/java/forge/ai/simulation/GameStateEvaluator.java @@ -6,8 +6,11 @@ import forge.game.card.Card; import forge.game.card.CounterEnumType; import forge.game.phase.PhaseType; import forge.game.player.Player; +import forge.game.spellability.SpellAbility; import forge.game.zone.ZoneType; +import static java.lang.Math.max; + public class GameStateEvaluator { private boolean debugging = false; private SimulationCreatureEvaluator eval = new SimulationCreatureEvaluator(); @@ -153,7 +156,16 @@ public class GameStateEvaluator { if (c.isCreature()) { return eval.evaluateCreature(c); } else if (c.isLand()) { - return 100; + int value = 100; + // for each mana color a land generates for free, increase the value by one + // for each mana a land can produce, add one hundred. + int max_produced = 0; + int possible_colors = 0; + for (SpellAbility m: c.getManaAbilities()) { + max_produced = max(max_produced, m.amountOfManaGenerated(false)); + } + value = 100 * max_produced; + return value; } else if (c.isEnchantingCard()) { // TODO: Should provide value in whatever it's enchanting? // Else the computer would think that casting a Lifelink enchantment diff --git a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java index 4b750cc6f24..2a79c5ae4c4 100644 --- a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java +++ b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java @@ -1657,7 +1657,16 @@ public class AbilityUtils { final String s2 = applyAbilityTextChangeEffects(s, ctb); final String[] l = s2.split("/"); final String expr = CardFactoryUtil.extractOperators(s2); - final Player player = ctb == null ? null : ctb instanceof SpellAbility ? ((SpellAbility)ctb).getActivatingPlayer() : ctb.getHostCard().getController(); + + Player player = null; + if (ctb != null) { + if (ctb instanceof SpellAbility) { + player = ((SpellAbility)ctb).getActivatingPlayer(); + } + if (player == null) { + player = ctb.getHostCard().getController(); + } + } // accept straight numbers if (l[0].startsWith("Number$")) { diff --git a/forge-gui-desktop/src/test/java/forge/ai/simulation/SpellAbilityPickerSimulationTest.java b/forge-gui-desktop/src/test/java/forge/ai/simulation/SpellAbilityPickerSimulationTest.java index 6a1f4490250..a40923c3581 100644 --- a/forge-gui-desktop/src/test/java/forge/ai/simulation/SpellAbilityPickerSimulationTest.java +++ b/forge-gui-desktop/src/test/java/forge/ai/simulation/SpellAbilityPickerSimulationTest.java @@ -279,6 +279,7 @@ public class SpellAbilityPickerSimulationTest extends SimulationTest { Game game = initAndCreateGame(); Player p = game.getPlayers().get(1); + // start with a hand with a basic, a tapland, and a card that can't be cast addCard("Forest", p); addCardToZone("Forest", p, ZoneType.Hand); Card guildgate = addCardToZone("Simic Guildgate", p, ZoneType.Hand); @@ -286,11 +287,33 @@ public class SpellAbilityPickerSimulationTest extends SimulationTest { game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p); game.getAction().checkStateEffects(true); + // ensure that the tapland is paid SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbility sa = picker.chooseSpellAbilityToPlay(null); AssertJUnit.assertEquals(guildgate, sa.getHostCard()); } + @Test + public void playTronOverBasic() { + Game game = initAndCreateGame(); + Player p = game.getPlayers().get(1); + + // start with a hand with a basic, a Tron land, and a card that can't be cast + addCard("Urza's Tower", p); + addCard("Urza's Mine", p); + addCardToZone("Forest", p, ZoneType.Hand); + Card desired = addCardToZone("Urza's Power Plant", p, ZoneType.Hand); + addCardToZone("Opt", p, ZoneType.Hand); + game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p); + game.getAction().checkStateEffects(true); + AssertJUnit.assertEquals(p, desired.getController()); + + // ensure that the tapland is paid + SpellAbilityPicker picker = new SpellAbilityPicker(game, p); + SpellAbility sa = picker.chooseSpellAbilityToPlay(null); + AssertJUnit.assertEquals(desired, sa.getHostCard()); + } + @Test public void testPlayRememberedCardsLand() { Game game = initAndCreateGame();