mirror of
https://github.com/correl/mage.git
synced 2025-01-11 19:13:02 +00:00
Minor changes to AI logging.
This commit is contained in:
parent
0cf25a5c8e
commit
27d441de0a
3 changed files with 41 additions and 19 deletions
|
@ -95,7 +95,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
||||||
public boolean priority(Game game) {
|
public boolean priority(Game game) {
|
||||||
if (lastLoggedTurn != game.getTurnNum()) {
|
if (lastLoggedTurn != game.getTurnNum()) {
|
||||||
lastLoggedTurn = game.getTurnNum();
|
lastLoggedTurn = game.getTurnNum();
|
||||||
logger.info(new StringBuilder("------------------------ ").append("Turn: ").append(game.getTurnNum()).append(" [").append(game.getPlayer(game.getActivePlayerId()).getName()).append("----------------------------------------------------").toString());
|
logger.info(new StringBuilder("============================== ").append("Turn: ").append(game.getTurnNum()).append(" [").append(game.getPlayer(game.getActivePlayerId()).getName()).append("] ====================================================").toString());
|
||||||
}
|
}
|
||||||
logState(game);
|
logState(game);
|
||||||
logger.debug("Priority -- Step: " + (game.getTurn().getStepType() + " ").substring(0,25) + " ActivePlayer-" + game.getPlayer(game.getActivePlayerId()).getName() + " PriorityPlayer-" + name);
|
logger.debug("Priority -- Step: " + (game.getTurn().getStepType() + " ").substring(0,25) + " ActivePlayer-" + game.getPlayer(game.getActivePlayerId()).getName() + " PriorityPlayer-" + name);
|
||||||
|
@ -110,6 +110,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
||||||
if (game.getActivePlayerId().equals(playerId)) {
|
if (game.getActivePlayerId().equals(playerId)) {
|
||||||
printOutState(game);
|
printOutState(game);
|
||||||
if (actions.size() == 0) {
|
if (actions.size() == 0) {
|
||||||
|
logger.info("Sim Calculate pre combat actions ----------------------------------------------------- ");
|
||||||
calculatePreCombatActions(game);
|
calculatePreCombatActions(game);
|
||||||
}
|
}
|
||||||
act(game);
|
act(game);
|
||||||
|
@ -126,6 +127,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
||||||
if (!game.getActivePlayerId().equals(playerId)) {
|
if (!game.getActivePlayerId().equals(playerId)) {
|
||||||
printOutState(game);
|
printOutState(game);
|
||||||
if (actions.size() == 0) {
|
if (actions.size() == 0) {
|
||||||
|
logger.info("Sim Calculate declare attackers actions ----------------------------------------------------- ");
|
||||||
calculatePreCombatActions(game);
|
calculatePreCombatActions(game);
|
||||||
}
|
}
|
||||||
act(game);
|
act(game);
|
||||||
|
@ -163,12 +165,11 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void calculatePreCombatActions(Game game) {
|
protected void calculatePreCombatActions(Game game) {
|
||||||
if (!getNextAction(game)) {
|
if (!getNextAction(game)) {
|
||||||
currentScore = GameStateEvaluator2.evaluate(playerId, game);
|
currentScore = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
Game sim = createSimulation(game);
|
Game sim = createSimulation(game);
|
||||||
SimulationNode2.resetCount();
|
SimulationNode2.resetCount();
|
||||||
logger.info("Sim Calculate pre combat actions -----------------------------------------------------------------------------------------");
|
|
||||||
root = new SimulationNode2(null, sim, maxDepth, playerId);
|
root = new SimulationNode2(null, sim, maxDepth, playerId);
|
||||||
|
|
||||||
addActionsTimed();
|
addActionsTimed();
|
||||||
|
@ -177,7 +178,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
||||||
root = root.children.get(0);
|
root = root.children.get(0);
|
||||||
// int bestScore = root.getScore();
|
// int bestScore = root.getScore();
|
||||||
// if (bestScore > currentScore || allowBadMoves) {
|
// if (bestScore > currentScore || allowBadMoves) {
|
||||||
actions = new LinkedList<Ability>(root.abilities);
|
actions = new LinkedList<>(root.abilities);
|
||||||
combat = root.combat;
|
combat = root.combat;
|
||||||
for (Ability ability : actions) {
|
for (Ability ability : actions) {
|
||||||
actionCache.add(ability.getRule() + "_" + ability.getSourceId());
|
actionCache.add(ability.getRule() + "_" + ability.getSourceId());
|
||||||
|
@ -185,6 +186,8 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
|
||||||
} else {
|
} else {
|
||||||
logger.info("[" + game.getPlayer(playerId).getName() + "][pre] Action: skip");
|
logger.info("[" + game.getPlayer(playerId).getName() + "][pre] Action: skip");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logger.debug("Next Action exists!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,11 @@
|
||||||
|
|
||||||
package mage.player.ai;
|
package mage.player.ai;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.player.ai.ma.ArtificialScoringSystem;
|
import mage.player.ai.ma.ArtificialScoringSystem;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.util.Logging;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -25,10 +21,6 @@ import java.util.logging.Logger;
|
||||||
public class GameStateEvaluator2 {
|
public class GameStateEvaluator2 {
|
||||||
|
|
||||||
private static final transient org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(GameStateEvaluator2.class);
|
private static final transient org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(GameStateEvaluator2.class);
|
||||||
// private static final transient Logger logger = Logging.getLogger(GameStateEvaluator2.class.getName());
|
|
||||||
// static {
|
|
||||||
// logger.setLevel(Level.ALL);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static final int WIN_GAME_SCORE = 100000000;
|
public static final int WIN_GAME_SCORE = 100000000;
|
||||||
public static final int LOSE_GAME_SCORE = -WIN_GAME_SCORE;
|
public static final int LOSE_GAME_SCORE = -WIN_GAME_SCORE;
|
||||||
|
@ -62,23 +54,50 @@ public class GameStateEvaluator2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
int permanentScore = 0;
|
int permanentScore = 0;
|
||||||
|
int playerScore = 0;
|
||||||
|
int opponentScore = 0;
|
||||||
try {
|
try {
|
||||||
|
StringBuilder sbPlayer = new StringBuilder();
|
||||||
|
StringBuilder sbOpponent = new StringBuilder();
|
||||||
|
// add values of player
|
||||||
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(playerId)) {
|
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(playerId)) {
|
||||||
permanentScore += evaluatePermanent(permanent, game);
|
int onePermScore = evaluatePermanent(permanent, game);
|
||||||
|
playerScore += onePermScore;
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
sbPlayer.append(permanent.getName()).append("[").append(onePermScore).append("] ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
sbPlayer.insert(0, playerScore + " - ");
|
||||||
|
sbPlayer.insert(0, "Player..: ");
|
||||||
|
logger.debug(sbPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add values of opponent
|
||||||
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(opponent.getId())) {
|
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(opponent.getId())) {
|
||||||
permanentScore -= evaluatePermanent(permanent, game);
|
int onePermScore = evaluatePermanent(permanent, game);
|
||||||
|
opponentScore += onePermScore;
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
sbOpponent.append(permanent.getName()).append("[").append(onePermScore).append("] ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
sbOpponent.insert(0, opponentScore + " - ");
|
||||||
|
sbOpponent.insert(0, "Opponent: ");
|
||||||
|
|
||||||
|
logger.debug(sbOpponent);
|
||||||
|
}
|
||||||
|
permanentScore = playerScore - opponentScore;
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
}
|
}
|
||||||
//permanentScore *= PERMANENT_FACTOR;
|
//permanentScore *= PERMANENT_FACTOR;
|
||||||
|
|
||||||
int handScore = 0;
|
int handScore;
|
||||||
handScore = player.getHand().size() - opponent.getHand().size();
|
handScore = player.getHand().size() - opponent.getHand().size();
|
||||||
handScore *= 5;
|
handScore *= 5;
|
||||||
|
|
||||||
int score = lifeScore + permanentScore + handScore;
|
int score = lifeScore + permanentScore + handScore;
|
||||||
logger.debug("game state evaluated to- lifeScore:" + lifeScore + " permanentScore:" + permanentScore + " handScore:" + handScore + " total:" + score);
|
logger.debug(score + " total Score (life:" + lifeScore + " permanents:" + permanentScore + " hand:" + handScore +")");
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,8 @@ import mage.game.permanent.Permanent;
|
||||||
public class PermanentEvaluator {
|
public class PermanentEvaluator {
|
||||||
|
|
||||||
//preserve calculations for efficiency
|
//preserve calculations for efficiency
|
||||||
private Map<UUID, Integer> values = new HashMap<UUID, Integer>();
|
private final Map<UUID, Integer> values = new HashMap<>();
|
||||||
private CombatEvaluator combat = new CombatEvaluator();
|
private final CombatEvaluator combat = new CombatEvaluator();
|
||||||
|
|
||||||
public int evaluate(Permanent permanent, Game game) {
|
public int evaluate(Permanent permanent, Game game) {
|
||||||
if (!values.containsKey(permanent.getId())) {
|
if (!values.containsKey(permanent.getId())) {
|
||||||
|
|
Loading…
Reference in a new issue