Exemplo n.º 1
0
        private bool TryAttackEnemy()
        {
            Logger.Log("[AI] Checking TryAttackEnemy");

            SampleMinionCard[] ownMinions   = GetUsableMinions();
            SampleMinionCard[] enemyMinions = GetEnemyMinions();

            int enemyRow = ActiveSampleMatch.GetRowForPlayer(ActiveSampleMatch.InactiveSamplePlayer);

            // Check if we should attack the enemy hero, which we will do if
            // there are no enemy minions on the playfield
            if (ownMinions.Length > 0 && enemyMinions.Length == 0)
            {
                for (int i = 0; i < ownMinions.Length; i++)
                {
                    int row   = 0;
                    int index = 0;
                    if (ActiveSampleMatch.GetPlayfieldPositionForCard(ownMinions[0], out row, out index) == true)
                    {
                        Logger.Log("[AI] Attacking enemy hero with minion '" + ownMinions[0] + "' at position " + index + ".");
                        ActiveSampleMatch.AttackWithCardUsingIndexes(row, index, enemyRow, -1);
                    }
                }
                return(true);
            }

            // Focus on killing enemy minions
            for (int i = 0; i < enemyMinions.Length; i++)
            {
                bool             canKill = false;
                SampleBaseCard[] cards   = GetAttackingSolution(enemyMinions[i].CurrentHealth, out canKill);
                if (canKill && cards.Length > 0)
                {
                    AttackEnemyWithCards(cards, enemyMinions[i]);
                    return(true);
                }
            }

            // If we couldn't kill a minion yet, try to damage one as much as possible
            if (enemyMinions.Length > 0)
            {
                bool canKill = false;

                SampleBaseCard[] cards = GetAttackingSolution(enemyMinions[0].CurrentHealth, out canKill);
                if (cards.Length > 0)
                {
                    AttackEnemyWithCards(cards, enemyMinions[0]);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        private void AttackEnemyWithCards(SampleBaseCard[] cards, SampleMinionCard victimMinion)
        {
            int victimRow   = 0;
            int victimIndex = 0;

            if (victimMinion != null)
            {
                if (ActiveSampleMatch.GetPlayfieldPositionForCard(victimMinion, out victimRow, out victimIndex) == false)
                {
                    return;
                }
            }
            else
            {
                victimRow   = ActiveSampleMatch.GetRowForPlayer(ActiveSampleMatch.InactiveSamplePlayer);
                victimIndex = -1;
            }

            for (int i = 0; i < cards.Length; i++)
            {
                if (cards[i].CardType == SampleCardType.Minion)
                {
                    SampleMinionCard minion = (SampleMinionCard)cards[i];
                    int row   = 0;
                    int index = 0;
                    if (ActiveSampleMatch.GetPlayfieldPositionForCard(minion, out row, out index) == true)
                    {
                        Logger.Log("[AI] Attacking '" + (victimMinion != null ? victimMinion.ToString() : "enemy hero") + "' with minion '" + minion + "' at position " + index + ".");
                        ActiveSampleMatch.AttackWithCardUsingIndexes(row, index, victimRow, victimIndex);

                        return;
                    }
                }
                else if (cards[i].CardType == SampleCardType.Spell)
                {
                    SampleSpellCard spell = (SampleSpellCard)cards[i];
                    Logger.Log("[AI] Casting damage spell '" + spell + "' on victim '" + (victimMinion != null ? victimMinion.ToString() : "enemy hero") + "'.");
                    PlayCardFromHand(spell, victimIndex, victimRow);

                    return;
                }
            }
        }