예제 #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);
 }
예제 #2
0
        /// <summary>
        /// Returns a list of minions of the enemy player. This function is only usable if the CPU is the active player
        /// </summary>
        private SampleMinionCard[] GetEnemyMinions()
        {
            SampleBaseCard[]        cardsOnPlayfield = ActiveSampleMatch.GetCardsForPlayer(ActiveSampleMatch.InactiveSamplePlayer);
            List <SampleMinionCard> result           = new List <SampleMinionCard>(cardsOnPlayfield.Length);

            for (int i = 0; i < cardsOnPlayfield.Length; i++)
            {
                result.Add((SampleMinionCard)cardsOnPlayfield[i]);
            }

            return(result.ToArray());
        }
예제 #3
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);
        }
예제 #4
0
        /// <summary>
        /// Returns a list of minions who can still perform some action in this round.
        /// </summary>
        private SampleMinionCard[] GetUsableMinions()
        {
            List <SampleMinionCard> result = new List <SampleMinionCard>();

            SampleBaseCard[] cardsOnPlayfield = ActiveSampleMatch.GetCardsForPlayer(this);
            for (int i = 0; i < cardsOnPlayfield.Length; i++)
            {
                SampleMinionCard card = (SampleMinionCard)cardsOnPlayfield[i];
                if (card.CurrentMovesPerRound > 0)
                {
                    result.Add(card);
                }
            }

            return(result.ToArray());
        }
예제 #5
0
 private bool TryHealMinions(SampleSpellCard spell)
 {
     SampleMinionCard[] damagedMinions = GetOwnDamagedMinions();
     for (int i = 0; i < damagedMinions.Length; i++)
     {
         int row   = 0;
         int index = 0;
         if (ActiveSampleMatch.GetPlayfieldPositionForCard(damagedMinions[i], out row, out index) == true)
         {
             Logger.Log("[AI] Casting heal " + spell + " on " + damagedMinions[i]);
             PlayCardFromHand(spell, index, row);
             return(true);
         }
     }
     return(false);
 }
예제 #6
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;
                }
            }
        }
예제 #7
0
        private SampleMinionCard[] GetOwnDamagedMinions()
        {
            List <SampleMinionCard> result = new List <SampleMinionCard>();

            SampleBaseCard[] minons = ActiveSampleMatch.GetCardsForPlayer(this);

            for (int i = 0; i < minons.Length; i++)
            {
                if (minons[i].CardType == SampleCardType.Minion)
                {
                    SampleMinionCard minion = (SampleMinionCard)minons[i];
                    if (minion.CurrentHealth < minion.MaxHealth)
                    {
                        result.Add(minion);
                    }
                }
            }

            return(result.ToArray());
        }
예제 #8
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);
        }