mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 19:41:59 -08:00
Some changes to AI logging.
This commit is contained in:
parent
787288c879
commit
cb43a58290
2 changed files with 89 additions and 49 deletions
|
|
@ -219,7 +219,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
boolean usedStack = false;
|
boolean usedStack = false;
|
||||||
while (actions.peek() != null) {
|
while (actions.peek() != null) {
|
||||||
Ability ability = actions.poll();
|
Ability ability = actions.poll();
|
||||||
logger.info(new StringBuilder("[").append(game.getPlayer(playerId).getName()).append("] Action: ").append(ability.toString()).toString());
|
logger.info(new StringBuilder("Act -------------> [").append(game.getPlayer(playerId).getName()).append("] Action: ").append(ability.toString()).toString());
|
||||||
if (ability.getTargets().size() > 0) {
|
if (ability.getTargets().size() > 0) {
|
||||||
for (Target target : ability.getTargets()) {
|
for (Target target : ability.getTargets()) {
|
||||||
for (UUID id : target.getTargets()) {
|
for (UUID id : target.getTargets()) {
|
||||||
|
|
@ -318,6 +318,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int minimaxAB(SimulationNode2 node, int depth, int alpha, int beta) {
|
protected int minimaxAB(SimulationNode2 node, int depth, int alpha, int beta) {
|
||||||
|
logger.info("Simulating minimaxAB -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " node-score: " + (node != null ? node.getScore() : "null"));
|
||||||
UUID currentPlayerId = node.getGame().getPlayerList().get();
|
UUID currentPlayerId = node.getGame().getPlayerList().get();
|
||||||
SimulationNode2 bestChild = null;
|
SimulationNode2 bestChild = null;
|
||||||
for (SimulationNode2 child : node.getChildren()) {
|
for (SimulationNode2 child : node.getChildren()) {
|
||||||
|
|
@ -412,6 +413,11 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
game.getPlayerList().setCurrent(game.getActivePlayerId());
|
game.getPlayerList().setCurrent(game.getActivePlayerId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base call for simulation of AI actions
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
protected Integer addActionsTimed() {
|
protected Integer addActionsTimed() {
|
||||||
FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
|
FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
|
||||||
|
|
||||||
|
|
@ -442,7 +448,9 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int addActions(SimulationNode2 node, int depth, int alpha, int beta) {
|
protected int addActions(SimulationNode2 node, int depth, int alpha, int beta) {
|
||||||
logger.debug("addActions: " + depth + ", alpha=" + alpha + ", beta=" + beta);
|
if (logger.isInfoEnabled() && node !=null && node.getAbilities() != null && !node.getAbilities().toString().equals("[Pass]")){
|
||||||
|
logger.info("Add actions [" + depth +"] " + (node.getAbilities().toString()+ " -- a: " + alpha + " b: " + beta));
|
||||||
|
}
|
||||||
Game game = node.getGame();
|
Game game = node.getGame();
|
||||||
int val;
|
int val;
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
|
|
@ -452,17 +460,17 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.isGameOver()) {
|
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.isGameOver()) {
|
||||||
logger.trace("Simulating -- reached end state, node count=" + SimulationNode2.nodeCount + ", depth=" + depth);
|
logger.trace("Add actions -- reached end state, node count=" + SimulationNode2.nodeCount + ", depth=" + depth);
|
||||||
val = GameStateEvaluator2.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
UUID currentPlayerId = node.getGame().getPlayerList().get();
|
UUID currentPlayerId = node.getGame().getPlayerList().get();
|
||||||
//logger.info("reached - " + val + ", playerId=" + playerId + ", node.pid="+currentPlayerId);
|
//logger.info("reached - " + val + ", playerId=" + playerId + ", node.pid="+currentPlayerId);
|
||||||
return val;
|
return val;
|
||||||
} else if (node.getChildren().size() > 0) {
|
} else if (node.getChildren().size() > 0) {
|
||||||
logger.trace("Simulating -- something added children:" + node.getChildren().size());
|
logger.trace("Add actions -- something added children:" + node.getChildren().size());
|
||||||
val = minimaxAB(node, depth - 1, alpha, beta);
|
val = minimaxAB(node, depth - 1, alpha, beta);
|
||||||
return val;
|
return val;
|
||||||
} else {
|
} else {
|
||||||
logger.trace("Simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + (node.getPlayerId().equals(playerId) ? "yes" : "no"));
|
logger.trace("Add actions -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + (node.getPlayerId().equals(playerId) ? "yes" : "no"));
|
||||||
if (allPassed(game)) {
|
if (allPassed(game)) {
|
||||||
if (!game.getStack().isEmpty()) {
|
if (!game.getStack().isEmpty()) {
|
||||||
resolve(node, depth, game);
|
resolve(node, depth, game);
|
||||||
|
|
@ -476,7 +484,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
val = GameStateEvaluator2.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
} else if (node.getChildren().size() > 0) {
|
} else if (node.getChildren().size() > 0) {
|
||||||
//declared attackers or blockers or triggered abilities
|
//declared attackers or blockers or triggered abilities
|
||||||
logger.debug("simulating -- attack/block/trigger added children:" + node.getChildren().size());
|
logger.debug("Add actions -- attack/block/trigger added children:" + node.getChildren().size());
|
||||||
val = minimaxAB(node, depth - 1, alpha, beta);
|
val = minimaxAB(node, depth - 1, alpha, beta);
|
||||||
} else {
|
} else {
|
||||||
val = simulatePriority(node, game, depth, alpha, beta);
|
val = simulatePriority(node, game, depth, alpha, beta);
|
||||||
|
|
@ -496,23 +504,26 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
}
|
}
|
||||||
node.setGameValue(game.getState().getValue(true).hashCode());
|
node.setGameValue(game.getState().getValue(true).hashCode());
|
||||||
SimulatedPlayer2 currentPlayer = (SimulatedPlayer2) game.getPlayer(game.getPlayerList().get());
|
SimulatedPlayer2 currentPlayer = (SimulatedPlayer2) game.getPlayer(game.getPlayerList().get());
|
||||||
//logger.info("simulating -- player " + currentPlayer.getName());
|
//logger.info("Sim Prio -- player " + currentPlayer.getName());
|
||||||
SimulationNode2 bestNode = null;
|
SimulationNode2 bestNode = null;
|
||||||
List<Ability> allActions = currentPlayer.simulatePriority(game);
|
List<Ability> allActions = currentPlayer.simulatePriority(game);
|
||||||
optimize(game, allActions);
|
optimize(game, allActions);
|
||||||
logger.debug("Simulating -- (depth=" + depth + ") adding " + allActions.size() + " children:" + allActions);
|
if (logger.isInfoEnabled() && allActions.size() > 0 && depth == maxDepth) {
|
||||||
|
logger.info("Sim Prio [" + depth + "] player " + currentPlayer.getName() + " adding " + allActions.size() + " actions:" + allActions);
|
||||||
|
}
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (Ability action : allActions) {
|
for (Ability action : allActions) {
|
||||||
logger.debug(new StringBuilder("Simulating -- actions: [" + ++counter + "] " + " -> " + action));
|
counter++;
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.debug("Simulating -- interrupted");
|
logger.info("Sim Prio [" + depth + "] -- interrupted");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
if (sim.getPlayer(currentPlayer.getId()).activateAbility((ActivatedAbility) action.copy(), sim)) {
|
if (sim.getPlayer(currentPlayer.getId()).activateAbility((ActivatedAbility) action.copy(), sim)) {
|
||||||
sim.applyEffects();
|
sim.applyEffects();
|
||||||
if (checkForRepeatedAction(sim, node, action, currentPlayer.getId())) {
|
if (checkForRepeatedAction(sim, node, action, currentPlayer.getId())) {
|
||||||
|
logger.info("Sim Prio [" + depth + "] -- repeated action: " + action.toString());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!sim.isGameOver() && action.isUsesStack()) {
|
if (!sim.isGameOver() && action.isUsesStack()) {
|
||||||
|
|
@ -525,7 +536,19 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
|
|
||||||
sim.checkStateAndTriggered();
|
sim.checkStateAndTriggered();
|
||||||
int val = addActions(newNode, depth - 1, alpha, beta);
|
int val = addActions(newNode, depth - 1, alpha, beta);
|
||||||
logger.debug("Simulating -- val = " + val + " depth= " + depth + " (" + action +")");
|
|
||||||
|
if (logger.isInfoEnabled() && depth == maxDepth) {
|
||||||
|
StringBuilder sb = new StringBuilder("Sim Prio [").append(depth).append("] #").append(counter).append(" -- val = ").append(val).append(" (").append(action).append(")");
|
||||||
|
SimulationNode2 logNode = newNode;
|
||||||
|
while (logNode.getChildren() != null && logNode.getChildren().size()>0) {
|
||||||
|
logNode = logNode.getChildren().get(0);
|
||||||
|
if (logNode.getAbilities() != null && logNode.getAbilities().size()>0) {
|
||||||
|
sb.append(" --> ").append(logNode.getAbilities().get(0).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.info(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
if (!currentPlayer.getId().equals(playerId)) {
|
if (!currentPlayer.getId().equals(playerId)) {
|
||||||
if (val < beta) {
|
if (val < beta) {
|
||||||
beta = val;
|
beta = val;
|
||||||
|
|
@ -538,7 +561,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
|
|
||||||
// no need to check other actions
|
// no need to check other actions
|
||||||
if (val == GameStateEvaluator2.LOSE_GAME_SCORE) {
|
if (val == GameStateEvaluator2.LOSE_GAME_SCORE) {
|
||||||
logger.debug("Simulating -- lose - break");
|
logger.debug("Sim Prio -- lose - break");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -555,7 +578,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
* choices = node.getChoices();
|
* choices = node.getChoices();
|
||||||
*/
|
*/
|
||||||
if (depth == maxDepth) {
|
if (depth == maxDepth) {
|
||||||
logger.info(new StringBuilder("Simulating -- Saved (depth=").append(depth).append(") Score: ").append(bestNode.getScore()).append(" abilities: ").append(bestNode.getAbilities().toString()).toString());
|
logger.info(new StringBuilder("Sim Prio [").append(depth).append("] -- Saved best node yet with score: ").append(bestNode.getScore()).append(" abilities: ").append(bestNode.getAbilities().toString()).toString());
|
||||||
node.children.clear();
|
node.children.clear();
|
||||||
node.children.add(bestNode);
|
node.children.add(bestNode);
|
||||||
node.setScore(bestNode.getScore());
|
node.setScore(bestNode.getScore());
|
||||||
|
|
@ -564,35 +587,33 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
|
|
||||||
// no need to check other actions
|
// no need to check other actions
|
||||||
if (val == GameStateEvaluator2.WIN_GAME_SCORE) {
|
if (val == GameStateEvaluator2.WIN_GAME_SCORE) {
|
||||||
logger.debug("Simulating -- win - break");
|
logger.debug("Sim Prio -- win - break");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
//logger.info("simulating -- pruning");
|
//logger.info("Sim Prio -- pruning");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (SimulationNode2.nodeCount > maxNodes) {
|
if (SimulationNode2.nodeCount > maxNodes) {
|
||||||
logger.debug("Simulating -- reached end-state");
|
logger.debug("Sim Prio -- reached end-state");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // end for allActions
|
||||||
|
if (depth == maxDepth) {
|
||||||
|
logger.info(new StringBuilder("Sim Prio [").append(depth).append("] -- End for Max Depth").toString());
|
||||||
}
|
}
|
||||||
if (bestNode != null) {
|
if (bestNode != null) {
|
||||||
node.children.clear();
|
node.children.clear();
|
||||||
node.children.add(bestNode);
|
node.children.add(bestNode);
|
||||||
node.setScore(bestNode.getScore());
|
node.setScore(bestNode.getScore());
|
||||||
|
if (logger.isTraceEnabled() && !bestNode.getAbilities().toString().equals("[Pass]") ) {
|
||||||
|
logger.trace(new StringBuilder("Sim Prio [").append(depth).append("] -- Set after (depth=").append(depth).append(") Score: ").append(bestNode.getScore()).append(" abilities: ").append(bestNode.getAbilities().toString()).toString());
|
||||||
}
|
}
|
||||||
if (!currentPlayer.getId().equals(playerId)) {
|
|
||||||
/*
|
|
||||||
* if (beta == Integer.MAX_VALUE) { int val =
|
|
||||||
* GameStateEvaluator2.evaluate(playerId, game);
|
|
||||||
* logger.info("returning priority beta: " + val); return val;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
//logger.info("returning priority beta: " + beta);
|
if (currentPlayer.getId().equals(playerId)) {
|
||||||
return beta;
|
|
||||||
} else {
|
|
||||||
/*
|
/*
|
||||||
* if (alpha == Integer.MIN_VALUE) { int val =
|
* if (alpha == Integer.MIN_VALUE) { int val =
|
||||||
* GameStateEvaluator2.evaluate(playerId, game);
|
* GameStateEvaluator2.evaluate(playerId, game);
|
||||||
|
|
@ -601,6 +622,13 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
*/
|
*/
|
||||||
//logger.info("returning priority alpha: " + alpha);
|
//logger.info("returning priority alpha: " + alpha);
|
||||||
return alpha;
|
return alpha;
|
||||||
|
} else {
|
||||||
|
// if (beta == Integer.MAX_VALUE) {
|
||||||
|
// int val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
|
// logger.info("returning priority beta: " + val);
|
||||||
|
// return val;
|
||||||
|
// }
|
||||||
|
return beta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1258,7 +1286,6 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
*/
|
*/
|
||||||
protected Game createSimulation(Game game) {
|
protected Game createSimulation(Game game) {
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
|
|
||||||
for (Player copyPlayer : sim.getState().getPlayers().values()) {
|
for (Player copyPlayer : sim.getState().getPlayers().values()) {
|
||||||
Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId()).copy();
|
Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId()).copy();
|
||||||
logger.debug(origPlayer.getName() + " suggested: " + suggested);
|
logger.debug(origPlayer.getName() + " suggested: " + suggested);
|
||||||
|
|
|
||||||
|
|
@ -137,21 +137,22 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
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);
|
||||||
logger.debug("simulating pre combat actions -----------------------------------------------------------------------------------------");
|
|
||||||
|
|
||||||
addActionsTimed();
|
addActionsTimed();
|
||||||
|
logger.trace("After add actions timed: root.children.size = " + root.children.size());
|
||||||
if (root.children.size() > 0) {
|
if (root.children.size() > 0) {
|
||||||
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<Ability>(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());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.debug("[" + game.getPlayer(playerId).getName() + "][pre] Action: skip");
|
logger.info("[" + game.getPlayer(playerId).getName() + "][pre] Action: skip");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -162,7 +163,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
Game sim = createSimulation(game);
|
Game sim = createSimulation(game);
|
||||||
SimulationNode2.resetCount();
|
SimulationNode2.resetCount();
|
||||||
root = new SimulationNode2(null, sim, maxDepth, playerId);
|
root = new SimulationNode2(null, sim, maxDepth, playerId);
|
||||||
logger.debug("simulating post combat actions ----------------------------------------------------------------------------------------");
|
logger.debug("Sim Calculate post combat actions ----------------------------------------------------------------------------------------");
|
||||||
|
|
||||||
addActionsTimed();
|
addActionsTimed();
|
||||||
if (root.children.size() > 0) {
|
if (root.children.size() > 0) {
|
||||||
|
|
@ -185,6 +186,9 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
protected int addActions(SimulationNode2 node, int depth, int alpha, int beta) {
|
protected int addActions(SimulationNode2 node, int depth, int alpha, int beta) {
|
||||||
boolean stepFinished = false;
|
boolean stepFinished = false;
|
||||||
int val;
|
int val;
|
||||||
|
if (logger.isTraceEnabled() && node !=null && node.getAbilities() != null && !node.getAbilities().toString().equals("[Pass]")){
|
||||||
|
logger.trace("Add Action [" + depth + "] " + node.getAbilities().toString() + " a: " + alpha + " b: " + beta);
|
||||||
|
}
|
||||||
Game game = node.getGame();
|
Game game = node.getGame();
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
|
@ -192,15 +196,24 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
return GameStateEvaluator2.evaluate(playerId, game);
|
return GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.isGameOver()) {
|
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.isGameOver()) {
|
||||||
logger.debug("Simulating -- reached end state");
|
|
||||||
val = GameStateEvaluator2.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
StringBuilder sb = new StringBuilder("Add Action [").append(depth).append("] -- reached end state val = ").append(val);
|
||||||
|
SimulationNode2 logNode = node;
|
||||||
|
StringBuilder sb2 = new StringBuilder(" --> ").append(node.getAbilities().get(0).toString());
|
||||||
|
while(logNode.getParent() != null) {
|
||||||
|
logNode = logNode.getParent();
|
||||||
|
sb2.insert(0,"["+node.getDepth()+"] s:" + logNode.score).insert(0," (0/"+node.getAbilities().size()+" " + node.getAbilities().get(0).toString()).insert(0, ") --> ");
|
||||||
|
}
|
||||||
|
logger.debug(sb.append(sb2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (node.getChildren().size() > 0) {
|
else if (node.getChildren().size() > 0) {
|
||||||
logger.debug("Simulating -- something added children:" + node.getChildren().size());
|
logger.debug("Add Action -- something added children:" + node.getChildren().size());
|
||||||
val = minimaxAB(node, depth-1, alpha, beta);
|
val = minimaxAB(node, depth-1, alpha, beta);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.trace("Simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(game.getPlayerList().get()).getName());
|
logger.trace("Add Action -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(game.getPlayerList().get()).getName());
|
||||||
if (allPassed(game)) {
|
if (allPassed(game)) {
|
||||||
if (!game.getStack().isEmpty()) {
|
if (!game.getStack().isEmpty()) {
|
||||||
resolve(node, depth, game);
|
resolve(node, depth, game);
|
||||||
|
|
@ -219,7 +232,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
if (game.getActivePlayerId().equals(playerId)) {
|
if (game.getActivePlayerId().equals(playerId)) {
|
||||||
if (testScore < currentScore) {
|
if (testScore < currentScore) {
|
||||||
// if score at end of step is worse than original score don't check further
|
// if score at end of step is worse than original score don't check further
|
||||||
//logger.debug("simulating -- abandoning check, no immediate benefit");
|
//logger.debug("Add Action -- abandoning check, no immediate benefit");
|
||||||
val = testScore;
|
val = testScore;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -247,7 +260,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node.getChildren().size() > 0) {
|
else if (node.getChildren().size() > 0) {
|
||||||
logger.debug("Simulating -- trigger added children:" + node.getChildren().size());
|
logger.debug("Add Action -- trigger added children:" + node.getChildren().size());
|
||||||
val = minimaxAB(node, depth, alpha, beta);
|
val = minimaxAB(node, depth, alpha, beta);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -319,10 +332,10 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
logger.debug(attacker.getName() + "'s possible attackers: " + attacker.getAvailableAttackers(game));
|
logger.debug(attacker.getName() + "'s possible attackers: " + attacker.getAvailableAttackers(game));
|
||||||
for (Combat engagement: attacker.addAttackers(game)) {
|
for (Combat engagement: attacker.addAttackers(game)) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Attackers: " + engagement.getAttackers() + ", blockers: " + engagement.getBlockers());
|
logger.debug("Sim Attackers: " + engagement.getAttackers() + ", blockers: " + engagement.getBlockers());
|
||||||
}
|
}
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.debug("simulating -- pruning attackers");
|
logger.debug("Sim Attackers -- pruning attackers");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
|
|
@ -335,11 +348,11 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, attackerId, attackerId));
|
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, attackerId, attackerId));
|
||||||
SimulationNode2 newNode = new SimulationNode2(node, sim, depth, attackerId);
|
SimulationNode2 newNode = new SimulationNode2(node, sim, depth, attackerId);
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("simulating attack for player:" + game.getPlayer(attackerId).getName());
|
logger.debug("Sim attack for player:" + game.getPlayer(attackerId).getName());
|
||||||
sim.checkStateAndTriggered();
|
sim.checkStateAndTriggered();
|
||||||
while (!sim.getStack().isEmpty()) {
|
while (!sim.getStack().isEmpty()) {
|
||||||
sim.getStack().resolve(sim);
|
sim.getStack().resolve(sim);
|
||||||
logger.debug("resolving triggered abilities");
|
logger.debug("Sim attack: resolving triggered abilities");
|
||||||
sim.applyEffects();
|
sim.applyEffects();
|
||||||
}
|
}
|
||||||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
|
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
|
||||||
|
|
@ -375,7 +388,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
node.setScore(bestNode.getScore());
|
node.setScore(bestNode.getScore());
|
||||||
}
|
}
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("returning -- combat attacker score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.debug("Sim attackers: returning score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -395,7 +408,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
List<Combat> combats = defender.addBlockers(game);
|
List<Combat> combats = defender.addBlockers(game);
|
||||||
for (Combat engagement: combats) {
|
for (Combat engagement: combats) {
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.debug("simulating -- pruning blockers");
|
logger.debug("Sim blockers -- pruning blockers");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
|
|
@ -410,11 +423,11 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, defenderId, defenderId));
|
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, defenderId, defenderId));
|
||||||
SimulationNode2 newNode = new SimulationNode2(node, sim, depth, defenderId);
|
SimulationNode2 newNode = new SimulationNode2(node, sim, depth, defenderId);
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("simulating block for player:" + game.getPlayer(defenderId).getName());
|
logger.debug("Sim block for player:" + game.getPlayer(defenderId).getName());
|
||||||
sim.checkStateAndTriggered();
|
sim.checkStateAndTriggered();
|
||||||
while (!sim.getStack().isEmpty()) {
|
while (!sim.getStack().isEmpty()) {
|
||||||
sim.getStack().resolve(sim);
|
sim.getStack().resolve(sim);
|
||||||
logger.debug("resolving triggered abilities");
|
logger.debug("Sim blockers: resolving triggered abilities");
|
||||||
sim.applyEffects();
|
sim.applyEffects();
|
||||||
}
|
}
|
||||||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
|
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
|
||||||
|
|
@ -454,7 +467,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
node.setScore(bestNode.getScore());
|
node.setScore(bestNode.getScore());
|
||||||
}
|
}
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("returning -- combat blocker score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.debug("Sim blockers: returning score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -522,7 +535,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
logger.debug("interrupted");
|
logger.debug("interrupted");
|
||||||
return GameStateEvaluator2.evaluate(playerId, game);
|
return GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
logger.debug("simulating -- post combat main");
|
logger.debug("Sim [" + depth + "] -- post combat main");
|
||||||
game.getTurn().setPhase(new PostCombatMainPhase());
|
game.getTurn().setPhase(new PostCombatMainPhase());
|
||||||
if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
|
if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
|
||||||
game.getPhase().setStep(new PostCombatMainStep());
|
game.getPhase().setStep(new PostCombatMainStep());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue