private int CalculateLifelossScore(EvaluationParameters p) { var attackerParameters = GetAttackerParamers(p.Attacker, p.Blockers); return(ScoreCalculator.CalculateLifelossScore(p.DefendersLife, QuickCombat.CalculateDefendingPlayerLifeloss(attackerParameters))); }
private void AssignInitialBlockers(Card attacker, IEnumerable <Card> blockers, int defendersLife) { _canAllInitialBlockersBeKilled = true; var attackerAbilities = attacker.GetCombatAbilities(); var attackerEvaluationParameters = new AttackerEvaluationParameters(attacker, attackerAbilities.PowerIncrease, attackerAbilities.ToughnessIncrease); foreach (var blocker in blockers) { var blockerAbilities = blocker.GetCombatAbilities(); _blockers.Add(blocker); attackerEvaluationParameters.AddBlocker(blocker, blockerAbilities.PowerIncrease, blockerAbilities.ToughnessIncrease); var canBlockerBeDealtLeathalCombatDamage = QuickCombat.CanBlockerBeDealtLeathalCombatDamage(new BlockerEvaluationParameters { Attacker = attacker, Blocker = blocker, BlockerPowerIncrease = blockerAbilities.PowerIncrease, BlockerToughnessIncrease = blockerAbilities.ToughnessIncrease, AttackerPowerIncrease = attackerAbilities.PowerIncrease, AttackerToughnessIncrease = attackerAbilities.ToughnessIncrease }); var blockerScore = canBlockerBeDealtLeathalCombatDamage && !blockerAbilities.CanRegenerate ? blocker.Score : 0; var lifelossScore = ScoreCalculator.CalculateLifelossScore( defendersLife, attacker.CalculateCombatDamageAmount(singleDamageStep: false)); var trampleScore = ScoreCalculator.CalculateLifelossScore( defendersLife, QuickCombat.CalculateTrampleDamage(Attacker, blocker)); Gain = lifelossScore - blockerScore - trampleScore; _canAllInitialBlockersBeKilled = _canAllInitialBlockersBeKilled && canBlockerBeDealtLeathalCombatDamage; } IsAttackerKilled = QuickCombat.CanAttackerBeDealtLeathalDamage(attackerEvaluationParameters); var attackerScore = IsAttackerKilled && !attackerAbilities.CanRegenerate ? attacker.Score : 0; Gain += attackerScore; }
public Results Evaluate() { var results = new Results(); if (!_p.Attacker.Is().Creature || !_p.Attacker.CanBeDestroyed) { return(results); } var blockers = _p.Blockers; if (_p.Attacker.HasFirstStrike) { blockers = GetOnlyBlockersThatWontBeKilledBeforeTheyDealDamage().ToList(); } var maxDamageDealtByAnyBlocker = 0; Card blockerThatDealsMaxDamage = null; foreach (var blocker in blockers) { var amount = QuickCombat.GetAmountOfDamageCreature1WillDealToCreature2( creature1: blocker.Card, creature2: _p.Attacker, powerIncrease: blocker.PowerIncrease); if (amount > 0 && blocker.Card.Has().Deathtouch) { results.ReceivesLeathalDamage = true; results.DeathTouchDamage += amount; results.LeathalBlocker = blocker.Card; } results.TotalDamage += amount; if (amount > maxDamageDealtByAnyBlocker) { blockerThatDealsMaxDamage = blocker.Card; maxDamageDealtByAnyBlocker = amount; } } results.ReceivesLeathalDamage = results.ReceivesLeathalDamage || results.TotalDamage >= _p.Attacker.Life + _p.AttackerToughnessIncrease; results.LeathalBlocker = results.LeathalBlocker ?? blockerThatDealsMaxDamage; return(results); }
private int CalculateAttackerScore(EvaluationParameters p) { if (p.Attacker.Card.Has().Deathtouch) { return(0); } var attackerParamers = GetAttackerParamers(p.Attacker, p.Blockers); if (QuickCombat.CanAttackerBeDealtLeathalDamage(attackerParamers) && !p.Attacker.Abilities.CanRegenerate) { return(p.Attacker.Card.Score); } return(0); }
private IEnumerable <AttackerEvaluationParameters.Blocker> GetOnlyBlockersThatWontBeKilledBeforeTheyDealDamage() { return(_p.Blockers.Where(blocker => { if (blocker.Card.HasFirstStrike || blocker.Card.Has().Indestructible) { return true; } var attackersDamage = QuickCombat.GetAmountOfDamageCreature1WillDealToCreature2( creature1: _p.Attacker, creature2: blocker.Card, powerIncrease: _p.AttackerPowerIncrease); return blocker.Card.Life + blocker.ToughnessIncrease > attackersDamage; })); }
private bool IncreasesGain(Card additionalBlocker) { // attacker was not killed, but blocker was // check if additional blocker changes things if (_canAllInitialBlockersBeKilled == false) { return(false); } if (additionalBlocker.Score > Attacker.Score) { return(false); } return(QuickCombat.CanAttackerBeDealtLeathalDamage( Attacker, _blockers.Concat(additionalBlocker.ToEnumerable()))); }
private int CalculateBlockersScore(EvaluationParameters p) { if (p.Blockers.Count == 0) { return(0); } var blockersRanks = p.Blockers.Select(blocker => { var blockerParameters = GetBlockerParameters(p.Attacker, blocker); var attackerParameters = GetAttackerParamers(p.Attacker, new[] { blocker }); return(new { Blocker = blocker, CanBeKilled = QuickCombat.CanBlockerBeDealtLeathalCombatDamage(blockerParameters), CanKill = QuickCombat.CanAttackerBeDealtLeathalDamage(attackerParameters) }); }) .ToList(); if (blockersRanks.Any(x => !x.CanBeKilled)) { return(0); } var leastValuedBlockerWhoCanKill = blockersRanks.Where(x => x.CanKill) .OrderBy(x => x.Blocker.Card.Score) .FirstOrDefault(); if (leastValuedBlockerWhoCanKill != null) { return(leastValuedBlockerWhoCanKill.Blocker.Card.Score); } return(blockersRanks.OrderBy(x => x.Blocker.Card.Score).First().Blocker.Card.Score); }
private bool IsSafeBlock(Card additionalBlocker) { return(!QuickCombat.CanBlockerBeDealtLeathalCombatDamage(Attacker, additionalBlocker)); }