@Override
protected int addActions(SimulationNode node, FilterAbility filter, int depth, int alpha, int beta) {
boolean stepFinished = false;
int val;
Game game = node.getGame();
if (Thread.interrupted()) {
Thread.currentThread().interrupt();
logger.fine("interrupted");
return GameStateEvaluator.evaluate(playerId, game);
}
if (depth <= 0 || SimulationNode.nodeCount > maxNodes || game.isGameOver()) {
logger.fine("simulating -- reached end state");
val = GameStateEvaluator.evaluate(playerId, game);
}
else if (node.getChildren().size() > 0) {
logger.fine("simulating -- somthing added children:" + node.getChildren().size());
val = minimaxAB(node, filter, depth-1, alpha, beta);
}
else {
if (logger.isLoggable(Level.FINE))
logger.fine("simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(game.getPlayerList().get()).getName());
if (allPassed(game)) {
if (!game.getStack().isEmpty()) {
resolve(node, depth, game);
}
else {
stepFinished = true;
}
}
if (game.isGameOver()) {
val = GameStateEvaluator.evaluate(playerId, game);
}
else if (stepFinished) {
logger.fine("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.fine("simulating -- abandoning check, no immediate benefit");
val = testScore;
}
else {
switch (game.getTurn().getStepType()) {
case PRECOMBAT_MAIN:
val = simulateCombat(game, node, depth-1, alpha, beta, false);
break;
case POSTCOMBAT_MAIN:
val = simulateCounterAttack(game, node, depth-1, alpha, beta);
break;
default:
val = GameStateEvaluator.evaluate(playerId, game);
break;
}
}
}
else {
if (game.getTurn().getStepType() == PhaseStep.DECLARE_ATTACKERS)
val = simulateBlockers(game, node, playerId, depth-1, alpha, beta, true);
else
val = GameStateEvaluator.evaluate(playerId, game);
}
}
else if (node.getChildren().size() > 0) {
logger.fine("simulating -- trigger added children:" + node.getChildren().size());
val = minimaxAB(node, filter, depth, alpha, beta);
}
else {
val = simulatePriority(node, game, filter, depth, alpha, beta);
}
}
if (logger.isLoggable(Level.FINE))
logger.fine("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
return val;
}