@Override
protected int addActions(SimulationNode node, int alpha, int beta) {
boolean stepFinished = false;
int val;
Game game = node.getGame();
if (Thread.interrupted()) {
Thread.currentThread().interrupt();
logger.debug(indent(node.depth) + "interrupted");
return GameStateEvaluator.evaluate(playerId, game);
}
if (node.depth > maxDepth || game.gameOver(null)) {
logger.debug(indent(node.depth) + "simulating -- reached end state");
val = GameStateEvaluator.evaluate(playerId, game);
}
else if (node.getChildren().size() > 0) {
logger.debug(indent(node.depth) + "simulating -- somthing added children:" + node.getChildren().size());
val = minimaxAB(node, alpha, beta);
}
else {
if (logger.isDebugEnabled())
logger.debug(indent(node.depth) + "simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + node.depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(game.getPlayerList().get()).getName());
if (allPassed(game)) {
if (!game.getStack().isEmpty()) {
resolve(node, game);
}
else {
stepFinished = true;
}
}
if (game.gameOver(null)) {
val = GameStateEvaluator.evaluate(playerId, game);
}
else if (stepFinished) {
logger.debug(indent(node.depth) + "step finished");
int testScore = GameStateEvaluator.evaluate(playerId, game);
if (game.getActivePlayerId().equals(playerId)) {
if (testScore < currentScore) {
// if score at end of step is worse than original score don't check further
logger.debug(indent(node.depth) + "simulating -- abandoning check, no immediate benefit");
val = testScore;
}
else {
switch (game.getTurn().getStepType()) {
case PRECOMBAT_MAIN:
val = simulateCombat(game, node, alpha, beta, false);
break;
case POSTCOMBAT_MAIN:
val = simulateCounterAttack(game, node, alpha, beta);
break;
default:
val = GameStateEvaluator.evaluate(playerId, game);
break;
}
}
}
else {
if (game.getTurn().getStepType() == PhaseStep.DECLARE_ATTACKERS)
val = simulateBlockers(game, node, playerId, alpha, beta, true);
else
val = GameStateEvaluator.evaluate(playerId, game);
}
}
else if (node.getChildren().size() > 0) {
logger.debug(indent(node.depth) + "simulating -- trigger added children:" + node.getChildren().size());
val = minimaxAB(node, alpha, beta);
}
else {
val = simulatePriority(node, game, alpha, beta);
}
}
if (logger.isDebugEnabled())
logger.debug(indent(node.depth) + "returning -- score: " + val + " depth:" + node.depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
return val;
}