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