Package mage.game

Examples of mage.game.Game


      for (Combat engagement: defender.addBlockers(game)) {
        if (alpha >= beta) {
          logger.fine("simulating -- pruning blockers");
          break;
        }
        Game sim = game.copy();
        for (CombatGroup group: engagement.getGroups()) {
          UUID attackerId = group.getAttackers().get(0);
          for (UUID blockerId: group.getBlockers()) {
            sim.getPlayer(defenderId).declareBlocker(blockerId, attackerId, sim);
          }
        }
        sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, playerId, playerId));
        SimulationNode newNode = new SimulationNode(sim, depth, defenderId);
        if (logger.isLoggable(Level.FINE))
          logger.fine("simulating block -- node#: " + SimulationNode.getCount());
        sim.checkStateAndTriggered();
        while (!sim.getStack().isEmpty()) {
          sim.getStack().resolve(sim);
          logger.fine("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.isGameOver()) {
          val = GameStateEvaluator.evaluate(playerId, sim);
        }
        else if (!counter) {
          val = simulatePostCombatMain(sim, newNode, depth-1, alpha, beta);
        }
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(sim, maxDepth, playerId);
      logger.fine("simulating actions");
      addActionsTimed(new FilterAbility());
      if (root.children.size() > 0) {
View Full Code Here

      SearchEffect effect = getSearchEffect((StackAbility) ability);
      if (effect != null && ability.getControllerId().equals(playerId)) {
        Target target = effect.getTarget();
        if (!target.doneChosing()) {
          for (UUID targetId: target.possibleTargets(ability.getSourceId(), ability.getControllerId(), game)) {
            Game sim = game.copy();
            StackAbility newAbility = (StackAbility) ability.copy();
            SearchEffect newEffect = getSearchEffect((StackAbility) newAbility);
            newEffect.getTarget().addTarget(targetId, newAbility, sim);
            sim.getStack().push(newAbility);
            SimulationNode newNode = new SimulationNode(sim, depth, ability.getControllerId());
            node.children.add(newNode);
            newNode.getTargets().add(targetId);
            logger.fine("simulating search -- node#: " + SimulationNode.getCount() + "for player: " + sim.getPlayer(ability.getControllerId()).getName());
          }
          return;
        }
      }
    }
View Full Code Here

    }
  }

  protected int addActions(SimulationNode node, FilterAbility filter, int depth, int alpha, int beta) {
    Game game = node.getGame();
    int val;
    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:" + (node.getPlayerId().equals(playerId)?"yes":"no"));
      if (allPassed(game)) {
        if (!game.getStack().isEmpty()) {
          resolve(node, depth, 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.fine("simulating -- abandoning current check, no immediate benefit");
//            return testScore;
//          }
          game.getPlayers().resetPassed();
          playNext(game, game.getActivePlayerId(), node);
        }
      }

      if (game.isGameOver()) {
        val = GameStateEvaluator.evaluate(playerId, game);
      }
      else if (node.getChildren().size() > 0) {
        //declared attackers or blockers or triggered abilities
        logger.fine("simulating -- attack/block/trigger added children:" + node.getChildren().size());
        val = minimaxAB(node, filter, depth-1, 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;

  }
View Full Code Here

    SimulationNode bestNode = null;
    List<Ability> allActions = currentPlayer.simulatePriority(game, filter);
    if (logger.isLoggable(Level.FINE))
      logger.fine("simulating -- adding " + allActions.size() + " children:" + allActions);
    for (Ability action: allActions) {
      Game sim = game.copy();
      if (sim.getPlayer(playerId).activateAbility((ActivatedAbility) action.copy(), sim)) {
        sim.applyEffects();
        if (!sim.isGameOver() && action.isUsesStack()) {
          // only pass if the last action uses the stack
          sim.getPlayer(currentPlayer.getId()).pass();
          sim.getPlayerList().getNext();
        }
        SimulationNode newNode = new SimulationNode(sim, action, depth, currentPlayer.getId());
        if (logger.isLoggable(Level.FINE))
          logger.fine("simulating -- node #:" + SimulationNode.getCount() + " actions:" + action);
        sim.checkStateAndTriggered();
        int val = addActions(newNode, filter, depth-1, alpha, beta);
        if (!currentPlayer.getId().equals(playerId)) {
          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);
                }
              }
              sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId));
              SimulationNode newNode = new SimulationNode(sim, node.getDepth()-1, activePlayerId);
              logger.fine("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(sim, node.getDepth()-1, defenderId);
                  logger.fine("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());
      SimulatedPlayer newPlayer = new SimulatedPlayer(copyPlayer.getId(), copyPlayer.getId().equals(playerId));
      newPlayer.restore(origPlayer);
      sim.getState().getPlayers().put(copyPlayer.getId(), newPlayer);
    }
    return sim;
  }
View Full Code Here

        Collections.shuffle(this.players, new Random());
    }

    @Override
    public void endGame() {
        Game game = getGame();
        for (MatchPlayer matchPlayer: this.players) {
            Player player = game.getPlayer(matchPlayer.getPlayer().getId());
            if (player != null) {
                // get the left time from player priority timer
                if (game.getPriorityTime() > 0) {
                    matchPlayer.setPriorityTimeLeft(player.getPriorityTimeLeft());
                }
                if (player.hasQuit()) {
                    matchPlayer.setQuit(true);
                }
                if (player.hasWon()) {
                    matchPlayer.addWin();
                }
            }
        }
        if (game.isADraw()) {
            addDraw();
        }
        checkIfMatchEnds();
        game.fireGameEndInfo();
        gamesInfo.add(createGameInfo(game));
    }
View Full Code Here

    }

    @Override
    public UUID getChooser() {
        UUID loserId = null;
        Game game = getGame();
        for (MatchPlayer player: this.players) {
            Player p = game.getPlayer(player.getPlayer().getId());
            if (p != null && p.hasLost() && !p.hasQuit()) {
                loserId = p.getId();
            }
        }
        return loserId;
View Full Code Here

        return true;
    }

    protected void calculateActions(Game game, NextAction action) {
        if (root == null) {
            Game sim = createMCTSGame(game);
            MCTSPlayer player = (MCTSPlayer) sim.getPlayer(playerId);
            player.setNextAction(action);
            root = new MCTSNode(sim);
        }
        applyMCTS(game, action);
        root = root.bestChild();
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.