Search in sources :

Example 1 with CombatGroupSimulator

use of mage.player.ai.simulators.CombatGroupSimulator in project mage by magefree.

the class ComputerPlayer method simulateAttack.

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;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) CombatSimulator(mage.player.ai.simulators.CombatSimulator) CombatGroupSimulator(mage.player.ai.simulators.CombatGroupSimulator)

Example 2 with CombatGroupSimulator

use of mage.player.ai.simulators.CombatGroupSimulator in project mage by magefree.

the class ComputerPlayer method selectAttackers.

@Override
public void selectAttackers(Game game, UUID attackingPlayerId) {
    log.debug("selectAttackers");
    UUID opponentId = game.getCombat().getDefenders().iterator().next();
    Attackers attackers = getPotentialAttackers(game);
    List<Permanent> blockers = getOpponentBlockers(opponentId, game);
    List<Permanent> actualAttackers = new ArrayList<>();
    if (blockers.isEmpty()) {
        actualAttackers = attackers.getAttackers();
    } 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);
            }
        }
    }
    for (Permanent attacker : actualAttackers) {
        this.declareAttacker(attacker.getId(), opponentId, game, false);
    }
}
Also used : Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) CombatSimulator(mage.player.ai.simulators.CombatSimulator) CombatGroupSimulator(mage.player.ai.simulators.CombatGroupSimulator)

Aggregations

FilterPermanent (mage.filter.FilterPermanent)2 Permanent (mage.game.permanent.Permanent)2 CombatGroupSimulator (mage.player.ai.simulators.CombatGroupSimulator)2 CombatSimulator (mage.player.ai.simulators.CombatSimulator)2