Package mage.player.ai.simulators

Examples of mage.player.ai.simulators.CombatSimulator


    }
    else if (attackers.size() - blockers.size() >= game.getPlayer(opponentId).getLife()) {
      actualAttackers = attackers.getAttackers();
    }
    else {
      CombatSimulator combat = simulateAttack(attackers, blockers, opponentId, game);
      if (combat.rating > 2) {
        for (CombatGroupSimulator group: combat.groups) {
          this.declareAttacker(group.attackers.get(0).id, group.defenderId, game);
        }
      }
View Full Code Here


  public void selectBlockers(Game game) {
    logger.fine("selectBlockers");

    List<Permanent> blockers = getAvailableBlockers(game);

    CombatSimulator sim = simulateBlock(CombatSimulator.load(game), blockers, game);

    List<CombatGroup> groups = game.getCombat().getGroups();
    for (int i = 0; i< groups.size(); i++) {
      for (CreatureSimulator creature: sim.groups.get(i).blockers) {
        groups.get(i).addBlocker(creature.id, playerId, game);
View Full Code Here

  }

  protected CombatSimulator simulateAttack(Attackers attackers, List<Permanent> blockers, UUID opponentId, Game game) {
    logger.fine("simulateAttack");
    List<Permanent> attackersList = attackers.getAttackers();
    CombatSimulator best = new CombatSimulator();
    int bestResult = 0;
    //use binary digits to calculate powerset of attackers
    int powerElements = (int) Math.pow(2, attackersList.size());
    for (int i = 1; i < powerElements; i++) {
      String binary = Integer.toBinaryString(i);
      while(binary.length() < attackersList.size()) {
        binary = "0" + binary;
      }
      List<Permanent> trialAttackers = new ArrayList<Permanent>();
      for (int j = 0; j < attackersList.size(); j++) {
        if (binary.charAt(j) == '1')
          trialAttackers.add(attackersList.get(j));
      }
      CombatSimulator combat = new CombatSimulator();
      for (Permanent permanent: trialAttackers) {
        combat.groups.add(new CombatGroupSimulator(opponentId, Arrays.asList(permanent.getId()), new ArrayList<UUID>(), game));
      }
      CombatSimulator test = simulateBlock(combat, blockers, game);
      if (test.evaluate() > bestResult) {
        best = test;
        bestResult = test.evaluate();
      }
    }

    return best;
  }
View Full Code Here

    Copier<CombatSimulator> copier = new Copier<CombatSimulator>();
    for (Permanent blocker: blockers) {
      List<Permanent> subList = remove(blockers, blocker);
      for (int i = 0; i < numGroups; i++) {
        if (node.getData().groups.get(i).canBlock(blocker, game)) {
          CombatSimulator combat = copier.copy(node.getData());
          combat.groups.get(i).blockers.add(new CreatureSimulator(blocker));
          TreeNode<CombatSimulator> child = new TreeNode<CombatSimulator>(combat);
          node.addChild(child);
          addBlockSimulations(subList, child, game);
          combat.simulate();
        }
      }
    }
  }
View Full Code Here

    }
    return newList;
  }

  protected CombatSimulator getBestSimulation(TreeNode<CombatSimulator> simulations) {
    CombatSimulator best = simulations.getData();
    int bestResult = best.evaluate();
    for (TreeNode<CombatSimulator> node: simulations.getChildren()) {
      CombatSimulator bestSub = getBestSimulation(node);
      if (bestSub.evaluate() > bestResult) {
        best = node.getData();
        bestResult = best.evaluate();
      }
    }
    return best;
View Full Code Here

    }
    return best;
  }

  protected CombatSimulator getWorstSimulation(TreeNode<CombatSimulator> simulations) {
    CombatSimulator worst = simulations.getData();
    int worstResult = worst.evaluate();
    for (TreeNode<CombatSimulator> node: simulations.getChildren()) {
      CombatSimulator worstSub = getWorstSimulation(node);
      if (worstSub.evaluate() < worstResult) {
        worst = node.getData();
        worstResult = worst.evaluate();
      }
    }
    return worst;
View Full Code Here

        }
        else if (attackers.size() - blockers.size() >= game.getPlayer(opponentId).getLife()) {
            actualAttackers = attackers.getAttackers();
        }
        else {
            CombatSimulator combat = simulateAttack(attackers, blockers, opponentId, game);
            if (combat.rating > 2) {
                for (CombatGroupSimulator group: combat.groups) {
                    this.declareAttacker(group.attackers.get(0).id, group.defenderId, game, false);
                }
            }
View Full Code Here

    public void selectBlockers(Game game, UUID defendingPlayerId) {
        log.debug("selectBlockers");

        List<Permanent> blockers = getAvailableBlockers(game);

        CombatSimulator sim = simulateBlock(CombatSimulator.load(game), blockers, game);

        List<CombatGroup> groups = game.getCombat().getGroups();
        for (int i = 0; i< groups.size(); i++) {
            for (CreatureSimulator creature: sim.groups.get(i).blockers) {
                groups.get(i).addBlocker(creature.id, playerId, game);
View Full Code Here

    }

    protected CombatSimulator simulateAttack(Attackers attackers, List<Permanent> blockers, UUID opponentId, Game game) {
        log.debug("simulateAttack");
        List<Permanent> attackersList = attackers.getAttackers();
        CombatSimulator best = new CombatSimulator();
        int bestResult = 0;
        //use binary digits to calculate powerset of attackers
        int powerElements = (int) Math.pow(2, attackersList.size());
        for (int i = 1; i < powerElements; i++) {
            String binary = Integer.toBinaryString(i);
            while(binary.length() < attackersList.size()) {
                binary = "0" + binary;
            }
            List<Permanent> trialAttackers = new ArrayList<>();
            for (int j = 0; j < attackersList.size(); j++) {
                if (binary.charAt(j) == '1') {
                    trialAttackers.add(attackersList.get(j));
                }
            }
            CombatSimulator combat = new CombatSimulator();
            for (Permanent permanent: trialAttackers) {
                combat.groups.add(new CombatGroupSimulator(opponentId, Arrays.asList(permanent.getId()), new ArrayList<UUID>(), game));
            }
            CombatSimulator test = simulateBlock(combat, blockers, game);
            if (test.evaluate() > bestResult) {
                best = test;
                bestResult = test.evaluate();
            }
        }

        return best;
    }
View Full Code Here

        Copier<CombatSimulator> copier = new Copier<>();
        for (Permanent blocker: blockers) {
            List<Permanent> subList = remove(blockers, blocker);
            for (int i = 0; i < numGroups; i++) {
                if (node.getData().groups.get(i).canBlock(blocker, game)) {
                    CombatSimulator combat = copier.copy(node.getData());
                    combat.groups.get(i).blockers.add(new CreatureSimulator(blocker));
                    TreeNode<CombatSimulator> child = new TreeNode<>(combat);
                    node.addChild(child);
                    addBlockSimulations(subList, child, game);
                    combat.simulate();
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of mage.player.ai.simulators.CombatSimulator

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.