Search in sources :

Example 6 with Permanent

use of mage.game.permanent.Permanent 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 7 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class SimulatedPlayerMCTS method selectBlockers.

@Override
public void selectBlockers(Ability source, Game game, UUID defendingPlayerId) {
    // logger.info("select blockers");
    int numGroups = game.getCombat().getGroups().size();
    if (numGroups == 0) {
        return;
    }
    List<Permanent> blockers = getAvailableBlockers(game);
    for (Permanent blocker : blockers) {
        int check = RandomUtil.nextInt(numGroups + 1);
        if (check < numGroups) {
            CombatGroup group = game.getCombat().getGroups().get(check);
            if (!group.getAttackers().isEmpty()) {
                this.declareBlocker(this.getId(), blocker.getId(), group.getAttackers().get(0), game);
            }
        }
    }
    actionCount++;
}
Also used : Permanent(mage.game.permanent.Permanent) CombatGroup(mage.game.combat.CombatGroup)

Example 8 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class SimulatedPlayerMCTS method assignDamage.

@Override
public void assignDamage(int damage, List<UUID> targets, String singleTargetName, UUID attackerId, Ability source, Game game) {
    if (this.isHuman()) {
        int remainingDamage = damage;
        UUID targetId;
        int amount;
        while (remainingDamage > 0) {
            if (targets.size() == 1) {
                targetId = targets.get(0);
                amount = remainingDamage;
            } else {
                targetId = targets.get(RandomUtil.nextInt(targets.size()));
                amount = RandomUtil.nextInt(damage + 1);
            }
            Permanent permanent = game.getPermanent(targetId);
            if (permanent != null) {
                permanent.damage(amount, attackerId, source, game, false, true);
                remainingDamage -= amount;
            } else {
                Player player = game.getPlayer(targetId);
                if (player != null) {
                    player.damage(amount, attackerId, source, game);
                    remainingDamage -= amount;
                }
            }
            targets.remove(targetId);
        }
    } else {
        super.assignDamage(damage, targets, singleTargetName, attackerId, source, game);
    }
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Example 9 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class SimulatedPlayer method addBlocker.

protected void addBlocker(Game game, List<Permanent> blockers, Map<Integer, Combat> engagements) {
    if (blockers.isEmpty())
        return;
    int numGroups = game.getCombat().getGroups().size();
    // try to block each attacker with each potential blocker
    Permanent blocker = blockers.get(0);
    if (logger.isDebugEnabled())
        logger.debug("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().hashCode(), sim.getCombat()) != null)
                logger.debug("simulating -- found redundant block combination");
            // and recurse minus the used blocker
            addBlocker(sim, remaining, engagements);
        }
    }
    addBlocker(game, remaining, engagements);
}
Also used : Game(mage.game.Game) Permanent(mage.game.permanent.Permanent)

Example 10 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class SimulatedPlayer method addAttackers.

/*@Override
    public boolean playXMana(VariableManaCost cost, ManaCosts<ManaCost> costs, Game game) {
        //simulateVariableCosts method adds a generic mana cost for each option
        for (ManaCost manaCost: costs) {
            if (manaCost instanceof GenericManaCost) {
                cost.setPayment(manaCost.getPayment());
                logger.debug("simulating -- X = " + cost.getPayment().count());
                break;
            }
        }
        cost.setPaid();
        return true;
    }*/
public List<Combat> addAttackers(Game game) {
    Map<Integer, Combat> engagements = new HashMap<>();
    // useful only for two player games - will only attack first opponent
    UUID defenderId = game.getOpponents(playerId).iterator().next();
    List<Permanent> attackersList = super.getAvailableAttackers(defenderId, 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') {
                // makes it possible to UNDO a declared attacker with costs from e.g. Propaganda
                setStoredBookmark(sim.bookmarkState());
                if (!sim.getCombat().declareAttacker(attackersList.get(j).getId(), defenderId, playerId, sim)) {
                    sim.undo(playerId);
                }
            }
        }
        if (engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()) != null) {
            logger.debug("simulating -- found redundant attack combination");
        } else if (logger.isDebugEnabled()) {
            logger.debug("simulating -- attack:" + sim.getCombat().getGroups().size());
        }
    }
    return new ArrayList<>(engagements.values());
}
Also used : Game(mage.game.Game) Permanent(mage.game.permanent.Permanent) Combat(mage.game.combat.Combat)

Aggregations

Permanent (mage.game.permanent.Permanent)3269 Player (mage.players.Player)1706 UUID (java.util.UUID)665 TargetPermanent (mage.target.TargetPermanent)571 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)541 FixedTarget (mage.target.targetpointer.FixedTarget)496 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)467 FilterPermanent (mage.filter.FilterPermanent)466 Card (mage.cards.Card)425 MageObject (mage.MageObject)246 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)226 Target (mage.target.Target)225 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)217 ContinuousEffect (mage.abilities.effects.ContinuousEffect)207 Effect (mage.abilities.effects.Effect)183 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)179 Test (org.junit.Test)179 OneShotEffect (mage.abilities.effects.OneShotEffect)175 FilterCard (mage.filter.FilterCard)158 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)153