Package mage.game

Examples of mage.game.Game


            logger.fatal("Error starting game", ex);
            if (table != null) {
                TableManager.getInstance().removeTable(table.getId());
            }
            if (match != null) {
                Game game = match.getGame();
                if (game != null) {
                    GameManager.getInstance().removeGame(game.getId());
                }
            }
        }
    }
View Full Code Here


     *
     * @return true if table can be closed
     */
    public boolean endGameAndStartNextGame() {
        // get player that chooses who goes first
        Game game = match.getGame();
        if (game == null) {
            return true;
        }
        UUID choosingPlayerId = match.getChooser();
        match.endGame();
        if (ConfigSettings.getInstance().isSaveGameActivated() && !game.isSimulation()) {
            if (GameManager.getInstance().saveGame(game.getId())) {
                match.setReplayAvailable(true);
            }
        }
        GameManager.getInstance().removeGame(game.getId());
        try {
            if (!match.hasEnded()) {
                if (match.getGame().getGameType().isSideboardingAllowed()) {
                    sideboard();
                }
View Full Code Here

        try{
            InputStream file = new FileInputStream("saved/" + gameId.toString() + ".game");
            InputStream buffer = new BufferedInputStream(file);
            ObjectInput input = new CopierObjectInputStream(Main.classLoader, new GZIPInputStream(buffer));
            try {
                Game loadGame = (Game)input.readObject();
                GameStates states = (GameStates)input.readObject();
                loadGame.loadGameStates(states);
                return loadGame;
            }
            finally {
                input.close();
            }
View Full Code Here

            tableController.cleanUp()// deletes the table chat and references to users          
           
            Table table = tables.get(tableId);
            tables.remove(tableId);
            Match match = table.getMatch();
            Game game = null;
            if (match != null) {
                game = match.getGame();
                if (game != null && !game.hasEnded()) {
                    game.end();
                }               
            }
                       
            // If table is not finished, the table has to be removed completly because it's not a normal state (if finished it will be removed in GamesRoomImpl.Update())
            if (!table.getState().equals(TableState.FINISHED)) {
                if (game != null) {
                    GameManager.getInstance().removeGame(game.getId());
                }
                GamesRoomManager.getInstance().removeTable(tableId);
            }
           
        }
View Full Code Here

            for (Combat engagement: defender.addBlockers(game)) {
                if (alpha >= beta) {
                    logger.debug(indent(node.depth) + "simulating -- pruning blockers");
                    break;
                }
                Game sim = game.copy();
                for (CombatGroup group: engagement.getGroups()) {
                    if (group.getAttackers().size() > 0) {
                        UUID attackerId = group.getAttackers().get(0);
                        for (UUID blockerId: group.getBlockers()) {
                            sim.getPlayer(defenderId).declareBlocker(defenderId, blockerId, attackerId, sim);
                        }
                    }
                }
                sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, defenderId, defenderId));
                SimulationNode newNode = new SimulationNode(node, sim, defenderId);
                if (logger.isDebugEnabled()) {
                    logger.debug(indent(node.depth) + "simulating block for player:" + game.getPlayer(defenderId).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_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
                Combat simCombat = sim.getCombat().copy();
                finishCombat(sim);
                if (sim.gameOver(null)) {
                    val = GameStateEvaluator.evaluate(playerId, sim);
                }
                else if (!counter) {
                    val = simulatePostCombatMain(sim, newNode, alpha, beta);
                }
View Full Code Here

            task.cancel(true);
        }
    }

    protected int addActions(SimulationNode node, int alpha, int beta) {
        Game game = node.getGame();
        if (Thread.interrupted()) {
            Thread.currentThread().interrupt();
            logger.debug(indent(node.depth) + "interrupted");
            return GameStateEvaluator.evaluate(playerId, game);
        }
        int val;
        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:" + (node.getPlayerId().equals(playerId)?"yes":"no"));
            if (allPassed(game)) {
                if (!game.getStack().isEmpty()) {
                    resolve(node, game);
                }
                else {
//                    int testScore = GameStateEvaluator.evaluate(playerId, game);
//                    if (testScore < currentScore) {
//                        // if score at end of step is worse than original score don't check any further
//                        logger.debug("simulating -- abandoning current check, no immediate benefit");
//                        return testScore;
//                    }
                    game.getPlayers().resetPassed();
                    playNext(game, game.getActivePlayerId(), node);
                }
            }

            if (game.gameOver(null)) {
                val = GameStateEvaluator.evaluate(playerId, game);
            }
            else if (node.getChildren().size() > 0) {
                //declared attackers or blockers or triggered abilities
                logger.debug(indent(node.depth) + "simulating -- attack/block/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

            if (Thread.interrupted()) {
                Thread.currentThread().interrupt();
                logger.debug(indent(node.depth) + "interrupted");
                break;
            }
            Game sim = game.copy();
            if (sim.getPlayer(currentPlayer.getId()).activateAbility((ActivatedAbility) action.copy(), sim)) {
                sim.applyEffects();
                if (checkForUselessAction(sim, node, action, currentPlayer.getId())) {
                    logger.debug(indent(node.depth) + "found useless action: " + action);
                    continue;
                }
                if (!sim.gameOver(null) && action.isUsesStack()) {
                    // only pass if the last action uses the stack
                    sim.getPlayer(currentPlayer.getId()).pass(game);
                    sim.getPlayerList().getNext();
                }
                SimulationNode newNode = new SimulationNode(node, sim, action, currentPlayer.getId());
                if (logger.isDebugEnabled())
                    logger.debug(indent(newNode.depth) + "simulating -- node #:" + SimulationNode.getCount() + " actions:" + action);
                sim.checkStateAndTriggered();
                int val = addActions(newNode, alpha, beta);
                if (!isSimulatedPlayer) {
                    if (val < beta) {
                        beta = val;
                        bestNode = newNode;
View Full Code Here

            if (!game.getStep().skipStep(game, game.getActivePlayerId())) {
                if (game.getTurn().getStepType() == PhaseStep.DECLARE_ATTACKERS) {
                    game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE, null, null, activePlayerId));
                    if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, activePlayerId, activePlayerId))) {
                        for (Combat engagement: ((SimulatedPlayer)game.getPlayer(activePlayerId)).addAttackers(game)) {
                            Game sim = game.copy();
                            UUID defenderId = game.getOpponents(playerId).iterator().next();
                            for (CombatGroup group: engagement.getGroups()) {
                                for (UUID attackerId: group.getAttackers()) {
                                    sim.getPlayer(activePlayerId).declareAttacker(attackerId, defenderId, sim, false);
                                }
                            }
                            sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId));
                            SimulationNode newNode = new SimulationNode(node, sim, activePlayerId);
                            logger.debug(indent(node.depth) + "simulating -- node #:" + SimulationNode.getCount() + " declare attakers");
                            newNode.setCombat(sim.getCombat());
                            node.children.add(newNode);
                        }
                    }
                }
                else if (game.getTurn().getStepType() == PhaseStep.DECLARE_BLOCKERS) {
                    game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_PRE, null, null, activePlayerId));
                    if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_BLOCKERS, activePlayerId, activePlayerId))) {
                        for (UUID defenderId: game.getCombat().getDefenders()) {
                            //check if defender is being attacked
                            if (game.getCombat().isAttacked(defenderId, game)) {
                                for (Combat engagement: ((SimulatedPlayer)game.getPlayer(defenderId)).addBlockers(game)) {
                                    Game sim = game.copy();
                                    for (CombatGroup group: engagement.getGroups()) {
                                        for (UUID blockerId: group.getBlockers()) {
                                            group.addBlocker(blockerId, defenderId, sim);
                                        }
                                    }
                                    sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, playerId, playerId));
                                    SimulationNode newNode = new SimulationNode(node, sim, defenderId);
                                    logger.debug(indent(node.depth) + "simulating -- node #:" + SimulationNode.getCount() + " declare blockers");
                                    newNode.setCombat(sim.getCombat());
                                    node.children.add(newNode);
                                }
                            }
                        }
                    }
View Full Code Here

     *
     * @param game
     * @return a new game object with simulated players
     */
    protected Game createSimulation(Game game) {
        Game sim = game.copy();

        for (Player copyPlayer: sim.getState().getPlayers().values()) {
            Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId()).copy();
            SimulatedPlayer newPlayer = new SimulatedPlayer(copyPlayer.getId(), copyPlayer.getId().equals(playerId), maxDepth);
            newPlayer.restore(origPlayer);
            sim.getState().getPlayers().put(copyPlayer.getId(), newPlayer);
        }
        sim.setSimulation(true);
        return sim;
    }
View Full Code Here

            return false;
        SimulationNode test = node.getParent();
        if (test == null)
            return false;
        if (action.isUsesStack()) {
            Game testSim = sim.copy();
            StackObject ability = testSim.getStack().pop();
            ability.resolve(testSim);
            testSim.applyEffects();
            currentVal = GameStateEvaluator.evaluate(playerId, testSim, true);
        }
        else {
            currentVal = GameStateEvaluator.evaluate(playerId, sim, true);
        }
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.