Example #1
0
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>(ControlledBy.Opponent)
            .OrderByDescending(x => x.Score);

              return Group(candidates, p.MinTargetCount(), p.MaxTargetCount());
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var sourceTargetCandidates = GetDamageSourceAndDamageTargetCandidates(p);

              if (sourceTargetCandidates.DamageSource.Count == 0 ||
            sourceTargetCandidates.DamageTarget.Count == 0)
              {
            return None<Targets>();
              }

              // for simplicity we consider only 'best' 1 legal assignment
              var damageSource = sourceTargetCandidates.DamageSource[0];
              var damageTarget = sourceTargetCandidates.DamageTarget[0];

              // cost should not be paid with damage target
              var cost = p.Candidates<Card>(selector: trgs => trgs.Cost)
            .OrderBy(x => x.Score)
            .Where(x => x != damageTarget)
            .FirstOrDefault();

              if (cost == null)
              {
            return None<Targets>();
              }

              var targets = new Targets();
              targets.AddCost(cost);
              targets.AddEffect(damageSource);
              targets.AddEffect(damageTarget);

              return new[] {targets};
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var costCandidates = p
            .Candidates<Card>(selector: c => c.Cost)
            .OrderBy(x => x.Score)
            .Take(1);

              var effectCandidates =
            p.Candidates<Card>(ControlledBy.Opponent, selector: c => c.Effect)
              .Where(x => !x.IsTapped)
              .OrderBy(x =>
            {
              if (x.Is().Creature)
                return 1;

              if (x.Is().Land)
                return 2;

              return 3;
            })
              .Take(1);

              return Group(costCandidates, effectCandidates,
            add1: (t, trgs) => trgs.AddCost(t),
            add2: (t, trgs) => trgs.AddEffect(t));
        }
Example #4
0
        protected override IEnumerable<Targets> ForceSelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>(ControlledBy.SpellOwner)
            .OrderBy(x => x.Score);

              return Group(candidates, p.MinTargetCount(), p.MaxTargetCount());
        }
Example #5
0
        protected override IEnumerable<Targets> ForceSelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>()
            .OrderBy(c => c.Score);

              return Group(candidates, p.MinTargetCount());
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>(ControlledBy.Opponent)
            .Where(c => c.IsAttacker || c.CanBlock())
            .Select(c =>
              {
            for (var i = 0; i < _abilities.Count; i++)
            {
              var ability = _abilities[i];

              if (c.Has().Has(ability))
                return new
                  {
                    Card = c,
                    Rank = i
                  };
            }

            return new
              {
                Card = c,
                Rank = -1
              };
              })
            .Where(x => x.Rank != -1)
            .OrderBy(x => x.Rank)
            .ThenByDescending(x => x.Card.Power*2 + x.Card.Toughness)
            .Select(x => x.Card);

              return Group(candidates, p.MinTargetCount());
        }
Example #7
0
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = GetCandidatesForProtectionFromTopSpell(p)
            .OrderByDescending(x => x.Score);

              return Group(candidates, p.MinTargetCount());
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var targetPicks = new List<ITarget>();

              if (!Stack.IsEmpty && p.Candidates<ITarget>().Contains(Stack.TopSpell))
              {
            var damageToPlayer = Stack.GetDamageTopSpellWillDealToPlayer(p.Controller);

            if (damageToPlayer > 0)
            {
              targetPicks.Add(Stack.TopSpell);
            }
              }

              if (Turn.Step == Step.DeclareBlockers && Stack.IsEmpty)
              {
            if (!p.Controller.IsActive)
            {
              var attacker = Combat.FindAttackerWhichWillDealGreatestDamageToDefender(
            card => p.Candidates<ITarget>().Contains(card));

              if (attacker != null)
              {
            targetPicks.Add(attacker);
              }
            }
              }

              return Group(targetPicks, 1);
        }
Example #9
0
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Player>()
            .Where(x => x == p.Controller.Opponent);

              return Group(candidates, 1);
        }
        private void PreventDamageAttackerWillDealToBlocker(TargetingRuleParameters p,
      DamageSourceAndDamageTargetCandidates selectedCandidates)
        {
            var blockerAttackerPair = p.Candidates<Card>(selectorIndex: 1, selector: trgs => trgs.Effect)
            .Where(card => card.IsBlocker)
            .Select(blocker =>
              {
            var attacker = Combat.GetAttacker(blocker);

            return new
              {
                Target = blocker,
                Source = QuickCombat.CanBlockerBeDealtLeathalCombatDamage(attacker, blocker)
                  ? attacker : null
              };
              })
            .Where(x => x.Source != null)
            .OrderByDescending(x => x.Target.Score)
            .FirstOrDefault();

              if (blockerAttackerPair != null)
              {
            selectedCandidates.DamageTarget.Add(blockerAttackerPair.Target);
            selectedCandidates.DamageSource.Add(blockerAttackerPair.Source);
              }
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            if (Stack.CanTopSpellReducePlayersLifeToZero(p.Controller))
              {
            var candidates1 = p.Candidates<Card>()
              .OrderBy(x => x.Score);

            return Group(candidates1, p.MinTargetCount(), add: (target, targets) => targets.Cost.Add(target));
              }

              var candidates = new List<Card>();

              if (Turn.Step == Step.DeclareBlockers && Stack.IsEmpty)
              {
            candidates.AddRange(
              p.Candidates<Card>()
            .Where(x => Combat.CanBeDealtLeathalCombatDamage(x))
            .Where(x => !Combat.CanKillAny(x)));
              }

              candidates.AddRange(
            p.Candidates<Card>()
              .Where(x => Stack.CanBeDestroyedByTopSpell(x)));

              return Group(candidates, p.MinTargetCount(), add: (target, targets) => targets.Cost.Add(target));
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>(ControlledBy.Opponent)
            .OrderByDescending(x => x.Toughness);

              return Group(candidates, 1);
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            IEnumerable<Card> candidates;

              if (Turn.Step == Step.FirstMain)
              {
            candidates = p.Candidates<Card>(ControlledBy.SpellOwner)
              .Where(x => x.CanAttack)
              .Select(x => new
            {
              Card = x.Card(),
              Score = CalculateAttackerScoreForThisTurn(x)
            })
              .OrderByDescending(x => x.Score)
              .Where(x => x.Score > 0)
              .Select(x => x.Card);
              }
              else
              {
            candidates = p.Candidates<Card>(ControlledBy.SpellOwner)
              .Where(x => x.CanBlock())
              .Select(x => new
            {
              Card = x,
              Score = CalculateBlockerScore(x)
            })
              .OrderByDescending(x => x.Score)
              .Where(x => x.Score > 0)
              .Select(x => x.Card);
              }

              return Group(candidates, 1);
        }
        protected DamageSourceAndDamageTargetCandidates GetDamageSourceAndDamageTargetCandidates(TargetingRuleParameters p)
        {
            var selectedCandidates = new DamageSourceAndDamageTargetCandidates();

              if (Stack.IsEmpty == false)
              {
            PreventDamageTopSpellWillDealToPlayer(p, selectedCandidates);
            PreventDamageTopSpellWillDealToCreature(p, selectedCandidates);
              }

              if (Turn.Step == Step.DeclareBlockers)
              {
            if (p.Controller.IsActive == false)
            {
              PreventDamageAttackerWillDealToPlayer(p, selectedCandidates);
              PreventDamageAttackerWillDealToBlocker(p, selectedCandidates);
            }
            else
            {
              PreventDamageBlockerWillDealToAttacker(p, selectedCandidates);
            }
              }

              return selectedCandidates;
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>(ControlledBy.Opponent)
            .Where(x => (!_blockOnly && x.IsAbleToAttack) || (!_attackOnly && !x.Has().CannotBlock))
            .OrderByDescending(x => 2*x.Power + x.Toughness);

              return Group(candidates, p.MinTargetCount(), p.MaxTargetCount());
        }
Example #16
0
        protected override IEnumerable<Targets> ForceSelectTargets(TargetingRuleParameters p)
        {
            // triggered abilities force you to choose a target even if its
              // not favorable e.g Flaming Kavu

              var candidates = p.Candidates<Card>().OrderByDescending(x => x.Toughness);
              return Group(candidates, p.MinTargetCount());
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>(ControlledBy.SpellOwner)
            .Where(attacker => _filter(attacker))
            .OrderByDescending(CalculateScore);

              return Group(candidates, p.MinTargetCount());
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>(ControlledBy.SpellOwner)
            .Where(x => x.IsTapped && !x.Is().Land)
            .OrderByDescending(x => x.Score);

              return Group(candidates, p.MinTargetCount());
        }
Example #19
0
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>()
            .OrderBy(x => ScoreCalculator.CalculateDiscardScore(x, Ai.IsSearchInProgress));

              return Group(candidates, p.MaxTargetCount(),
            add: (trg, trgs) => trgs.Cost.Add(trg));
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = GetCandidatesThatCanBeDestroyed(p)
            .Where(x => !x.HasRegenerationShield)
            .OrderByDescending(x => x.Card().Score);

              return Group(candidates, p.MinTargetCount());
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>()
            .OrderBy(x => x.Score);

              return Group(candidates, p.MinTargetCount(),
            add: (trg, trgs) => trgs.Cost.Add(trg));
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var costTargets = p.Candidates<Card>(selectorIndex: 0, selector: c => c.Cost)
            .OrderBy(x => x.IsTapped ? 0 : 1)
            .ThenBy(x => x.Score)
            .Take(1);

              return Group(costTargets, p.MinTargetCount(), add: (t, trgs) => trgs.AddCost(t));
        }
Example #23
0
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>(ControlledBy.SpellOwner)
            .OrderByDescending(x => x.IsTapped ? 1 : 0)
            .Select(x => x)
            .ToList();

              return Group(candidates, p.MinTargetCount());
        }
Example #24
0
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>(ControlledBy.SpellOwner)
            .Where(c => c.CanBlock())
            .Where(c => !c.Has().Flying && !c.Has().Reach)
            .OrderByDescending(x => x.Power);

              return Group(candidates, p.MinTargetCount());
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>()
            .Where(x => x.IsGoodTarget(p.Card, p.Card.Controller))
            .OrderByDescending(x => x.Score)
            .ToList();

              return Group(candidates, p.MinTargetCount(), p.MaxTargetCount());
        }
Example #26
0
        private int CalculateOpponentCardRank(Card card, TargetingRuleParameters p)
        {
            if (card.Owner == p.Controller)
            return -2;

              if (card.HasAttachments)
            return -1;

              return 0;
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var battlefieldCandidates = p.Candidates<Card>(ControlledBy.SpellOwner)
            .OrderBy(x => x.Score);

              var graveyardCandidates = p.Candidates<Card>(ControlledBy.SpellOwner, selectorIndex: 1)
            .OrderBy(x => -x.Score);

              return Group(battlefieldCandidates, graveyardCandidates);
        }
Example #28
0
        protected override IEnumerable<Targets> ForceSelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>()
            .OrderBy(_forceRank);

              if (p.HasEffectCandidates)
            return Group(candidates, p.MinTargetCount());

              return Group(candidates, p.MinTargetCount(), add: (trg, trgs) => trgs.AddCost(trg));
        }
Example #29
0
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Card>(_controlledBy)
            .OrderBy(x => _rank(x));

              if (p.HasEffectCandidates)
            return Group(candidates, p.MinTargetCount(), p.MaxTargetCount());

              return Group(candidates, p.MinTargetCount(), p.MaxTargetCount(), (trg, trgs) => trgs.AddCost(trg));
        }
        protected override IEnumerable<Targets> SelectTargets(TargetingRuleParameters p)
        {
            var candidates = p.Candidates<Effect>(ControlledBy.Opponent);

              if (!candidates.Contains(Stack.TopSpell))
              {
            return None<Targets>();
              }

              return new[] {new Targets().AddEffect(Stack.TopSpell)};
        }