mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Remove assumption about having a single opponent in game scoring function for AI simulation.
This commit is contained in:
@@ -40,12 +40,11 @@ public class GameSimulator {
|
||||
debugPrint = false;
|
||||
// TODO: Make this logic more bulletproof.
|
||||
Player origAiPlayer = origGame.getPlayers().get(1);
|
||||
Player origOpponent = origGame.getPlayers().get(0);
|
||||
origScore = eval.getScoreForGameState(origGame, origAiPlayer, origOpponent);
|
||||
origScore = eval.getScoreForGameState(origGame, origAiPlayer);
|
||||
|
||||
ArrayList<String> simLines = new ArrayList<String>();
|
||||
debugLines = simLines;
|
||||
int simScore = eval.getScoreForGameState(simGame, aiPlayer, opponent);
|
||||
int simScore = eval.getScoreForGameState(simGame, aiPlayer);
|
||||
if (simScore != origScore) {
|
||||
// Print debug info.
|
||||
printDiff(origLines, simLines);
|
||||
@@ -155,6 +154,7 @@ public class GameSimulator {
|
||||
System.err.println("Stack empty: " + sa);
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
// TODO: This needs to set an AI controller for all opponents, in case of multiplayer.
|
||||
opponent.runWithController(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -181,7 +181,7 @@ public class GameSimulator {
|
||||
ArrayList<String> simLines = new ArrayList<String>();
|
||||
debugLines = simLines;
|
||||
debugPrint = false;
|
||||
int score = eval.getScoreForGameState(simGame, aiPlayer, opponent);
|
||||
int score = eval.getScoreForGameState(simGame, aiPlayer);
|
||||
debugLines = null;
|
||||
debugPrint = true;
|
||||
printDiff(origLines, simLines);
|
||||
|
||||
@@ -8,7 +8,7 @@ import forge.game.zone.ZoneType;
|
||||
|
||||
public class GameStateEvaluator {
|
||||
|
||||
public int getScoreForGameState(Game game, Player aiPlayer, Player opponent) {
|
||||
public int getScoreForGameState(Game game, Player aiPlayer) {
|
||||
if (game.isGameOver()) {
|
||||
return game.getOutcome().getWinningPlayer() == aiPlayer ? Integer.MAX_VALUE : Integer.MIN_VALUE;
|
||||
}
|
||||
@@ -43,13 +43,19 @@ public class GameStateEvaluator {
|
||||
if (!nonAbilityText.isEmpty()) {
|
||||
GameSimulator.debugPrint(" "+nonAbilityText.replaceAll("CARDNAME", c.getName()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
GameSimulator.debugPrint(" My life: " + aiPlayer.getLife());
|
||||
score += aiPlayer.getLife();
|
||||
GameSimulator.debugPrint(" Opponent life: -" + opponent.getLife());
|
||||
score -= opponent.getLife();
|
||||
int opponentIndex = 1;
|
||||
int opponentLife = 0;
|
||||
for (Player opponent : game.getPlayers()) {
|
||||
if (opponent != aiPlayer) {
|
||||
GameSimulator.debugPrint(" Opponent " + opponentIndex + " life: -" + opponent.getLife());
|
||||
opponentLife += opponent.getLife();
|
||||
opponentIndex++;
|
||||
}
|
||||
}
|
||||
score -= opponentLife / (game.getPlayers().size() - 1);
|
||||
GameSimulator.debugPrint("Score = " + score);
|
||||
return score;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user