Search in sources :

Example 1 with Permanent

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

the class HumanPlayer method selectBlockers.

@Override
public void selectBlockers(Ability source, Game game, UUID defendingPlayerId) {
    if (gameInCheckPlayableState(game)) {
        return;
    }
    FilterCreatureForCombatBlock filter = filterCreatureForCombatBlock.copy();
    filter.add(new ControllerIdPredicate(defendingPlayerId));
    // stop skip on any/zero permanents available
    int possibleBlockersCount = game.getBattlefield().count(filter, null, playerId, game);
    boolean canStopOnAny = possibleBlockersCount != 0 && getControllingPlayersUserData(game).getUserSkipPrioritySteps().isStopOnDeclareBlockersWithAnyPermanents();
    boolean canStopOnZero = possibleBlockersCount == 0 && getControllingPlayersUserData(game).getUserSkipPrioritySteps().isStopOnDeclareBlockersWithZeroPermanents();
    // skip declare blocker step
    // as opposed to declare attacker - it can be skipped by ANY skip button TODO: make same for declare attackers and rework skip buttons (normal and forced)
    boolean skipButtonActivated = passedAllTurns || passedUntilEndStepBeforeMyTurn || passedTurn || passedUntilEndOfTurn || passedUntilNextMain;
    if (skipButtonActivated && !canStopOnAny && !canStopOnZero) {
        return;
    }
    while (canRespond()) {
        updateGameStatePriority("selectBlockers", game);
        prepareForResponse(game);
        if (!isExecutingMacro()) {
            Map<String, Serializable> options = new HashMap<>();
            java.util.List<UUID> possibleBlockers = game.getBattlefield().getActivePermanents(filter, playerId, game).stream().map(p -> p.getId()).collect(Collectors.toList());
            options.put(Constants.Option.POSSIBLE_BLOCKERS, (Serializable) possibleBlockers);
            game.fireSelectEvent(playerId, "Select blockers", options);
        }
        waitForResponse(game);
        UUID responseId = getFixedResponseUUID(game);
        if (response.getBoolean() != null) {
            return;
        } else if (response.getInteger() != null) {
            return;
        } else if (responseId != null) {
            Permanent blocker = game.getPermanent(responseId);
            if (blocker != null) {
                boolean removeBlocker = false;
                // does not block yet and can block or can block more attackers
                if (filter.match(blocker, null, playerId, game)) {
                    selectCombatGroup(defendingPlayerId, blocker.getId(), game);
                } else if (filterBlock.match(blocker, null, playerId, game) && game.getStack().isEmpty()) {
                    removeBlocker = true;
                }
                if (removeBlocker) {
                    game.getCombat().removeBlocker(blocker.getId(), game);
                }
            }
        }
    }
}
Also used : RequirementEffect(mage.abilities.effects.RequirementEffect) FilterBlockingCreature(mage.filter.common.FilterBlockingCreature) Match(mage.game.match.Match) REQUEST_AUTO_ANSWER_RESET_ALL(mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL) Logger(org.apache.log4j.Logger) TapSourceCost(mage.abilities.costs.common.TapSourceCost) ManaCost(mage.abilities.costs.mana.ManaCost) mage.constants(mage.constants) Draft(mage.game.draft.Draft) mage.abilities(mage.abilities) Choice(mage.choices.Choice) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) StaticFilters(mage.filter.StaticFilters) GameLog(mage.util.GameLog) TargetAnyTarget(mage.target.common.TargetAnyTarget) mage.cards(mage.cards) FilterCreatureForCombatBlock(mage.filter.common.FilterCreatureForCombatBlock) CardUtil(mage.util.CardUtil) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) FilterCreatureForCombat(mage.filter.common.FilterCreatureForCombat) TargetDefender(mage.target.common.TargetDefender) List(java.util.List) Permanent(mage.game.permanent.Permanent) TargetAmount(mage.target.TargetAmount) Tournament(mage.game.tournament.Tournament) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Target(mage.target.Target) java.util(java.util) PlayerImpl(mage.players.PlayerImpl) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PlayerList(mage.players.PlayerList) DeclareAttackerEvent(mage.game.events.DeclareAttackerEvent) Player(mage.players.Player) ManaUtil(mage.util.ManaUtil) TargetCard(mage.target.TargetCard) FilterAttackingCreature(mage.filter.common.FilterAttackingCreature) MageObject(mage.MageObject) CombatGroup(mage.game.combat.CombatGroup) Spell(mage.game.stack.Spell) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) Deck(mage.cards.decks.Deck) TRIGGER_AUTO_ORDER_RESET_ALL(mage.constants.PlayerAction.TRIGGER_AUTO_ORDER_RESET_ALL) TargetAttackingCreature(mage.target.common.TargetAttackingCreature) java.awt(java.awt) VariableCost(mage.abilities.costs.VariableCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) ManaAbility(mage.abilities.mana.ManaAbility) ChoiceImpl(mage.choices.ChoiceImpl) GameImpl(mage.game.GameImpl) MessageToClient(mage.util.MessageToClient) HintUtils(mage.abilities.hint.HintUtils) TargetPermanent(mage.target.TargetPermanent) Serializable(java.io.Serializable) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FilterCreatureForCombatBlock(mage.filter.common.FilterCreatureForCombatBlock) java.util(java.util) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

Example 2 with Permanent

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

the class HumanPlayer method selectDefender.

/**
 * Selects a defender for an attacker and adds the attacker to combat
 *
 * @param defenders  - list of possible defender
 * @param attackerId - UUID of attacker
 * @param game
 * @return
 */
protected boolean selectDefender(Set<UUID> defenders, UUID attackerId, Game game) {
    boolean forcedToAttack = false;
    Set<UUID> possibleDefender = game.getCombat().getCreaturesForcedToAttack().get(attackerId);
    if (possibleDefender != null) {
        forcedToAttack = true;
    }
    if (possibleDefender == null || possibleDefender.isEmpty()) {
        possibleDefender = defenders;
    }
    if (possibleDefender.size() == 1) {
        declareAttacker(attackerId, possibleDefender.iterator().next(), game, true);
        return true;
    } else {
        TargetDefender target = new TargetDefender(possibleDefender, attackerId);
        if (forcedToAttack) {
            StringBuilder sb = new StringBuilder(target.getTargetName());
            Permanent attacker = game.getPermanent(attackerId);
            if (attacker != null) {
                sb.append(" (").append(attacker.getName()).append(')');
                target.setTargetName(sb.toString());
            }
        }
        if (chooseTarget(Outcome.Damage, target, null, game)) {
            UUID defenderId = getFixedResponseUUID(game);
            declareAttacker(attackerId, defenderId, game, true);
            return true;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetDefender(mage.target.common.TargetDefender)

Example 3 with Permanent

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

the class ComputerPlayer method findBestPermanentTargets.

protected void findBestPermanentTargets(Outcome outcome, UUID abilityControllerId, UUID sourceId, FilterPermanent filter, Game game, Target target, List<Permanent> goodList, List<Permanent> badList, List<Permanent> allList) {
    // searching for most valuable/powerfull permanents
    goodList.clear();
    badList.clear();
    allList.clear();
    List<UUID> usedTargets = target.getTargets();
    // search all
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, abilityControllerId, sourceId, game)) {
        if (usedTargets.contains(permanent.getId())) {
            continue;
        }
        if (outcome.isGood()) {
            // good effect
            if (permanent.isControlledBy(abilityControllerId)) {
                goodList.add(permanent);
            } else {
                badList.add(permanent);
            }
        } else {
            // bad effect
            if (permanent.isControlledBy(abilityControllerId)) {
                badList.add(permanent);
            } else {
                goodList.add(permanent);
            }
        }
    }
    // sort from tiny to big (more valuable)
    PermanentComparator comparator = new PermanentComparator(game);
    goodList.sort(comparator);
    badList.sort(comparator);
    // most valueable goes first in good list
    Collections.reverse(goodList);
    // most weakest goes first in bad list (no need to reverse)
    // Collections.reverse(badList);
    allList.addAll(goodList);
    allList.addAll(badList);
    // "can target all mode" don't need your/opponent lists -- all targets goes with same value
    if (outcome.isCanTargetAll()) {
        // bad sort
        allList.sort(comparator);
        if (outcome.isGood()) {
            // good sort
            Collections.reverse(allList);
        }
        goodList.clear();
        goodList.addAll(allList);
        badList.clear();
        badList.addAll(allList);
    }
}
Also used : Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent)

Example 4 with Permanent

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

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

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