Search in sources :

Example 1 with CombatSimulator

use of mage.player.ai.simulators.CombatSimulator 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 CombatSimulator

use of mage.player.ai.simulators.CombatSimulator 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)

Example 3 with CombatSimulator

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

the class ComputerPlayer method selectBlockers.

@Override
public void selectBlockers(Ability source, 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);
        }
    }
}
Also used : Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) CombatSimulator(mage.player.ai.simulators.CombatSimulator) CreatureSimulator(mage.player.ai.simulators.CreatureSimulator) CombatGroup(mage.game.combat.CombatGroup)

Example 4 with CombatSimulator

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

the class ComputerPlayer method getWorstSimulation.

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;
}
Also used : CombatSimulator(mage.player.ai.simulators.CombatSimulator)

Example 5 with CombatSimulator

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

the class ComputerPlayer method getBestSimulation.

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;
}
Also used : CombatSimulator(mage.player.ai.simulators.CombatSimulator)

Aggregations

CombatSimulator (mage.player.ai.simulators.CombatSimulator)6 FilterPermanent (mage.filter.FilterPermanent)4 Permanent (mage.game.permanent.Permanent)4 CombatGroupSimulator (mage.player.ai.simulators.CombatGroupSimulator)2 CreatureSimulator (mage.player.ai.simulators.CreatureSimulator)2 CombatGroup (mage.game.combat.CombatGroup)1