Package mage.game

Examples of mage.game.Game


        return new SimulatedPlayer(this);
    }

    public List<Ability> simulatePriority(Game game) {
        allActions = new ConcurrentLinkedQueue<Ability>();
        Game sim = game.copy();

        simulateOptions(sim, pass);

        ArrayList<Ability> list = new ArrayList<Ability>(allActions);
        //Collections.shuffle(list);
View Full Code Here


        List<Permanent> attackersList = super.getAvailableAttackers(defenderId, game);
        //use binary digits to calculate powerset of attackers
        int powerElements = (int) Math.pow(2, attackersList.size());
        StringBuilder binary = new StringBuilder();
        for (int i = powerElements - 1; i >= 0; i--) {
            Game sim = game.copy();
            binary.setLength(0);
            binary.append(Integer.toBinaryString(i));
            while (binary.length() < attackersList.size()) {
                binary.insert(0, "0");
            }
            for (int j = 0; j < attackersList.size(); j++) {
                if (binary.charAt(j) == '1')
                    sim.getCombat().declareAttacker(attackersList.get(j).getId(), defenderId, sim);
            }
            if (engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()) != null) {
                logger.debug("simulating -- found redundant attack combination");
            }
            else if (logger.isDebugEnabled()) {
                logger.debug("simulating -- attack:" + sim.getCombat().getGroups().size());
            }
        }
        return new ArrayList<Combat>(engagements.values());
    }
View Full Code Here

        Map<Integer, Combat> engagements = new HashMap<Integer, Combat>();
        int numGroups = game.getCombat().getGroups().size();
        if (numGroups == 0) return new ArrayList<Combat>();

        //add a node with no blockers
        Game sim = game.copy();
        engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat());
        sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, playerId, playerId));

        List<Permanent> blockers = getAvailableBlockers(game);
        addBlocker(game, blockers, engagements);

        return new ArrayList<Combat>(engagements.values());
View Full Code Here

        if (logger.isDebugEnabled())
            logger.debug("simulating -- block:" + blocker);
        List<Permanent> remaining = remove(blockers, blocker);
        for (int i = 0; i < numGroups; i++) {
            if (game.getCombat().getGroups().get(i).canBlock(blocker, game)) {
                Game sim = game.copy();
                sim.getCombat().getGroups().get(i).addBlocker(blocker.getId(), playerId, sim);
                if (engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()) != null)
                    logger.debug("simulating -- found redundant block combination");
                addBlocker(sim, remaining, engagements)// and recurse minus the used blocker
            }
        }
        addBlocker(game, remaining, engagements);
View Full Code Here

        }
        return true;
    }

    protected void addAbilityNode(SimulationNode parent, Ability ability, Game game) {
        Game sim = game.copy();
        sim.getStack().push(new StackAbility(ability, playerId));
        ability.activate(sim, false);
        sim.applyEffects();
        SimulationNode newNode = new SimulationNode(parent, sim, playerId);
        logger.debug(indent(newNode.getDepth()) + "simulating -- node #:" + SimulationNode.getCount() + " triggered ability option");
        for (Target target: ability.getTargets()) {
            for (UUID targetId: target.getTargets()) {
                newNode.getTargets().add(targetId);
View Full Code Here

    }

    protected void calculatePreCombatActions(Game game) {
        if (!getNextAction(game)) {
            currentScore = GameStateEvaluator.evaluate(playerId, game);
            Game sim = createSimulation(game);
            SimulationNode.resetCount();
            root = new SimulationNode(null, sim, playerId);
            logger.debug("simulating pre combat actions -----------------------------------------------------------------------------------------");

            if (!isTestMode)
View Full Code Here

    }

    protected void calculatePostCombatActions(Game game) {
        if (!getNextAction(game)) {
            currentScore = GameStateEvaluator.evaluate(playerId, game);
            Game sim = createSimulation(game);
            SimulationNode.resetCount();
            root = new SimulationNode(null, sim, playerId);
            logger.debug("simulating post combat actions ----------------------------------------------------------------------------------------");
            if (!isTestMode)
                addActionsTimed();
View Full Code Here

    @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;

    }
View Full Code Here

        for (Combat engagement: engagements) {
            if (alpha >= beta) {
                logger.debug(indent(node.depth) + "simulating -- pruning attackers");
                break;
            }
            Game sim = game.copy();
           
            for (CombatGroup group: engagement.getGroups()) {
                for (UUID attackId: group.getAttackers()) {
                    sim.getPlayer(attackerId).declareAttacker(attackId, defenderId, sim, false);
                }
            }
            sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, attackerId, attackerId));
            SimulationNode newNode = new SimulationNode(node, sim, attackerId);
            if (logger.isDebugEnabled()) {
                logger.debug(indent(node.depth) + "simulating attack for player:" + game.getPlayer(attackerId).getName());
            }
            sim.checkStateAndTriggered();
            while (!sim.getStack().isEmpty()) {
                sim.getStack().resolve(sim);
                logger.debug(indent(node.depth) + "resolving triggered abilities");
                sim.applyEffects();
            }
            sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
            Combat simCombat = sim.getCombat().copy();
            sim.getPhase().setStep(new DeclareBlockersStep());
            val = simulateCombat(sim, newNode, alpha, beta, counter);
            if (!attackerId.equals(playerId)) {
                if (val < beta) {
                    beta = val;
                    bestNode = newNode;
View Full Code Here

    }

    protected void calculateActions(Game game) {
        currentScore = GameStateEvaluator.evaluate(playerId, game);
        if (!getNextAction(game)) {
            Game sim = createSimulation(game);
            SimulationNode.resetCount();
            root = new SimulationNode(null, sim, playerId);
            logger.debug("simulating actions");
            if (!isTestMode)
                addActionsTimed();
View Full Code Here

TOP

Related Classes of mage.game.Game

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.