Fix simulated AI finding wrong card in hand when simulating and add a test.

This commit is contained in:
Myrd
2015-02-08 20:21:23 +00:00
parent 2dc5d6da09
commit 1963cc94ad
2 changed files with 28 additions and 3 deletions

View File

@@ -112,7 +112,7 @@ public class GameSimulator {
Card origHostCard = sa.getHostCard();
ZoneType zone = origHostCard.getZone().getZoneType();
for (Card c : simGame.getCardsIn(zone)) {
if (!c.getOwner().getController().isAI()) {
if (c.getController() != aiPlayer) {
continue;
}
if (c.getName().equals(origHostCard.getName())) {
@@ -137,6 +137,7 @@ public class GameSimulator {
return Integer.MIN_VALUE;
}
System.out.println("Found SA " + sa + " on host card " + sa.getHostCard() + " with owner:"+ sa.getHostCard().getOwner());
sa.setActivatingPlayer(aiPlayer);
if (origSa.usesTargeting()) {
for (GameObject o : origSa.getTargets().getTargets()) {

View File

@@ -244,10 +244,34 @@ public class GameSimulatorTest extends TestCase {
GameSimulator sim = new GameSimulator(game, p);
Game simGame = sim.getSimulatedGameState();
Card ripperCopy = findCardWithName(simGame, "");
SpellAbility unmorphSA = findSAWithPrefix(ripperCopy, "Morph - Reveal a black card");
SpellAbility unmorphSA = findSAWithPrefix(ripper, "Morph - Reveal a black card");
assertNotNull(unmorphSA);
sim.simulateSpellAbility(unmorphSA);
assertEquals(18, simGame.getPlayers().get(0).getLife());
}
public void testFindingOwnCard() {
Game game = initAndCreateGame();
Player p0 = game.getPlayers().get(0);
Player p1 = game.getPlayers().get(1);
Card fractureP0 = createCard("Skull Fracture", p0);
p0.getZone(ZoneType.Hand).add(fractureP0);
Card creature = createCard("Runeclaw Bear", p0);
p0.getZone(ZoneType.Hand).add(creature);
Card fractureP1 = createCard("Skull Fracture", p1);
p1.getZone(ZoneType.Hand).add(fractureP1);
addCard("Swamp", p1);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p1);
game.getAction().checkStateEffects(true);
GameSimulator sim = new GameSimulator(game, p1);
Game simGame = sim.getSimulatedGameState();
SpellAbility fractureSa = fractureP1.getSpellAbilities().get(0);
assertNotNull(fractureSa);
fractureSa.getTargets().add(p0);
sim.simulateSpellAbility(fractureSa);
assertEquals(1, simGame.getPlayers().get(0).getCardsIn(ZoneType.Hand).size());
assertEquals(0, simGame.getPlayers().get(1).getCardsIn(ZoneType.Hand).size());
}
}