Fix simulation AI logic related to playing lands.

This got broken by the following refactor:
79c9c914e2

The result was that simulation AI was ignoring certain decision trees that involved
playing lands, leading to not considering certain lines of play and some log
messages printed to standard error. I've added a test that covers this logic to prevent
it breaking again in the future.

Also, a couple small clean ups to related tests.
This commit is contained in:
asvitkine
2022-11-02 10:26:37 -04:00
parent c6e4eaa19c
commit b0120eedf0
4 changed files with 42 additions and 20 deletions

View File

@@ -2242,8 +2242,8 @@ public class GameSimulationTest extends SimulationTest {
simGame.getPhaseHandler().devAdvanceToPhase(PhaseType.MAIN2);
AssertJUnit.assertEquals(21, simGame.getPlayers().get(0).getLife());
AssertJUnit.assertEquals(true, simGoblin.isRed() && simGoblin.isBlack());
AssertJUnit.assertEquals(true, simGoblin.getType().hasSubtype("Zombie"));
AssertJUnit.assertTrue(simGoblin.isRed() && simGoblin.isBlack());
AssertJUnit.assertTrue(simGoblin.getType().hasSubtype("Zombie"));
}
@Test

View File

@@ -1,5 +1,6 @@
package forge.ai.simulation;
import forge.game.spellability.LandAbility;
import java.util.List;
import org.testng.AssertJUnit;
@@ -79,16 +80,44 @@ public class SpellAbilityPickerSimulationTest extends SimulationTest {
SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
// assertEquals(game.PLAY_LAND_SURROGATE, sa);
AssertJUnit.assertTrue(sa instanceof LandAbility);
AssertJUnit.assertEquals(mountain, sa.getHostCard());
Plan plan = picker.getPlan();
AssertJUnit.assertEquals(2, plan.getDecisions().size());
AssertJUnit.assertEquals("Play land Mountain", plan.getDecisions().get(0).saRef.toString());
AssertJUnit.assertEquals("Mountain (1) -> Play land", plan.getDecisions().get(0).saRef.toString(true));
AssertJUnit.assertEquals("Shock deals 2 damage to any target.", plan.getDecisions().get(1).saRef.toString());
AssertJUnit.assertTrue(plan.getDecisions().get(1).targets.toString().contains("Runeclaw Bear"));
}
@Test
public void testPlayingLandAfterSpell() {
Game game = initAndCreateGame();
Player p = game.getPlayers().get(1);
addCard("Island", p);
addCard("Island", p);
addCard("Forest", p);
addCard("Forest", p);
addCard("Forest", p);
Card tatyova = addCardToZone("Tatyova, Benthic Druid", p, ZoneType.Hand);
addCardToZone("Forest", p, ZoneType.Hand);
addCardToZone("Forest", p, ZoneType.Library);
game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p);
game.getAction().checkStateEffects(true);
SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertEquals(tatyova, sa.getHostCard());
Plan plan = picker.getPlan();
AssertJUnit.assertEquals(2, plan.getDecisions().size());
AssertJUnit.assertEquals("Tatyova, Benthic Druid - Creature 3 / 3", plan.getDecisions().get(0).saRef.toString());
AssertJUnit.assertEquals("Play land", plan.getDecisions().get(1).saRef.toString());
}
@Test
public void testModeSelection() {
Game game = initAndCreateGame();
@@ -279,7 +308,8 @@ public class SpellAbilityPickerSimulationTest extends SimulationTest {
AssertJUnit.assertEquals(abbot.getSpellAbilities().get(0), sa);
Plan plan = picker.getPlan();
AssertJUnit.assertEquals(3, plan.getDecisions().size());
AssertJUnit.assertEquals("Play land Mountain", plan.getDecisions().get(1).saRef.toString());
AssertJUnit.assertEquals("Mountain (5) -> Play land by Abbot of Keral Keep (3)",
plan.getDecisions().get(1).saRef.toString(true));
AssertJUnit.assertEquals("Lightning Bolt deals 3 damage to any target.",
plan.getDecisions().get(2).saRef.toString());
}