forge-gui-desktop: tests: refactor (format)

Affected namespace:
forge.ai.simulation
This commit is contained in:
Leandro Doctors
2022-04-17 03:18:38 -03:00
parent efa45f8889
commit 1a57bee27f
3 changed files with 2207 additions and 2184 deletions

View File

@@ -31,111 +31,111 @@ import forge.localinstance.properties.ForgePreferences.FPref;
import forge.model.FModel; import forge.model.FModel;
public class SimulationTest { public class SimulationTest {
private static boolean initialized = false; private static boolean initialized = false;
protected Game initAndCreateGame() { protected Game initAndCreateGame() {
if (!initialized) { if (!initialized) {
GuiBase.setInterface(new GuiDesktop()); GuiBase.setInterface(new GuiDesktop());
FModel.initialize(null, new Function<ForgePreferences, Void>() { FModel.initialize(null, new Function<ForgePreferences, Void>() {
@Override @Override
public Void apply(ForgePreferences preferences) { public Void apply(ForgePreferences preferences) {
preferences.setPref(FPref.LOAD_CARD_SCRIPTS_LAZILY, false); preferences.setPref(FPref.LOAD_CARD_SCRIPTS_LAZILY, false);
preferences.setPref(FPref.UI_LANGUAGE, "en-US"); preferences.setPref(FPref.UI_LANGUAGE, "en-US");
return null; return null;
} }
}); });
initialized = true; initialized = true;
} }
// need to be done after FModel.initialize, or the Localizer isn't loaded yet // need to be done after FModel.initialize, or the Localizer isn't loaded yet
List<RegisteredPlayer> players = Lists.newArrayList(); List<RegisteredPlayer> players = Lists.newArrayList();
Deck d1 = new Deck(); Deck d1 = new Deck();
players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p2", null))); players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p2", null)));
Set<AIOption> options = new HashSet<>(); Set<AIOption> options = new HashSet<>();
options.add(AIOption.USE_SIMULATION); options.add(AIOption.USE_SIMULATION);
players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p1", options))); players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p1", options)));
GameRules rules = new GameRules(GameType.Constructed); GameRules rules = new GameRules(GameType.Constructed);
Match match = new Match(rules, players, "Test"); Match match = new Match(rules, players, "Test");
Game game = new Game(players, rules, match); Game game = new Game(players, rules, match);
game.setAge(GameStage.Play); game.setAge(GameStage.Play);
return game; return game;
} }
protected GameSimulator createSimulator(Game game, Player p) { protected GameSimulator createSimulator(Game game, Player p) {
return new GameSimulator(new SimulationController(new Score(0)) { return new GameSimulator(new SimulationController(new Score(0)) {
@Override @Override
public boolean shouldRecurse() { public boolean shouldRecurse() {
return false; return false;
} }
}, game, p, null); }, game, p, null);
} }
protected int countCardsWithName(Game game, String name) { protected int countCardsWithName(Game game, String name) {
int i = 0; int i = 0;
for (Card c : game.getCardsIn(ZoneType.Battlefield)) { for (Card c : game.getCardsIn(ZoneType.Battlefield)) {
if (c.getName().equals(name)) { if (c.getName().equals(name)) {
i++; i++;
} }
} }
return i; return i;
} }
protected Card findCardWithName(Game game, String name) { protected Card findCardWithName(Game game, String name) {
for (Card c : game.getCardsIn(ZoneType.Battlefield)) { for (Card c : game.getCardsIn(ZoneType.Battlefield)) {
if (c.getName().equals(name)) { if (c.getName().equals(name)) {
return c; return c;
} }
} }
return null; return null;
} }
protected String gameStateToString(Game game) {
StringBuilder sb = new StringBuilder();
for (ZoneType zone : ZoneType.values()) {
CardCollectionView cards = game.getCardsIn(zone);
if (!cards.isEmpty()) {
sb.append("Zone ").append(zone.name()).append(":\n");
for (Card c : game.getCardsIn(zone)) {
sb.append(" ").append(c).append("\n");
}
}
}
return sb.toString();
}
protected SpellAbility findSAWithPrefix(Card c, String prefix) { protected String gameStateToString(Game game) {
return findSAWithPrefix(c.getSpellAbilities(), prefix); StringBuilder sb = new StringBuilder();
} for (ZoneType zone : ZoneType.values()) {
CardCollectionView cards = game.getCardsIn(zone);
protected SpellAbility findSAWithPrefix(Iterable<SpellAbility> abilities, String prefix) { if (!cards.isEmpty()) {
for (SpellAbility sa : abilities) { sb.append("Zone ").append(zone.name()).append(":\n");
if (sa.getDescription().startsWith(prefix)) { for (Card c : game.getCardsIn(zone)) {
return sa; sb.append(" ").append(c).append("\n");
} }
} }
return null; }
} return sb.toString();
}
protected Card createCard(String name, Player p) { protected SpellAbility findSAWithPrefix(Card c, String prefix) {
IPaperCard paperCard = FModel.getMagicDb().getCommonCards().getCard(name); return findSAWithPrefix(c.getSpellAbilities(), prefix);
if (paperCard == null) { }
StaticData.instance().attemptToLoadCard(name);
paperCard = FModel.getMagicDb().getCommonCards().getCard(name);
}
return Card.fromPaperCard(paperCard, p);
}
protected Card addCardToZone(String name, Player p, ZoneType zone) { protected SpellAbility findSAWithPrefix(Iterable<SpellAbility> abilities, String prefix) {
Card c = createCard(name, p); for (SpellAbility sa : abilities) {
// card need a new Timestamp otherwise Static Abilities might collide if (sa.getDescription().startsWith(prefix)) {
c.setTimestamp(p.getGame().getNextTimestamp()); return sa;
p.getZone(zone).add(c); }
return c; }
} return null;
}
protected Card addCard(String name, Player p) { protected Card createCard(String name, Player p) {
return addCardToZone(name, p, ZoneType.Battlefield); IPaperCard paperCard = FModel.getMagicDb().getCommonCards().getCard(name);
} if (paperCard == null) {
StaticData.instance().attemptToLoadCard(name);
paperCard = FModel.getMagicDb().getCommonCards().getCard(name);
}
return Card.fromPaperCard(paperCard, p);
}
protected Card addCardToZone(String name, Player p, ZoneType zone) {
Card c = createCard(name, p);
// card need a new Timestamp otherwise Static Abilities might collide
c.setTimestamp(p.getGame().getNextTimestamp());
p.getZone(zone).add(c);
return c;
}
protected Card addCard(String name, Player p) {
return addCardToZone(name, p, ZoneType.Battlefield);
}
} }

View File

@@ -15,394 +15,396 @@ import forge.game.spellability.SpellAbility;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
public class SpellAbilityPickerSimulationTest extends SimulationTest { public class SpellAbilityPickerSimulationTest extends SimulationTest {
@Test @Test
public void testPickingLethalDamage() { public void testPickingLethalDamage() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
p.setTeam(0); p.setTeam(0);
addCard("Mountain", p);
addCardToZone("Shock", p, ZoneType.Hand);
Player opponent = game.getPlayers().get(0); addCard("Mountain", p);
opponent.setTeam(1); addCardToZone("Shock", p, ZoneType.Hand);
addCard("Runeclaw Bear", opponent);
opponent.setLife(2, null);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p); Player opponent = game.getPlayers().get(0);
game.getAction().checkStateEffects(true); opponent.setTeam(1);
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); addCard("Runeclaw Bear", opponent);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); opponent.setLife(2, null);
AssertJUnit.assertNotNull(sa);
AssertJUnit.assertNull(sa.getTargetCard());
AssertJUnit.assertEquals(opponent, sa.getTargets().getFirstTargetedPlayer());
}
@Test game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true);
SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertNotNull(sa);
AssertJUnit.assertNull(sa.getTargetCard());
AssertJUnit.assertEquals(opponent, sa.getTargets().getFirstTargetedPlayer());
}
@Test
public void testPickingKillingCreature() { public void testPickingKillingCreature() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
addCard("Mountain", p); addCard("Mountain", p);
addCardToZone("Shock", p, ZoneType.Hand); addCardToZone("Shock", p, ZoneType.Hand);
Player opponent = game.getPlayers().get(0); Player opponent = game.getPlayers().get(0);
Card bearCard = addCard("Runeclaw Bear", opponent); Card bearCard = addCard("Runeclaw Bear", opponent);
opponent.setLife(20, null); opponent.setLife(20, null);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertNotNull(sa); AssertJUnit.assertNotNull(sa);
AssertJUnit.assertEquals(bearCard, sa.getTargetCard()); AssertJUnit.assertEquals(bearCard, sa.getTargetCard());
AssertJUnit.assertNull(sa.getTargets().getFirstTargetedPlayer()); AssertJUnit.assertNull(sa.getTargets().getFirstTargetedPlayer());
} }
@Test @Test
public void testSequenceStartingWithPlayingLand() { public void testSequenceStartingWithPlayingLand() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
Card mountain = addCardToZone("Mountain", p, ZoneType.Hand); Card mountain = addCardToZone("Mountain", p, ZoneType.Hand);
addCardToZone("Shock", p, ZoneType.Hand); addCardToZone("Shock", p, ZoneType.Hand);
Player opponent = game.getPlayers().get(0); Player opponent = game.getPlayers().get(0);
addCard("Runeclaw Bear", opponent); addCard("Runeclaw Bear", opponent);
opponent.setLife(20, null); opponent.setLife(20, null);
game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
//assertEquals(game.PLAY_LAND_SURROGATE, sa); // assertEquals(game.PLAY_LAND_SURROGATE, sa);
AssertJUnit.assertEquals(mountain, sa.getHostCard()); AssertJUnit.assertEquals(mountain, sa.getHostCard());
Plan plan = picker.getPlan(); Plan plan = picker.getPlan();
AssertJUnit.assertEquals(2, plan.getDecisions().size()); AssertJUnit.assertEquals(2, plan.getDecisions().size());
AssertJUnit.assertEquals("Play land Mountain", plan.getDecisions().get(0).saRef.toString()); AssertJUnit.assertEquals("Play land Mountain", plan.getDecisions().get(0).saRef.toString());
AssertJUnit.assertEquals("Shock deals 2 damage to any target.", plan.getDecisions().get(1).saRef.toString()); 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")); AssertJUnit.assertTrue(plan.getDecisions().get(1).targets.toString().contains("Runeclaw Bear"));
} }
@Test @Test
public void testModeSelection() { public void testModeSelection() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
addCard("Plains", p); addCard("Plains", p);
addCard("Island", p); addCard("Island", p);
addCard("Swamp", p); addCard("Swamp", p);
Card spell = addCardToZone("Dromar's Charm", p, ZoneType.Hand); Card spell = addCardToZone("Dromar's Charm", p, ZoneType.Hand);
Player opponent = game.getPlayers().get(0); Player opponent = game.getPlayers().get(0);
addCard("Runeclaw Bear", opponent); addCard("Runeclaw Bear", opponent);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
// Expected: All creatures get -2/-2 to kill the bear. // Expected: All creatures get -2/-2 to kill the bear.
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertEquals(spell.getSpellAbilities().get(0), sa); AssertJUnit.assertEquals(spell.getSpellAbilities().get(0), sa);
AssertJUnit.assertEquals("Dromar's Charm -> Target creature gets -2/-2 until end of turn.", picker.getPlan().getDecisions().get(0).modesStr); AssertJUnit.assertEquals("Dromar's Charm -> Target creature gets -2/-2 until end of turn.",
} picker.getPlan().getDecisions().get(0).modesStr);
}
@Test @Test
public void testModeSelection2() { public void testModeSelection2() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
addCard("Plains", p); addCard("Plains", p);
addCard("Island", p); addCard("Island", p);
addCard("Swamp", p); addCard("Swamp", p);
Card spell = addCardToZone("Dromar's Charm", p, ZoneType.Hand); Card spell = addCardToZone("Dromar's Charm", p, ZoneType.Hand);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
// Expected: Gain 5 life, since other modes aren't helpful. // Expected: Gain 5 life, since other modes aren't helpful.
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertEquals(spell.getSpellAbilities().get(0), sa); AssertJUnit.assertEquals(spell.getSpellAbilities().get(0), sa);
AssertJUnit.assertEquals("Dromar's Charm -> You gain 5 life.", picker.getPlan().getDecisions().get(0).modesStr); AssertJUnit.assertEquals("Dromar's Charm -> You gain 5 life.", picker.getPlan().getDecisions().get(0).modesStr);
} }
@Test @Test
public void testMultipleModes() { public void testMultipleModes() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
addCard("Mountain", p); addCard("Mountain", p);
addCard("Mountain", p); addCard("Mountain", p);
addCard("Mountain", p); addCard("Mountain", p);
addCard("Mountain", p); addCard("Mountain", p);
Card spell = addCardToZone("Fiery Confluence", p, ZoneType.Hand); Card spell = addCardToZone("Fiery Confluence", p, ZoneType.Hand);
Player opponent = game.getPlayers().get(0); Player opponent = game.getPlayers().get(0);
addCard("Runeclaw Bear", opponent); addCard("Runeclaw Bear", opponent);
opponent.setLife(20, null); opponent.setLife(20, null);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
// Expected: 2x 1 damage to each creature, 1x 2 damage to each opponent. // Expected: 2x 1 damage to each creature, 1x 2 damage to each opponent.
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertEquals(spell.getSpellAbilities().get(0), sa); AssertJUnit.assertEquals(spell.getSpellAbilities().get(0), sa);
String dmgCreaturesStr = "Fiery Confluence deals 1 damage to each creature."; String dmgCreaturesStr = "Fiery Confluence deals 1 damage to each creature.";
String dmgOppStr = "Fiery Confluence deals 2 damage to each opponent."; String dmgOppStr = "Fiery Confluence deals 2 damage to each opponent.";
String expected = "Fiery Confluence -> " + dmgCreaturesStr + " " + dmgCreaturesStr + " " + dmgOppStr; String expected = "Fiery Confluence -> " + dmgCreaturesStr + " " + dmgCreaturesStr + " " + dmgOppStr;
AssertJUnit.assertEquals(expected, picker.getPlan().getDecisions().get(0).modesStr); AssertJUnit.assertEquals(expected, picker.getPlan().getDecisions().get(0).modesStr);
} }
@Test @Test
public void testMultipleModes2() { public void testMultipleModes2() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
addCard("Mountain", p); addCard("Mountain", p);
addCard("Mountain", p); addCard("Mountain", p);
addCard("Mountain", p); addCard("Mountain", p);
addCard("Mountain", p); addCard("Mountain", p);
Card spell = addCardToZone("Fiery Confluence", p, ZoneType.Hand); Card spell = addCardToZone("Fiery Confluence", p, ZoneType.Hand);
Player opponent = game.getPlayers().get(0); Player opponent = game.getPlayers().get(0);
addCard("Runeclaw Bear", opponent); addCard("Runeclaw Bear", opponent);
opponent.setLife(6, null); opponent.setLife(6, null);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
// Expected: 3x 2 damage to each opponent. // Expected: 3x 2 damage to each opponent.
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertEquals(spell.getSpellAbilities().get(0), sa); AssertJUnit.assertEquals(spell.getSpellAbilities().get(0), sa);
String dmgOppStr = "Fiery Confluence deals 2 damage to each opponent."; String dmgOppStr = "Fiery Confluence deals 2 damage to each opponent.";
String expected = "Fiery Confluence -> " + dmgOppStr + " " + dmgOppStr + " " + dmgOppStr; String expected = "Fiery Confluence -> " + dmgOppStr + " " + dmgOppStr + " " + dmgOppStr;
AssertJUnit.assertEquals(expected, picker.getPlan().getDecisions().get(0).modesStr); AssertJUnit.assertEquals(expected, picker.getPlan().getDecisions().get(0).modesStr);
} }
@Test @Test
public void testMultipleTargets() { public void testMultipleTargets() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
addCard("Mountain", p); addCard("Mountain", p);
addCard("Mountain", p); addCard("Mountain", p);
Card spell = addCardToZone("Arc Trail", p, ZoneType.Hand); Card spell = addCardToZone("Arc Trail", p, ZoneType.Hand);
Player opponent = game.getPlayers().get(0); Player opponent = game.getPlayers().get(0);
Card bear = addCard("Runeclaw Bear", opponent); Card bear = addCard("Runeclaw Bear", opponent);
Card men = addCard("Flying Men", opponent); Card men = addCard("Flying Men", opponent);
opponent.setLife(20, null); opponent.setLife(20, null);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertEquals(spell.getSpellAbilities().get(0), sa); AssertJUnit.assertEquals(spell.getSpellAbilities().get(0), sa);
AssertJUnit.assertEquals(bear, sa.getTargetCard()); AssertJUnit.assertEquals(bear, sa.getTargetCard());
AssertJUnit.assertEquals("2", sa.getParam("NumDmg")); AssertJUnit.assertEquals("2", sa.getParam("NumDmg"));
SpellAbility subSa = sa.getSubAbility(); SpellAbility subSa = sa.getSubAbility();
AssertJUnit.assertEquals(men, subSa.getTargetCard()); AssertJUnit.assertEquals(men, subSa.getTargetCard());
AssertJUnit.assertEquals("1", subSa.getParam("NumDmg")); AssertJUnit.assertEquals("1", subSa.getParam("NumDmg"));
} }
@Test @Test
public void testLandSearchForCombo() { public void testLandSearchForCombo() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
addCard("Forest", p); addCard("Forest", p);
addCard("Thespian's Stage", p); addCard("Thespian's Stage", p);
Card darkDepths = addCard("Dark Depths", p); Card darkDepths = addCard("Dark Depths", p);
Card cropRotation = addCardToZone("Crop Rotation", p, ZoneType.Hand); Card cropRotation = addCardToZone("Crop Rotation", p, ZoneType.Hand);
addCardToZone("Forest", p, ZoneType.Library); addCardToZone("Forest", p, ZoneType.Library);
addCardToZone("Urborg, Tomb of Yawgmoth", p, ZoneType.Library); addCardToZone("Urborg, Tomb of Yawgmoth", p, ZoneType.Library);
addCardToZone("Swamp", p, ZoneType.Library); addCardToZone("Swamp", p, ZoneType.Library);
darkDepths.setCounters(CounterEnumType.ICE, 10); darkDepths.setCounters(CounterEnumType.ICE, 10);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
AssertJUnit.assertEquals(10, darkDepths.getCounters(CounterEnumType.ICE)); AssertJUnit.assertEquals(10, darkDepths.getCounters(CounterEnumType.ICE));
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertEquals(cropRotation.getSpellAbilities().get(0), sa); AssertJUnit.assertEquals(cropRotation.getSpellAbilities().get(0), sa);
// Expected: Sac a Forest to get an Urborg. // Expected: Sac a Forest to get an Urborg.
List<String> choices = picker.getPlan().getDecisions().get(0).choices; List<String> choices = picker.getPlan().getDecisions().get(0).choices;
AssertJUnit.assertEquals(2, choices.size()); AssertJUnit.assertEquals(2, choices.size());
AssertJUnit.assertEquals("Forest", choices.get(0)); AssertJUnit.assertEquals("Forest", choices.get(0));
AssertJUnit.assertEquals("Urborg, Tomb of Yawgmoth", choices.get(1)); AssertJUnit.assertEquals("Urborg, Tomb of Yawgmoth", choices.get(1));
// Next, expected to use Thespian's Stage to copy Dark Depths. // Next, expected to use Thespian's Stage to copy Dark Depths.
Plan.Decision d2 = picker.getPlan().getDecisions().get(1); Plan.Decision d2 = picker.getPlan().getDecisions().get(1);
String expected = "{2}, {T}: Thespian's Stage becomes a copy of target land, except it has this ability."; String expected = "{2}, {T}: Thespian's Stage becomes a copy of target land, except it has this ability.";
AssertJUnit.assertEquals(expected, d2.saRef.toString()); AssertJUnit.assertEquals(expected, d2.saRef.toString());
AssertJUnit.assertTrue(d2.targets.toString().contains("Dark Depths")); AssertJUnit.assertTrue(d2.targets.toString().contains("Dark Depths"));
} }
@Test @Test
public void testPlayRememberedCardsLand() { public void testPlayRememberedCardsLand() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
addCard("Mountain", p); addCard("Mountain", p);
addCard("Mountain", p); addCard("Mountain", p);
Card abbot = addCardToZone("Abbot of Keral Keep", p, ZoneType.Hand); Card abbot = addCardToZone("Abbot of Keral Keep", p, ZoneType.Hand);
addCardToZone("Lightning Bolt", p, ZoneType.Hand); addCardToZone("Lightning Bolt", p, ZoneType.Hand);
// Note: This assumes the top of library is revealed. If the AI is made // Note: This assumes the top of library is revealed. If the AI is made
// smarter to not assume that, then this test can be updated to have // smarter to not assume that, then this test can be updated to have
// something that reveals top of library active - e.g. Lens of Clarity. // something that reveals top of library active - e.g. Lens of Clarity.
addCardToZone("Mountain", p, ZoneType.Library); addCardToZone("Mountain", p, ZoneType.Library);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
// Expected plan: // Expected plan:
// 1. Play Abbot. // 1. Play Abbot.
// 2. Play land exiled by Abbot. // 2. Play land exiled by Abbot.
// 3. Play Bolt targeting opponent. // 3. Play Bolt targeting opponent.
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertEquals(abbot.getSpellAbilities().get(0), sa); AssertJUnit.assertEquals(abbot.getSpellAbilities().get(0), sa);
Plan plan = picker.getPlan(); Plan plan = picker.getPlan();
AssertJUnit.assertEquals(3, plan.getDecisions().size()); AssertJUnit.assertEquals(3, plan.getDecisions().size());
AssertJUnit.assertEquals("Play land Mountain", plan.getDecisions().get(1).saRef.toString()); AssertJUnit.assertEquals("Play land Mountain", plan.getDecisions().get(1).saRef.toString());
AssertJUnit.assertEquals("Lightning Bolt deals 3 damage to any target.", plan.getDecisions().get(2).saRef.toString()); AssertJUnit.assertEquals("Lightning Bolt deals 3 damage to any target.",
} plan.getDecisions().get(2).saRef.toString());
}
@Test @Test
public void testPlayRememberedCardsSpell() { public void testPlayRememberedCardsSpell() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
addCard("Mountain", p); addCard("Mountain", p);
addCard("Mountain", p); addCard("Mountain", p);
addCard("Mountain", p); addCard("Mountain", p);
Card abbot = addCardToZone("Abbot of Keral Keep", p, ZoneType.Hand); Card abbot = addCardToZone("Abbot of Keral Keep", p, ZoneType.Hand);
// Note: This assumes the top of library is revealed. If the AI is made // Note: This assumes the top of library is revealed. If the AI is made
// smarter to not assume that, then this test can be updated to have // smarter to not assume that, then this test can be updated to have
// something that reveals top of library active - e.g. Lens of Clarity. // something that reveals top of library active - e.g. Lens of Clarity.
addCardToZone("Lightning Bolt", p, ZoneType.Library); addCardToZone("Lightning Bolt", p, ZoneType.Library);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
// Expected plan: // Expected plan:
// 1. Play Abbot. // 1. Play Abbot.
// 3. Play Bolt exiled by Abbot. // 3. Play Bolt exiled by Abbot.
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertEquals(abbot.getSpellAbilities().get(0), sa); AssertJUnit.assertEquals(abbot.getSpellAbilities().get(0), sa);
Plan plan = picker.getPlan(); Plan plan = picker.getPlan();
AssertJUnit.assertEquals(2, plan.getDecisions().size()); AssertJUnit.assertEquals(2, plan.getDecisions().size());
String saDesc = plan.getDecisions().get(1).saRef.toString(); String saDesc = plan.getDecisions().get(1).saRef.toString();
AssertJUnit.assertTrue(saDesc, saDesc.startsWith("Lightning Bolt deals 3 damage to any target.")); AssertJUnit.assertTrue(saDesc, saDesc.startsWith("Lightning Bolt deals 3 damage to any target."));
} }
@Test @Test
public void testPlayingPumpSpellsAfterBlocks() { public void testPlayingPumpSpellsAfterBlocks() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
Player opponent = game.getPlayers().get(0); Player opponent = game.getPlayers().get(0);
opponent.setLife(2, null); opponent.setLife(2, null);
Card blocker = addCard("Fugitive Wizard", opponent);
Card attacker1 = addCard("Dwarven Trader", p);
attacker1.setSickness(false);
Card attacker2 = addCard("Dwarven Trader", p);
attacker2.setSickness(false);
addCard("Mountain", p);
addCardToZone("Brute Force", p, ZoneType.Hand);
game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p); Card blocker = addCard("Fugitive Wizard", opponent);
game.getAction().checkStateEffects(true); Card attacker1 = addCard("Dwarven Trader", p);
attacker1.setSickness(false);
Card attacker2 = addCard("Dwarven Trader", p);
attacker2.setSickness(false);
addCard("Mountain", p);
addCardToZone("Brute Force", p, ZoneType.Hand);
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p);
AssertJUnit.assertNull(picker.chooseSpellAbilityToPlay(null)); game.getAction().checkStateEffects(true);
game.getPhaseHandler().devAdvanceToPhase(PhaseType.COMBAT_BEGIN); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
game.getAction().checkStateEffects(true); AssertJUnit.assertNull(picker.chooseSpellAbilityToPlay(null));
AssertJUnit.assertNull(picker.chooseSpellAbilityToPlay(null));
game.getPhaseHandler().devModeSet(PhaseType.COMBAT_DECLARE_ATTACKERS, p); game.getPhaseHandler().devAdvanceToPhase(PhaseType.COMBAT_BEGIN);
Combat combat = new Combat(p); game.getAction().checkStateEffects(true);
combat.addAttacker(attacker1, opponent); AssertJUnit.assertNull(picker.chooseSpellAbilityToPlay(null));
combat.addAttacker(attacker2, opponent);
game.getPhaseHandler().setCombat(combat);
game.getAction().checkStateEffects(true);
AssertJUnit.assertNull(picker.chooseSpellAbilityToPlay(null));
game.getPhaseHandler().devModeSet(PhaseType.COMBAT_DECLARE_BLOCKERS, p, false); game.getPhaseHandler().devModeSet(PhaseType.COMBAT_DECLARE_ATTACKERS, p);
game.getAction().checkStateEffects(true); Combat combat = new Combat(p);
combat.addBlocker(attacker1, blocker); combat.addAttacker(attacker1, opponent);
combat.getBandOfAttacker(attacker1).setBlocked(true); combat.addAttacker(attacker2, opponent);
combat.getBandOfAttacker(attacker2).setBlocked(false); game.getPhaseHandler().setCombat(combat);
combat.orderBlockersForDamageAssignment(); game.getAction().checkStateEffects(true);
combat.orderAttackersForDamageAssignment(); AssertJUnit.assertNull(picker.chooseSpellAbilityToPlay(null));
SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertNotNull(sa); game.getPhaseHandler().devModeSet(PhaseType.COMBAT_DECLARE_BLOCKERS, p, false);
AssertJUnit.assertEquals("Target creature gets +3/+3 until end of turn.", sa.toString()); game.getAction().checkStateEffects(true);
AssertJUnit.assertEquals(attacker2, sa.getTargetCard()); combat.addBlocker(attacker1, blocker);
} combat.getBandOfAttacker(attacker1).setBlocked(true);
combat.getBandOfAttacker(attacker2).setBlocked(false);
@Test combat.orderBlockersForDamageAssignment();
combat.orderAttackersForDamageAssignment();
SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertNotNull(sa);
AssertJUnit.assertEquals("Target creature gets +3/+3 until end of turn.", sa.toString());
AssertJUnit.assertEquals(attacker2, sa.getTargetCard());
}
@Test
public void testPlayingSorceryPumpSpellsBeforeBlocks() { public void testPlayingSorceryPumpSpellsBeforeBlocks() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
Player opponent = game.getPlayers().get(0); Player opponent = game.getPlayers().get(0);
opponent.setLife(2, null); opponent.setLife(2, null);
addCard("Fugitive Wizard", opponent); addCard("Fugitive Wizard", opponent);
Card attacker1 = addCard("Dwarven Trader", p); Card attacker1 = addCard("Dwarven Trader", p);
attacker1.setSickness(false); attacker1.setSickness(false);
Card attacker2 = addCard("Kird Ape", p); Card attacker2 = addCard("Kird Ape", p);
attacker2.setSickness(false); attacker2.setSickness(false);
addCard("Mountain", p); addCard("Mountain", p);
Card furor = addCardToZone("Furor of the Bitten", p, ZoneType.Hand); Card furor = addCardToZone("Furor of the Bitten", p, ZoneType.Hand);
game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertNotNull(sa); AssertJUnit.assertNotNull(sa);
AssertJUnit.assertEquals(furor.getSpellAbilities().get(0), sa); AssertJUnit.assertEquals(furor.getSpellAbilities().get(0), sa);
AssertJUnit.assertEquals(attacker1, sa.getTargetCard()); AssertJUnit.assertEquals(attacker1, sa.getTargetCard());
} }
@Test @Test
public void testPlayingRemovalBeforeBlocks() { public void testPlayingRemovalBeforeBlocks() {
Game game = initAndCreateGame(); Game game = initAndCreateGame();
Player p = game.getPlayers().get(1); Player p = game.getPlayers().get(1);
Player opponent = game.getPlayers().get(0); Player opponent = game.getPlayers().get(0);
opponent.setLife(2, null); opponent.setLife(2, null);
Card blocker = addCard("Fugitive Wizard", opponent); Card blocker = addCard("Fugitive Wizard", opponent);
Card attacker1 = addCard("Dwarven Trader", p); Card attacker1 = addCard("Dwarven Trader", p);
attacker1.setSickness(false); attacker1.setSickness(false);
addCard("Swamp", p); addCard("Swamp", p);
addCard("Swamp", p); addCard("Swamp", p);
addCardToZone("Doom Blade", p, ZoneType.Hand); addCardToZone("Doom Blade", p, ZoneType.Hand);
game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p); game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p);
game.getAction().checkStateEffects(true); game.getAction().checkStateEffects(true);
SpellAbilityPicker picker = new SpellAbilityPicker(game, p); SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null); SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertNotNull(sa); AssertJUnit.assertNotNull(sa);
AssertJUnit.assertEquals("Destroy target nonblack creature.", sa.toString()); AssertJUnit.assertEquals("Destroy target nonblack creature.", sa.toString());
AssertJUnit.assertEquals(blocker, sa.getTargetCard()); AssertJUnit.assertEquals(blocker, sa.getTargetCard());
} }
} }