Search in sources :

Example 51 with Game

use of mage.game.Game in project mage by magefree.

the class CombatUtil method willItSurvive.

public static SurviveInfo willItSurvive(Game game, UUID attackingPlayerId, UUID defendingPlayerId, Permanent attacker, Permanent blocker) {
    Game sim = game.copy();
    Combat combat = sim.getCombat();
    combat.setAttacker(attackingPlayerId);
    combat.setDefenders(sim);
    if (blocker == null || attacker == null || sim.getPlayer(defendingPlayerId) == null) {
        return null;
    }
    sim.getPlayer(defendingPlayerId).declareBlocker(defendingPlayerId, blocker.getId(), attacker.getId(), sim);
    sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, defendingPlayerId, defendingPlayerId));
    sim.checkStateAndTriggered();
    while (!sim.getStack().isEmpty()) {
        sim.getStack().resolve(sim);
        sim.applyEffects();
    }
    sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
    simulateStep(sim, new FirstCombatDamageStep());
    simulateStep(sim, new CombatDamageStep());
    simulateStep(sim, new EndOfCombatStep());
    // sim.checkStateAndTriggered();
    while (!sim.getStack().isEmpty()) {
        sim.getStack().resolve(sim);
        sim.applyEffects();
    }
    return new SurviveInfo(!sim.getBattlefield().containsPermanent(attacker.getId()), !sim.getBattlefield().containsPermanent(blocker.getId()));
}
Also used : FirstCombatDamageStep(mage.game.turn.FirstCombatDamageStep) CombatDamageStep(mage.game.turn.CombatDamageStep) Game(mage.game.Game) EndOfCombatStep(mage.game.turn.EndOfCombatStep) Combat(mage.game.combat.Combat) FirstCombatDamageStep(mage.game.turn.FirstCombatDamageStep)

Example 52 with Game

use of mage.game.Game in project mage by magefree.

the class SimulatedPlayer2 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);
    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 53 with Game

use of mage.game.Game in project mage by magefree.

the class SimulatedPlayer2 method simulatePriority.

public List<Ability> simulatePriority(Game game) {
    allActions = new ConcurrentLinkedQueue<>();
    Game sim = game.copy();
    sim.setSimulation(true);
    forced = false;
    simulateOptions(sim);
    List<Ability> list = new ArrayList<>(allActions);
    Collections.reverse(list);
    if (!forced) {
        list.add(pass);
    }
    if (logger.isTraceEnabled()) {
        for (Ability a : allActions) {
            logger.info("ability==" + a);
            if (!a.getTargets().isEmpty()) {
                MageObject mageObject = game.getObject(a.getFirstTarget());
                if (mageObject != null) {
                    logger.info("   target=" + mageObject.getName());
                } else {
                    Player player = game.getPlayer(a.getFirstTarget());
                    if (player != null) {
                        logger.info("   target=" + player.getName());
                    }
                }
            }
        }
    }
    return list;
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) Game(mage.game.Game) MageObject(mage.MageObject)

Example 54 with Game

use of mage.game.Game in project mage by magefree.

the class ComputerPlayer6 method checkForRepeatedAction.

private boolean checkForRepeatedAction(Game sim, SimulationNode2 node, Ability action, UUID playerId) {
    // pass or casting two times a spell multiple times on hand is ok
    if (action instanceof PassAbility || action instanceof SpellAbility || action.getAbilityType() == AbilityType.MANA) {
        return false;
    }
    int newVal = GameStateEvaluator2.evaluate(playerId, sim).getTotalScore();
    SimulationNode2 test = node.getParent();
    while (test != null) {
        if (test.getPlayerId().equals(playerId)) {
            if (test.getAbilities() != null && test.getAbilities().size() == 1) {
                if (action.toString().equals(test.getAbilities().get(0).toString())) {
                    if (test.getParent() != null) {
                        Game prevGame = node.getGame();
                        if (prevGame != null) {
                            int oldVal = GameStateEvaluator2.evaluate(playerId, prevGame).getTotalScore();
                            if (oldVal >= newVal) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
        test = test.getParent();
    }
    return false;
}
Also used : PassAbility(mage.abilities.common.PassAbility) Game(mage.game.Game) SpellAbility(mage.abilities.SpellAbility)

Example 55 with Game

use of mage.game.Game in project mage by magefree.

the class ComputerPlayer6 method resolve.

protected void resolve(SimulationNode2 node, int depth, Game game) {
    StackObject stackObject = game.getStack().getFirst();
    if (stackObject instanceof StackAbility) {
        // AI hint for search effects (calc all possible cards for best score)
        SearchEffect effect = getSearchEffect((StackAbility) stackObject);
        if (effect != null && stackObject.getControllerId().equals(playerId)) {
            Target target = effect.getTarget();
            if (!target.doneChosing()) {
                for (UUID targetId : target.possibleTargets(stackObject.getSourceId(), stackObject.getControllerId(), game)) {
                    Game sim = game.copy();
                    StackAbility newAbility = (StackAbility) stackObject.copy();
                    SearchEffect newEffect = getSearchEffect(newAbility);
                    newEffect.getTarget().addTarget(targetId, newAbility, sim);
                    sim.getStack().push(newAbility);
                    SimulationNode2 newNode = new SimulationNode2(node, sim, depth, stackObject.getControllerId());
                    node.children.add(newNode);
                    newNode.getTargets().add(targetId);
                    logger.trace("Sim search -- node#: " + SimulationNode2.getCount() + " for player: " + sim.getPlayer(stackObject.getControllerId()).getName());
                }
                return;
            }
        }
    }
    stackObject.resolve(game);
    if (stackObject instanceof StackAbility) {
        game.getStack().remove(stackObject, game);
    }
    game.applyEffects();
    game.getPlayers().resetPassed();
    game.getPlayerList().setCurrent(game.getActivePlayerId());
}
Also used : SearchEffect(mage.abilities.effects.SearchEffect) Target(mage.target.Target) Game(mage.game.Game) StackObject(mage.game.stack.StackObject) StackAbility(mage.game.stack.StackAbility)

Aggregations

Game (mage.game.Game)212 Ability (mage.abilities.Ability)139 Player (mage.players.Player)126 UUID (java.util.UUID)117 OneShotEffect (mage.abilities.effects.OneShotEffect)104 CardSetInfo (mage.cards.CardSetInfo)102 CardImpl (mage.cards.CardImpl)100 CardType (mage.constants.CardType)82 Outcome (mage.constants.Outcome)78 Permanent (mage.game.permanent.Permanent)66 MageInt (mage.MageInt)60 mage.constants (mage.constants)47 Zone (mage.constants.Zone)46 GameEvent (mage.game.events.GameEvent)44 Objects (java.util.Objects)41 StaticFilters (mage.filter.StaticFilters)40 Collectors (java.util.stream.Collectors)35 SubType (mage.constants.SubType)34 Card (mage.cards.Card)32 MageObjectReference (mage.MageObjectReference)30