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;
|
debugPrint = false;
|
||||||
// TODO: Make this logic more bulletproof.
|
// TODO: Make this logic more bulletproof.
|
||||||
Player origAiPlayer = origGame.getPlayers().get(1);
|
Player origAiPlayer = origGame.getPlayers().get(1);
|
||||||
Player origOpponent = origGame.getPlayers().get(0);
|
origScore = eval.getScoreForGameState(origGame, origAiPlayer);
|
||||||
origScore = eval.getScoreForGameState(origGame, origAiPlayer, origOpponent);
|
|
||||||
|
|
||||||
ArrayList<String> simLines = new ArrayList<String>();
|
ArrayList<String> simLines = new ArrayList<String>();
|
||||||
debugLines = simLines;
|
debugLines = simLines;
|
||||||
int simScore = eval.getScoreForGameState(simGame, aiPlayer, opponent);
|
int simScore = eval.getScoreForGameState(simGame, aiPlayer);
|
||||||
if (simScore != origScore) {
|
if (simScore != origScore) {
|
||||||
// Print debug info.
|
// Print debug info.
|
||||||
printDiff(origLines, simLines);
|
printDiff(origLines, simLines);
|
||||||
@@ -155,6 +154,7 @@ public class GameSimulator {
|
|||||||
System.err.println("Stack empty: " + sa);
|
System.err.println("Stack empty: " + sa);
|
||||||
return Integer.MIN_VALUE;
|
return Integer.MIN_VALUE;
|
||||||
}
|
}
|
||||||
|
// TODO: This needs to set an AI controller for all opponents, in case of multiplayer.
|
||||||
opponent.runWithController(new Runnable() {
|
opponent.runWithController(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -181,7 +181,7 @@ public class GameSimulator {
|
|||||||
ArrayList<String> simLines = new ArrayList<String>();
|
ArrayList<String> simLines = new ArrayList<String>();
|
||||||
debugLines = simLines;
|
debugLines = simLines;
|
||||||
debugPrint = false;
|
debugPrint = false;
|
||||||
int score = eval.getScoreForGameState(simGame, aiPlayer, opponent);
|
int score = eval.getScoreForGameState(simGame, aiPlayer);
|
||||||
debugLines = null;
|
debugLines = null;
|
||||||
debugPrint = true;
|
debugPrint = true;
|
||||||
printDiff(origLines, simLines);
|
printDiff(origLines, simLines);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import forge.game.zone.ZoneType;
|
|||||||
|
|
||||||
public class GameStateEvaluator {
|
public class GameStateEvaluator {
|
||||||
|
|
||||||
public int getScoreForGameState(Game game, Player aiPlayer, Player opponent) {
|
public int getScoreForGameState(Game game, Player aiPlayer) {
|
||||||
if (game.isGameOver()) {
|
if (game.isGameOver()) {
|
||||||
return game.getOutcome().getWinningPlayer() == aiPlayer ? Integer.MAX_VALUE : Integer.MIN_VALUE;
|
return game.getOutcome().getWinningPlayer() == aiPlayer ? Integer.MAX_VALUE : Integer.MIN_VALUE;
|
||||||
}
|
}
|
||||||
@@ -43,13 +43,19 @@ public class GameStateEvaluator {
|
|||||||
if (!nonAbilityText.isEmpty()) {
|
if (!nonAbilityText.isEmpty()) {
|
||||||
GameSimulator.debugPrint(" "+nonAbilityText.replaceAll("CARDNAME", c.getName()));
|
GameSimulator.debugPrint(" "+nonAbilityText.replaceAll("CARDNAME", c.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
GameSimulator.debugPrint(" My life: " + aiPlayer.getLife());
|
GameSimulator.debugPrint(" My life: " + aiPlayer.getLife());
|
||||||
score += aiPlayer.getLife();
|
score += aiPlayer.getLife();
|
||||||
GameSimulator.debugPrint(" Opponent life: -" + opponent.getLife());
|
int opponentIndex = 1;
|
||||||
score -= opponent.getLife();
|
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);
|
GameSimulator.debugPrint("Score = " + score);
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user