protected int addActions(SimulationNode2 node, int depth, int alpha, int 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();
int val;
if (Thread.interrupted()) {
Thread.currentThread().interrupt();
val = GameStateEvaluator2.evaluate(playerId, game);
logger.trace("interrupted - " + val);
return val;
}
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.gameOver(null)) {
logger.trace("Add actions -- reached end state, node count=" + SimulationNode2.nodeCount + ", depth=" + depth);
val = GameStateEvaluator2.evaluate(playerId, game);
UUID currentPlayerId = node.getGame().getPlayerList().get();
//logger.info("reached - " + val + ", playerId=" + playerId + ", node.pid="+currentPlayerId);
return val;
} else if (node.getChildren().size() > 0) {
logger.trace("Add actions -- something added children:" + node.getChildren().size());
val = minimaxAB(node, depth - 1, alpha, beta);
return val;
} else {
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 (!game.getStack().isEmpty()) {
resolve(node, depth, game);
} else {
game.getPlayers().resetPassed();
playNext(game, game.getActivePlayerId(), node);
}
}
if (game.gameOver(null)) {
val = GameStateEvaluator2.evaluate(playerId, game);
} else if (node.getChildren().size() > 0) {
//declared attackers or blockers or triggered abilities
logger.debug("Add actions -- attack/block/trigger added children:" + node.getChildren().size());
val = minimaxAB(node, depth - 1, alpha, beta);
} else {
val = simulatePriority(node, game, depth, alpha, beta);
}
}
logger.trace("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
return val;
}