Package mage.game

Examples of mage.game.Game


  private GameFactory() {}

  public Game createGame(String gameType, MultiplayerAttackOption attackOption, RangeOfInfluence range) {

    Game game;
    Constructor<Game> con;
    try {
      con = games.get(gameType).getConstructor(new Class[]{MultiplayerAttackOption.class, RangeOfInfluence.class});
      game = con.newInstance(new Object[] {attackOption, range});
    } catch (Exception ex) {
      logger.log(Level.SEVERE, null, ex);
      return null;
    }
    logger.info("Game created: " + game.getId().toString());

    return game;
  }
View Full Code Here


    return new SimulatedPlayer(this);
  }

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

    simulateOptions(sim, pass);

    ArrayList<Ability> list = new ArrayList<Ability>(allActions);
View Full Code Here

    List<Permanent> attackersList = super.getAvailableAttackers(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(sim), sim.getCombat()) != null) {
        logger.fine("simulating -- found redundant attack combination");
      }
      else if (logger.isLoggable(Level.FINE)) {
        logger.fine("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(sim), 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.isLoggable(Level.FINE))
      logger.fine("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(sim), sim.getCombat()) != null)
          logger.fine("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, int depth, Game game) {
    Game sim = game.copy();
    sim.getStack().push(new StackAbility(ability, playerId));
    ability.activate(sim, false);
    sim.applyEffects();
    SimulationNode newNode = new SimulationNode(sim, depth, playerId);
    logger.fine("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(sim, maxDepth, playerId);
      logger.fine("simulating pre combat actions -----------------------------------------------------------------------------------------");

      addActionsTimed(new FilterAbility());
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(sim, maxDepth, playerId);
      logger.fine("simulating post combat actions ----------------------------------------------------------------------------------------");
      addActionsTimed(new FilterAbility());
      if (root.children.size() > 0) {
View Full Code Here

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

  }
View Full Code Here

    for (Combat engagement: attacker.addAttackers(game)) {
      if (alpha >= beta) {
        logger.fine("simulating -- pruning attackers");
        break;
      }
      Game sim = game.copy();
      UUID defenderId = game.getOpponents(playerId).iterator().next();
      for (CombatGroup group: engagement.getGroups()) {
        for (UUID attackId: group.getAttackers()) {
          sim.getPlayer(attackerId).declareAttacker(attackId, defenderId, sim);
        }
      }
      sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId));
      SimulationNode newNode = new SimulationNode(sim, depth, game.getActivePlayerId());
      if (logger.isLoggable(Level.FINE))
        logger.fine("simulating attack -- 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_ATTACKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
      Combat simCombat = sim.getCombat().copy();
      sim.getPhase().setStep(new DeclareBlockersStep());
      val = simulateCombat(sim, newNode, depth-1, alpha, beta, counter);
      if (!attackerId.equals(playerId)) {
        if (val < beta) {
          beta = val;
          bestNode = newNode;
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.