Exemple #1
0
        public ClientCard GetBestBotMonster(bool onlyATK = false)
        {
            int        bestPower   = -1;
            ClientCard bestMonster = null;

            for (int i = 0; i < 7; ++i)
            {
                ClientCard card = Bot.MonsterZone[i];
                if (card == null || card.Data == null)
                {
                    continue;
                }
                if (onlyATK && card.IsDefense())
                {
                    continue;
                }
                int newPower = card.GetDefensePower();
                if (newPower > bestPower)
                {
                    bestPower   = newPower;
                    bestMonster = card;
                }
            }
            return(bestMonster);
        }
Exemple #2
0
        /// <summary>
        /// Decide which card should the attacker attack.
        /// </summary>
        /// <param name="attacker">Card that attack.</param>
        /// <param name="defenders">Cards that defend.</param>
        /// <returns>BattlePhaseAction including the target, or null (in this situation, GameAI will check the next attacker)</returns>
        public override BattlePhaseAction OnSelectAttackTarget(ClientCard attacker, IList <ClientCard> defenders)
        {
            for (int i = 0; i < defenders.Count; ++i)
            {
                ClientCard defender = defenders[i];

                attacker.RealPower = attacker.Attack;
                defender.RealPower = defender.GetDefensePower();
                if (!OnPreBattleBetween(attacker, defender))
                {
                    continue;
                }

                if (attacker.RealPower > defender.RealPower || (attacker.RealPower >= defender.RealPower && attacker.IsLastAttacker && defender.IsAttack()))
                {
                    return(AI.Attack(attacker, defender));
                }
            }

            if (attacker.CanDirectAttack)
            {
                return(AI.Attack(attacker, null));
            }

            return(null);
        }
Exemple #3
0
        public bool IsOneEnemyBetterThanValue(int value, bool onlyATK)
        {
            int  bestValue = -1;
            bool nomonster = true;

            for (int i = 0; i < 7; ++i)
            {
                ClientCard card = Enemy.MonsterZone[i];
                if (card == null || card.Data == null)
                {
                    continue;
                }
                if (onlyATK && card.IsDefense())
                {
                    continue;
                }
                nomonster = false;
                int enemyValue = card.GetDefensePower();
                if (enemyValue > bestValue)
                {
                    bestValue = enemyValue;
                }
            }
            if (nomonster)
            {
                return(false);
            }
            return(bestValue > value);
        }
Exemple #4
0
        /// <summary>
        /// Summon with tributes ATK lower.
        /// </summary>
        protected bool DefaultTributeSummon()
        {
            foreach (ClientCard card in Bot.MonsterZone)
            {
                if (card != null &&
                    card.Id == Card.Id &&
                    card.HasPosition(CardPosition.FaceUp))
                {
                    return(false);
                }
            }
            int tributecount = (int)Math.Ceiling((Card.Level - 4.0d) / 2.0d);

            for (int j = 0; j < 7; ++j)
            {
                ClientCard tributeCard = Bot.MonsterZone[j];
                if (tributeCard == null)
                {
                    continue;
                }
                if (tributeCard.GetDefensePower() < Card.Attack)
                {
                    tributecount--;
                }
            }
            return(tributecount <= 0);
        }
Exemple #5
0
        public ClientCard GetWorstEnemyMonster(bool onlyATK = false)
        {
            int        WorstPower   = -1;
            ClientCard WorstMonster = null;

            for (int i = 0; i < 7; ++i)
            {
                ClientCard card = Enemy.MonsterZone[i];
                if (card == null || card.Data == null)
                {
                    continue;
                }
                if (onlyATK && card.IsDefense())
                {
                    continue;
                }
                int newPower = card.GetDefensePower();
                if (newPower < WorstPower)
                {
                    WorstPower   = newPower;
                    WorstMonster = card;
                }
            }
            return(WorstMonster);
        }
Exemple #6
0
        public bool IsOneEnnemyBetterThanValue(int value, bool onlyatk)
        {
            int  bestValue = -1;
            bool nomonster = true;

            for (int i = 0; i < 5; ++i)
            {
                ClientCard card = Duel.Fields[1].MonsterZone[i];
                if (card == null)
                {
                    continue;
                }
                if (onlyatk && card.IsDefense())
                {
                    continue;
                }
                nomonster = false;
                int ennemyValue = card.GetDefensePower();
                if (ennemyValue > bestValue)
                {
                    bestValue = ennemyValue;
                }
            }
            if (nomonster)
            {
                return(false);
            }
            return(bestValue > value);
        }
Exemple #7
0
        /// <summary>
        /// Summon with no tribute, or with tributes ATK lower.
        /// </summary>
        protected bool DefaultMonsterSummon()
        {
            if (Card.Level <= 4)
            {
                return(true);
            }

            if (!UniqueFaceupMonster())
            {
                return(false);
            }
            int tributecount = (int)Math.Ceiling((Card.Level - 4.0d) / 2.0d);

            for (int j = 0; j < 7; ++j)
            {
                ClientCard tributeCard = Bot.MonsterZone[j];
                if (tributeCard == null)
                {
                    continue;
                }
                if (tributeCard.GetDefensePower() < Card.Attack)
                {
                    tributecount--;
                }
            }
            return(tributecount <= 0);
        }
Exemple #8
0
        public ClientCard GetOneEnemyBetterThanValue(int value, bool onlyATK = false, bool canBeTarget = false)
        {
            ClientCard bestCard  = null;
            int        bestValue = value;

            for (int i = 0; i < 7; ++i)
            {
                ClientCard card = Enemy.MonsterZone[i];
                if (card == null || card.Data == null || (canBeTarget && card.IsShouldNotBeTarget()))
                {
                    continue;
                }
                if (onlyATK && card.IsDefense())
                {
                    continue;
                }
                int enemyValue = card.GetDefensePower();
                if (enemyValue >= bestValue)
                {
                    bestCard  = card;
                    bestValue = enemyValue;
                }
            }
            return(bestCard);
        }
Exemple #9
0
        public static int CompareDefensePower(ClientCard cardA, ClientCard cardB)
        {
            if (cardA == null && cardB == null)
            {
                return(0);
            }
            if (cardA == null)
            {
                return(-1);
            }
            if (cardB == null)
            {
                return(1);
            }
            int powerA = cardA.GetDefensePower();
            int powerB = cardB.GetDefensePower();

            if (powerA < powerB)
            {
                return(-1);
            }
            if (powerA == powerB)
            {
                return(0);
            }
            return(1);
        }
Exemple #10
0
        public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
        {
            if (!defender.IsMonsterHasPreventActivationEffectInBattle())
            {
                if (attacker.IsCode(CardId.TrickstarCandina) && Bot.HasInHand(CardId.TrickstarCarobein))
                {
                    attacker.RealPower = attacker.RealPower + 1800;
                }

                if (attacker.IsCode(CardId.BorrelswordDragon) && !attacker.IsDisabled() && !BorrelswordDragonUsed)
                {
                    attacker.RealPower = attacker.RealPower + defender.GetDefensePower() / 2;
                    defender.RealPower = defender.RealPower - defender.GetDefensePower() / 2;
                }
            }
            return(base.OnPreBattleBetween(attacker, defender));
        }
Exemple #11
0
        /// <summary>
        /// Called when the AI has to decide if it should attack
        /// </summary>
        /// <param name="attackers">List of monsters that can attcack.</param>
        /// <param name="defenders">List of monsters of enemy.</param>
        /// <returns>A new BattlePhaseAction containing the action to do.</returns>
        public virtual BattlePhaseAction OnBattle(IList <ClientCard> attackers, IList <ClientCard> defenders)
        {
            if (attackers.Count == 0)
            {
                return(AI.ToMainPhase2());
            }

            if (defenders.Count == 0)
            {
                for (int i = attackers.Count - 1; i >= 0; --i)
                {
                    ClientCard attacker = attackers[i];
                    if (attacker.Attack > 0)
                    {
                        return(AI.Attack(attacker, null));
                    }
                }
            }
            else
            {
                for (int i = defenders.Count - 1; i >= 0; --i)
                {
                    ClientCard defender = defenders[i];
                    for (int j = 0; j < attackers.Count; ++j)
                    {
                        ClientCard attacker = attackers[j];
                        attacker.RealPower = attacker.Attack;
                        defender.RealPower = defender.GetDefensePower();
                        if (!OnPreBattleBetween(attacker, defender))
                        {
                            continue;
                        }
                        if (attacker.RealPower > defender.RealPower || (attacker.RealPower >= defender.RealPower && j == attackers.Count - 1))
                        {
                            return(AI.Attack(attacker, defender));
                        }
                    }
                }

                for (int i = attackers.Count - 1; i >= 0; --i)
                {
                    ClientCard attacker = attackers[i];
                    if (attacker.CanDirectAttack)
                    {
                        return(AI.Attack(attacker, null));
                    }
                }
            }

            if (!Battle.CanMainPhaseTwo)
            {
                return(AI.Attack(attackers[0], (defenders.Count == 0) ? null : defenders[0]));
            }

            return(AI.ToMainPhase2());
        }
Exemple #12
0
 public static int CompareDefensePower(ClientCard cardA, ClientCard cardB)
 {
     if (cardA == null && cardB == null)
         return 0;
     if (cardA == null)
         return -1;
     if (cardB == null)
         return 1;
     int powerA = cardA.GetDefensePower();
     int powerB = cardB.GetDefensePower();
     if (powerA < powerB)
         return -1;
     if (powerA == powerB)
         return 0;
     return 1;
 }
 public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
 {
     if (defender.IsMonsterInvincible())
     {
         if (defender.IsMonsterDangerous() || defender.IsDefense())
         {
             return(false);
         }
     }
     if (!(defender.Id == (int)CardId.闪光No39希望皇霍普电光皇))
     {
         if (attacker.Id == (int)CardId.神骑矢车菊圣人马 && !attacker.IsDisabled() && attacker.HasXyzMaterial())
         {
             attacker.RealPower = Duel.LifePoints[0] + attacker.Attack;
         }
     }
     return(attacker.RealPower >= defender.GetDefensePower());
 }
Exemple #14
0
 public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
 {
     if (defender.IsMonsterInvincible())
     {
         if (defender.IsMonsterDangerous() || defender.IsDefense())
         {
             return(false);
         }
     }
     if (!(defender.Id == (int)CardId.闪光No39希望皇霍普电光皇))
     {
         //if (attacker.HasType(CardType.Fusion) && Bot.HasInHand((int)CardId.召唤师阿莱斯特))
         //    attacker.RealPower = attacker.RealPower + 1000;
         if (attacker.Id == (int)CardId.闪光No39希望皇霍普电光皇 && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, (int)CardId.No39希望皇霍普))
         {
             attacker.RealPower = 5000;
         }
     }
     return(attacker.RealPower > defender.GetDefensePower());
 }
Exemple #15
0
 public ClientCard GetOneEnnemyBetterThanValue(int value, bool onlyatk)
 {
     for (int i = 0; i < 7; ++i)
     {
         ClientCard card = Duel.Fields[1].MonsterZone[i];
         if (card == null)
         {
             continue;
         }
         if (onlyatk && card.IsDefense())
         {
             continue;
         }
         int ennemyValue = card.GetDefensePower();
         if (ennemyValue >= value)
         {
             return(card);
         }
     }
     return(null);
 }
 public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
 {
     if (defender.IsMonsterInvincible())
     {
         if (defender.IsMonsterDangerous() || defender.IsDefense())
         {
             return(false);
         }
     }
     if (!(defender.Id == (int)CardId.闪光No39希望皇霍普电光皇))
     {
         if (attacker.Attribute == (int)CardAttribute.Light && Duel.Fields[0].HasInHand((int)CardId.欧尼斯特))
         {
             attacker.RealPower = attacker.RealPower + defender.Attack;
         }
         if (attacker.Id == (int)CardId.闪光No39希望皇霍普电光皇 && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, (int)CardId.No39希望皇霍普))
         {
             attacker.RealPower = 5000;
         }
     }
     return(attacker.RealPower > defender.GetDefensePower());
 }
Exemple #17
0
 public override BattlePhaseAction OnSelectAttackTarget(ClientCard attacker, IList <ClientCard> defenders)
 {
     if (attacker.IsCode(CardId.BlueEyesChaosMaxDragon) && !attacker.IsDisabled() &&
         Enemy.HasInMonstersZone(new[] { CardId.DeviritualTalismandra, CardId.DevirrtualCandoll }))
     {
         for (int i = 0; i < defenders.Count; i++)
         {
             ClientCard defender = defenders[i];
             attacker.RealPower = attacker.Attack;
             defender.RealPower = defender.GetDefensePower();
             if (!OnPreBattleBetween(attacker, defender))
             {
                 continue;
             }
             if (defender.IsCode(CardId.DevirrtualCandoll, CardId.DeviritualTalismandra))
             {
                 return(AI.Attack(attacker, defender));
             }
         }
     }
     return(base.OnSelectAttackTarget(attacker, defenders));
 }
Exemple #18
0
 public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
 {
     if (defender.IsMonsterInvincible())
     {
         if (defender.IsMonsterDangerous() || defender.IsDefense())
         {
             return(false);
         }
     }
     if (!(defender.Id == (int)CardId.闪光No39希望皇霍普电光皇))
     {
         if (attacker.Id == (int)CardId.闪光No39希望皇霍普电光皇 && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, (int)CardId.No39希望皇霍普))
         {
             attacker.RealPower = 5000;
         }
         if (Duel.Fields[0].HasInMonstersZone((int)CardId.No37希望织龙蜘蛛鲨, true, true))
         {
             attacker.RealPower = attacker.RealPower + 1000;
         }
     }
     return(attacker.RealPower > defender.GetDefensePower());
 }
Exemple #19
0
 public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
 {
     if (defender.IsMonsterInvincible())
     {
         if (defender.IsMonsterDangerous() || defender.IsDefense())
         {
             return(false);
         }
     }
     if (!(defender.Id == (int)CardId.NumberS39UtopiatheLightning))
     {
         if (attacker.Attribute == (int)CardAttribute.Light && Bot.HasInHand((int)CardId.Honest))
         {
             attacker.RealPower = attacker.RealPower + defender.Attack;
         }
         if (attacker.Id == (int)CardId.NumberS39UtopiatheLightning && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, (int)CardId.Number39Utopia))
         {
             attacker.RealPower = 5000;
         }
     }
     return(attacker.RealPower > defender.GetDefensePower());
 }
Exemple #20
0
 public override BattlePhaseAction OnSelectAttackTarget(ClientCard attacker, IList <ClientCard> defenders)
 {
     for (int i = 0; i < defenders.Count; ++i)
     {
         ClientCard defender = defenders[i];
         attacker.RealPower = attacker.Attack;
         defender.RealPower = defender.GetDefensePower();
         if (defender.IsCode(732) && defender.IsAttack())
         {
             defender.RealPower = defender.Attack * 2;
         }
         if (attacker.IsCode(CardId.Number100Dragon, CardId.CNumber100Dragon, 592) && !attacker.IsDisabled())
         {
             defender.RealPower = 0;
         }
         if (defender.IsCode(CardId.Number100Dragon, CardId.CNumber100Dragon, 592) && !defender.IsDisabled())
         {
             attacker.RealPower = 0;
         }
         if (attacker.IsCode(13701) && attacker.RealPower < defender.RealPower && Bot.LifePoints > defender.RealPower - attacker.RealPower && Bot.HasInHand(13717) && Bot.HasInExtra(CardId.CNo1000) && Bot.Graveyard.GetMatchingCardsCount(card => card.HasSetcode(0x48) || card.IsCode(12201, 13706)) + Bot.Banished.GetMatchingCardsCount(card => (card.HasSetcode(0x48) || card.IsCode(12201, 13706)) && card.IsFaceup()) > 4)
         {
             return(AI.Attack(attacker, defender));
         }
         if (!OnPreBattleBetween(attacker, defender))
         {
             continue;
         }
         if (attacker.RealPower >= defender.RealPower || (attacker.RealPower >= defender.RealPower && ((attacker.HasSetcode(0x48) && !attacker.IsDisabled() && !(defender.HasSetcode(0x48) && !defender.IsDisabled())) || attacker.IsLastAttacker && defender.IsAttack())))
         {
             return(AI.Attack(attacker, defender));
         }
     }
     if (Enemy.GetMonsterCount() == 0 || attacker.CanDirectAttack)
     {
         return(AI.Attack(attacker, null));
     }
     return(null);
 }
Exemple #21
0
        /// <summary>
        /// Get the best ATK or DEF power of the field.
        /// </summary>
        /// <param name="field">Bot or Enemy.</param>
        /// <param name="onlyATK">Only calculate attack.</param>
        public int GetBestPower(ClientField field, bool onlyATK = false)
        {
            int bestPower = -1;

            for (int i = 0; i < 7; ++i)
            {
                ClientCard card = field.MonsterZone[i];
                if (card == null || card.Data == null)
                {
                    continue;
                }
                if (onlyATK && card.IsDefense())
                {
                    continue;
                }
                int newPower = card.GetDefensePower();
                if (newPower > bestPower)
                {
                    bestPower = newPower;
                }
            }
            return(bestPower);
        }
Exemple #22
0
        public int GetBestAttack(ClientField field, bool onlyatk)
        {
            int bestAtk = -1;

            for (int i = 0; i < 7; ++i)
            {
                ClientCard card = field.MonsterZone[i];
                if (card == null)
                {
                    continue;
                }
                if (onlyatk && card.IsDefense())
                {
                    continue;
                }
                int ennemyValue = card.GetDefensePower();
                if (ennemyValue > bestAtk)
                {
                    bestAtk = ennemyValue;
                }
            }
            return(bestAtk);
        }
Exemple #23
0
        public virtual BattlePhaseAction OnBattle(IList <ClientCard> attackers, IList <ClientCard> defenders)
        {
            if (attackers.Count == 0)
            {
                return(AI.ToMainPhase2());
            }

            if (defenders.Count == 0)
            {
                return(AI.Attack(attackers[0], null));
            }

            for (int i = defenders.Count - 1; i >= 0; --i)
            {
                ClientCard defender = defenders[i];
                int        value    = defender.GetDefensePower();
                for (int j = 0; j < attackers.Count; ++j)
                {
                    ClientCard attacker = attackers[j];
                    if (!OnPreBattleBetween(attacker, defender))
                    {
                        continue;
                    }
                    if (attacker.Attack > value || (attacker.Attack >= value && j == attackers.Count - 1))
                    {
                        return(AI.Attack(attacker, defender));
                    }
                }
            }

            if (!Battle.CanMainPhaseTwo)
            {
                return(AI.Attack(attackers[attackers.Count - 1], defenders[0]));
            }

            return(AI.ToMainPhase2());
        }
Exemple #24
0
        public bool IsAllEnnemyBetterThanValue(int value, bool onlyatk)
        {
            bool nomonster = true;

            for (int i = 0; i < 5; ++i)
            {
                ClientCard card = Duel.Fields[1].MonsterZone[i];
                if (card == null || card.Data == null)
                {
                    continue;
                }
                if (onlyatk && card.IsDefense())
                {
                    continue;
                }
                nomonster = false;
                int ennemyValue = card.GetDefensePower();
                if (ennemyValue <= value)
                {
                    return(false);
                }
            }
            return(!nomonster);
        }