public boolean resumePlay(Game game, PhaseStep stepType, boolean wasPaused) { if (game.isPaused() || game.checkIfGameIsOver()) { return false; while (it.hasNext()) { step = it.next(); if (game.isPaused() || game.checkIfGameIsOver()) { return false; if (game.isPaused() || game.checkIfGameIsOver()) { return false;
public MCTSNode(UUID targetPlayer, Game game) { this.targetPlayer = targetPlayer; this.game = game; this.stateValue = game.getState().getValue(game, targetPlayer); this.fullStateValue = game.getState().getValue(true, game); this.terminal = game.checkIfGameIsOver(); setPlayer(); nodeCount = 1; // logger.info(this.stateValue); }
protected MCTSNode(MCTSNode parent, Game game, Combat combat) { this.targetPlayer = parent.targetPlayer; this.game = game; this.combat = combat; this.stateValue = game.getState().getValue(game, targetPlayer); this.fullStateValue = game.getState().getValue(true, game); this.terminal = game.checkIfGameIsOver(); this.parent = parent; setPlayer(); nodeCount++; // logger.info(this.stateValue); }
protected MCTSNode(MCTSNode parent, Game game, Ability action) { this.targetPlayer = parent.targetPlayer; this.game = game; this.stateValue = game.getState().getValue(game, targetPlayer); this.fullStateValue = game.getState().getValue(true, game); this.terminal = game.checkIfGameIsOver(); this.parent = parent; this.action = action; setPlayer(); nodeCount++; // logger.info(this.stateValue); }
protected void playStep(Game game) { if (!currentStep.skipStep(game, activePlayerId)) { game.getState().increaseStepNum(); prePriority(game, activePlayerId); if (!game.isPaused() && !game.checkIfGameIsOver() && !game.executingRollback()) { currentStep.priority(game, activePlayerId, false); if (game.executingRollback()) { return; } } if (!game.isPaused() && !game.checkIfGameIsOver() && !game.executingRollback()) { postPriority(game, activePlayerId); } } }
public static int evaluate(UUID playerId, Game game) { Player player = game.getPlayer(playerId); Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next()); if (game.checkIfGameIsOver()) { if (player.hasLost() || opponent.hasWon()) {
protected void simulateToEnd(Game game) { if (Thread.interrupted()) { Thread.currentThread().interrupt(); logger.debug("interrupted"); return; } if (!game.checkIfGameIsOver()) { game.getTurn().getPhase().endPhase(game, game.getActivePlayerId()); game.getTurn().setPhase(new EndPhase()); if (game.getTurn().getPhase().beginPhase(game, game.getActivePlayerId())) { simulateStep(game, new EndStep()); simulateStep(game, new CleanupStep()); } } }
protected void resumeStep(Game game, boolean wasPaused) { boolean resuming = true; if (currentStep == null || currentStep.getStepPart() == null) { game.end(); return; } switch (currentStep.getStepPart()) { case PRE: if (wasPaused) { currentStep.resumeBeginStep(game, activePlayerId); resuming = false; } else { prePriority(game, activePlayerId); } case PRIORITY: if (!game.isPaused() && !game.checkIfGameIsOver()) { currentStep.priority(game, activePlayerId, resuming); } case POST: if (!game.isPaused() && !game.checkIfGameIsOver()) { postPriority(game, activePlayerId); } } }
protected void simulateStep(Game game, Step step) { if (Thread.interrupted()) { Thread.currentThread().interrupt(); logger.debug("interrupted"); return; } if (!game.checkIfGameIsOver()) { game.getPhase().setStep(step); if (!step.skipStep(game, game.getActivePlayerId())) { step.beginStep(game, game.getActivePlayerId()); game.checkStateAndTriggered(); while (!game.getStack().isEmpty()) { game.getStack().resolve(game); game.applyEffects(); } step.endStep(game, game.getActivePlayerId()); } } }
if (node.depth > maxDepth || game.checkIfGameIsOver()) { logger.debug(indent(node.depth) + "simulating -- reached end state"); val = GameStateEvaluator.evaluate(playerId, game); if (game.checkIfGameIsOver()) { val = GameStateEvaluator.evaluate(playerId, game);
public boolean play(Game game, UUID activePlayerId) { if (game.isPaused() || game.checkIfGameIsOver()) { return false; if (game.isPaused() || game.checkIfGameIsOver()) { return false; if (game.isPaused() || game.checkIfGameIsOver()) { return false;
return GameStateEvaluator.evaluate(playerId, game); if (node.depth > maxDepth || game.checkIfGameIsOver()) { logger.debug(indent(node.depth) + "simulating -- reached end state"); val = GameStateEvaluator.evaluate(playerId, game); if (game.checkIfGameIsOver()) { val = GameStateEvaluator.evaluate(playerId, game);
if (game.isPaused() || game.checkIfGameIsOver()) { return;
protected int simulateCounterAttack(Game game, SimulationNode node, int alpha, int beta) { if (Thread.interrupted()) { Thread.currentThread().interrupt(); logger.debug(indent(node.depth) + "interrupted"); return GameStateEvaluator.evaluate(playerId, game); } Integer val = null; if (!game.checkIfGameIsOver()) { logger.debug(indent(node.depth) + "simulating -- ending turn"); simulateToEnd(game); game.getState().setActivePlayerId(game.getState().getPlayerList(game.getActivePlayerId()).getNext()); logger.debug(indent(node.depth) + "simulating -- counter attack for player " + game.getPlayer(game.getActivePlayerId()).getName()); game.getTurn().setPhase(new BeginningPhase()); if (game.getPhase().beginPhase(game, game.getActivePlayerId())) { simulateStep(game, new UntapStep()); simulateStep(game, new UpkeepStep()); simulateStep(game, new DrawStep()); game.getPhase().endPhase(game, game.getActivePlayerId()); } //TODO: calculate opponent actions before combat val = simulateCombat(game, node, alpha, beta, true); if (logger.isDebugEnabled()) logger.debug(indent(node.depth) + "returning -- counter attack score: " + val + " depth:" + node.depth + " for player:" + game.getPlayer(node.getPlayerId()).getName()); } if (val == null) val = GameStateEvaluator.evaluate(playerId, game); return val; }
Combat simCombat = sim.getCombat().copy(); finishCombat(sim); if (sim.checkIfGameIsOver()) { val = GameStateEvaluator.evaluate(playerId, sim);
public static int evaluate(UUID playerId, Game game, boolean ignoreTapped) { Player player = game.getPlayer(playerId); Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next()); if (game.checkIfGameIsOver()) { if (player.hasLost() || opponent.hasWon()) { return LOSE_SCORE; } if (opponent.hasLost() || player.hasWon()) { return WIN_SCORE; } } int lifeScore = (player.getLife() - opponent.getLife()) * LIFE_FACTOR; int poisonScore = (opponent.getCounters().getCount(CounterType.POISON) - player.getCounters().getCount(CounterType.POISON)) * LIFE_FACTOR * 2; int permanentScore = 0; for (Permanent permanent : game.getBattlefield().getAllActivePermanents(playerId)) { permanentScore += evaluatePermanent(permanent, game, ignoreTapped); } for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponent.getId())) { permanentScore -= evaluatePermanent(permanent, game, ignoreTapped); } permanentScore *= PERMANENT_FACTOR; int handScore = 0; handScore = player.getHand().size() - opponent.getHand().size(); handScore *= HAND_FACTOR; int score = lifeScore + poisonScore + permanentScore + handScore; if (logger.isDebugEnabled()) { logger.debug("game state for player " + player.getName() + " evaluated to- lifeScore:" + lifeScore + " permanentScore:" + permanentScore + " handScore:" + handScore + " total:" + score); } return score; }
public void selectAttackers(Game game) { if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, attackingPlayerId, attackingPlayerId))) { Player player = game.getPlayer(attackingPlayerId); //20101001 - 508.1d game.getCombat().checkAttackRequirements(player, game); boolean firstTime = true; do { if (!firstTime || !game.getPlayer(game.getActivePlayerId()).getAvailableAttackers(game).isEmpty()) { player.selectAttackers(game, attackingPlayerId); } firstTime = false; if (game.isPaused() || game.checkIfGameIsOver() || game.executingRollback()) { return; } // because of possible undo during declare attackers it's neccassary to call here the methods with "game.getCombat()." to get the current combat object!!! // I don't like it too - it has to be redesigned } while (!game.getCombat().checkAttackRestrictions(player, game)); game.getCombat().resumeSelectAttackers(game); } }
public int evaluateState() { Player opponent = game.getPlayer(game.getOpponents(player.getId()).iterator().next()); if (game.checkIfGameIsOver()) { if (player.hasLost() || opponent.hasWon()) { return Integer.MIN_VALUE; } if (opponent.hasLost() || player.hasWon()) { return Integer.MAX_VALUE; } } int value = player.getLife(); value -= opponent.getLife(); PermanentEvaluator evaluator = new PermanentEvaluator(); for (Permanent permanent: game.getBattlefield().getAllActivePermanents(player.getId())) { value += evaluator.evaluate(permanent, game); } for (Permanent permanent: game.getBattlefield().getAllActivePermanents(player.getId())) { value -= evaluator.evaluate(permanent, game); } value += player.getHand().size(); value -= opponent.getHand().size(); return value; }
activePlayer.becomesActivePlayer(); this.setDeclareAttackersStepStarted(false); if (game.isPaused() || game.checkIfGameIsOver()) { return false; game.getPlayer(activePlayer.getId()).beginTurn(game); for (Phase phase : phases) { if (game.isPaused() || game.checkIfGameIsOver()) { return false;
if (game.isPaused() || game.checkIfGameIsOver() || game.executingRollback()) { return;