mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Remove some assumptions about ordering of players in simulation AI code.
This commit is contained in:
@@ -24,25 +24,21 @@ public class GameSimulator {
|
||||
private GameCopier copier;
|
||||
private Game simGame;
|
||||
private Player aiPlayer;
|
||||
private Player opponent;
|
||||
private GameStateEvaluator eval;
|
||||
private ArrayList<String> origLines;
|
||||
private int origScore;
|
||||
|
||||
public GameSimulator(final Game origGame) {
|
||||
public GameSimulator(final Game origGame, final Player origAiPlayer) {
|
||||
copier = new GameCopier(origGame);
|
||||
simGame = copier.makeCopy();
|
||||
// TODO:
|
||||
aiPlayer = simGame.getPlayers().get(1);
|
||||
opponent = simGame.getPlayers().get(0);
|
||||
|
||||
aiPlayer = (Player) copier.find(origAiPlayer);
|
||||
eval = new GameStateEvaluator();
|
||||
|
||||
origLines = new ArrayList<String>();
|
||||
debugLines = origLines;
|
||||
|
||||
debugPrint = false;
|
||||
// TODO: Make this logic more bulletproof.
|
||||
Player origAiPlayer = origGame.getPlayers().get(1);
|
||||
origScore = eval.getScoreForGameState(origGame, origAiPlayer);
|
||||
|
||||
eval.setDebugging(true);
|
||||
@@ -174,6 +170,14 @@ public class GameSimulator {
|
||||
System.err.println("Stack empty: " + sa);
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
// TODO: Support multiple opponents.
|
||||
Player opponent = null;
|
||||
for (Player p : simGame.getPlayers()) {
|
||||
if (p != aiPlayer) {
|
||||
opponent = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
resolveStack(simGame, opponent);
|
||||
|
||||
// TODO: If this is during combat, before blockers are declared,
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SpellAbilityPicker {
|
||||
}
|
||||
SpellAbility bestSa = null;
|
||||
System.out.println("Evaluating...");
|
||||
GameSimulator simulator = new GameSimulator(game);
|
||||
GameSimulator simulator = new GameSimulator(game, player);
|
||||
// FIXME: This is wasteful, we should re-use the same simulator...
|
||||
int origGameScore = simulator.getScoreForOrigGame();
|
||||
int bestSaValue = origGameScore;
|
||||
@@ -145,7 +145,7 @@ public class SpellAbilityPicker {
|
||||
private int evaluateSa(SpellAbility sa) {
|
||||
System.out.println("Evaluate SA: " + sa);
|
||||
if (!sa.usesTargeting()) {
|
||||
GameSimulator simulator = new GameSimulator(game);
|
||||
GameSimulator simulator = new GameSimulator(game, player);
|
||||
return simulator.simulateSpellAbility(sa);
|
||||
}
|
||||
PossibleTargetSelector selector = new PossibleTargetSelector(game, player, sa);
|
||||
@@ -153,7 +153,7 @@ public class SpellAbilityPicker {
|
||||
TargetChoices tgt = null;
|
||||
while (selector.selectNextTargets()) {
|
||||
System.out.println("Trying targets: " + sa.getTargets().getTargetedString());
|
||||
GameSimulator simulator = new GameSimulator(game);
|
||||
GameSimulator simulator = new GameSimulator(game, player);
|
||||
int score = simulator.simulateSpellAbility(sa);
|
||||
if (score > bestScore) {
|
||||
bestScore = score;
|
||||
|
||||
@@ -85,7 +85,7 @@ public class GameSimulatorTest extends TestCase {
|
||||
SpellAbility outlastSA = findSAWithPrefix(herald, "Outlast");
|
||||
assertNotNull(outlastSA);
|
||||
|
||||
GameSimulator sim = new GameSimulator(game);
|
||||
GameSimulator sim = new GameSimulator(game, p);
|
||||
int score = sim.simulateSpellAbility(outlastSA);
|
||||
assertTrue(score > 0);
|
||||
Game simGame = sim.getSimulatedGameState();
|
||||
@@ -129,7 +129,7 @@ public class GameSimulatorTest extends TestCase {
|
||||
SpellAbility outlastSA = findSAWithPrefix(herald, "Outlast");
|
||||
assertNotNull(outlastSA);
|
||||
|
||||
GameSimulator sim = new GameSimulator(game);
|
||||
GameSimulator sim = new GameSimulator(game, p);
|
||||
int score = sim.simulateSpellAbility(outlastSA);
|
||||
assertTrue(score > 0);
|
||||
Game simGame = sim.getSimulatedGameState();
|
||||
@@ -151,7 +151,7 @@ public class GameSimulatorTest extends TestCase {
|
||||
game.getAction().checkStateEffects(true);
|
||||
assertEquals(1, bear.getAmountOfKeyword("Unblockable"));
|
||||
|
||||
GameSimulator sim = new GameSimulator(game);
|
||||
GameSimulator sim = new GameSimulator(game, p);
|
||||
Game simGame = sim.getSimulatedGameState();
|
||||
Card bearCopy = findCardWithName(simGame, bearCardName);
|
||||
assertEquals(1, bearCopy.getAmountOfKeyword("Unblockable"));
|
||||
@@ -169,7 +169,7 @@ public class GameSimulatorTest extends TestCase {
|
||||
game.getAction().checkStateEffects(true);
|
||||
assertEquals(1, bear.getAmountOfKeyword("Lifelink"));
|
||||
|
||||
GameSimulator sim = new GameSimulator(game);
|
||||
GameSimulator sim = new GameSimulator(game, p);
|
||||
Game simGame = sim.getSimulatedGameState();
|
||||
Card bearCopy = findCardWithName(simGame, bearCardName);
|
||||
assertEquals(1, bearCopy.getAmountOfKeyword("Lifelink"));
|
||||
@@ -192,7 +192,7 @@ public class GameSimulatorTest extends TestCase {
|
||||
SpellAbility playMerchantSa = c.getSpellAbilities().get(0);
|
||||
playMerchantSa.setActivatingPlayer(p);
|
||||
|
||||
GameSimulator sim = new GameSimulator(game);
|
||||
GameSimulator sim = new GameSimulator(game, p);
|
||||
int origScore = sim.getScoreForOrigGame();
|
||||
int score = sim.simulateSpellAbility(playMerchantSa);
|
||||
assertTrue(String.format("score=%d vs. origScore=%d", score, origScore), score > origScore);
|
||||
@@ -217,7 +217,7 @@ public class GameSimulatorTest extends TestCase {
|
||||
assertTrue(c2.hasStartOfKeyword("(Echo unpaid)"));
|
||||
c2.removeAllExtrinsicKeyword("(Echo unpaid)");
|
||||
|
||||
GameSimulator sim = new GameSimulator(game);
|
||||
GameSimulator sim = new GameSimulator(game, p);
|
||||
Game simGame = sim.getSimulatedGameState();
|
||||
Card c1Copy = findCardWithName(simGame, c1Name);
|
||||
assertTrue(c1Copy.hasStartOfKeyword("(Echo unpaid)"));
|
||||
|
||||
Reference in New Issue
Block a user