Beispiel #1
0
        static NetBattlefield ProduceFakeBFIfNeeded(int playerID, NetBattlefield bf)
        {
            //fake battlefield will contain all friendly cards currently not on battlefield
            //positioned on free positions so that AI can see if it can produce
            //any targets. there is no simulation involved so fake state should not harm "thinking"

            //we will not need fake BF IF all owned cards are already on BF.
            HashSet <NetCard> ownCastedCards = bf.GetCardsOnBattelfield(playerID);
            NetCardPlayerData ncd            = bf.GetPlayerByPlayerID(playerID);

            if (ncd == null || NetType.IsNullOrEmpty(ncd.HandCards))
            {
                return(bf);
            }

            List <int>     ownCardsAtHand = ncd.HandCards.value;
            List <NetCard> cardsToCast    = new List <NetCard>();

            //this is different set than just cards which were used, because card which casts summons or
            //does support will not be present on battlefield and still cost more than base AP
            foreach (var v in ownCardsAtHand)
            {
                NetCard nc = bf.GetCardByID(v);
                if (!ownCastedCards.Contains(nc))
                {
                    cardsToCast.Add(nc);
                }
            }

            if (cardsToCast.Count == 0)
            {
                return(bf);
            }

            //there are cards which should be represented on battle positions
            //which requires new BF
            //we would do simple but fake casts
            NetBattlefield bf2      = bf.CloneAndRemember();
            int            halfSize = bf2.BattlefieldSize / 2;
            int            start    = playerID == 0 ? 0 : halfSize;

            int cardListIndex = 0;

            for (int i = 0; i < halfSize; i++)
            {
                if (cardListIndex == cardsToCast.Count)
                {
                    break;
                }
                int index = i + start;
                if (bf2.BattlefieldPositions.value[index] == 0)
                {
                    bf2.BattlefieldPositions.value[index] = cardsToCast[cardListIndex].CardID;
                }
            }

            return(bf2);
        }