Example #1
0
 private bool TryHealHero(SampleSpellCard spell)
 {
     if (CurrentHealth < MaxHealth)
     {
         Logger.Log("[AI] Casting heal " + spell + " on hero.");
         PlayCardFromHand(spell, -1, ActiveSampleMatch.GetRowForPlayer(this));
         return(true);
     }
     return(false);
 }
Example #2
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);
        }
Example #3
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;
                }
            }
        }
Example #4
0
        private bool TryPlayMinion()
        {
            Logger.Log("[AI] Checking TryPlayMinion");

            List <SampleMinionCard> minions = new List <SampleMinionCard>();

            for (int i = 0; i < Hand.Cards.Count; i++)
            {
                SampleBaseCard card = (SampleBaseCard)Hand.Cards[i];
                if (card.CardType == SampleCardType.Minion)
                {
                    minions.Add(card as SampleMinionCard);
                }
            }

            if (minions.Count == 0)
            {
                Logger.Log("[AI] Got zero minions on hand. Not possible to play one.");
                return(false);
            }

            for (int i = 0; i < minions.Count; i++)
            {
                if (minions[i].Cost <= CurrentMana)
                {
                    if (PlayCardFromHand(minions[i], 0, ActiveSampleMatch.GetRowForPlayer(this)) == true)
                    {
                        Logger.Log("[AI] Played minion '" + minions[i] + "' to playfield.");
                        return(true);
                    }
                }
            }

            Logger.Log("[AI] Got some minions on hand, but can't play any.");

            return(false);
        }