示例#1
0
 private void CardMagicCard(CardBehaviourScript _attacker, CardBehaviourScript _target)
 {
     CardBehaviourScript attacker = AITableCards.Find(item => item._name == _attacker._name);
     CardBehaviourScript target   = PlayerTableCards.Find(item => item._name == _target._name);
     {
         Action a;
         a.Card1  = attacker._name;
         a.Card2  = target._name;
         a.Hero   = "";
         a.OpCode = 3;
         Actions.Enqueue(a);
         attacker.AddToMonster(attacker, target, false, delegate
         {
             attacker.Destroy(attacker);
         });
     }
 }
    void AIGetAttacks()
    {
        AIGameState InitialState = new AIGameState(/*MyHandCards,*/ MyTableCards, AIHandCards, AITableCards, MyHero, AIHero, maxMana, MyMana, AIMana, turn, null);

        InitialState.GetAllAttackingActions(AILEVEL);
        //Find Best Score
        float       MaxScore  = float.MinValue;
        AIGameState BestState = new AIGameState();

        foreach (AIGameState item in AIGameState.AllStates)
        {
            if (item.State_Score > MaxScore)
            {
                MaxScore  = item.State_Score;
                BestState = item;
            }
        }
        //Debug.Log("Best choice Index" + BestState.Index);
        int count = BestState.Actions.Count;

        //GetActions
        for (int i = 0; i < count; i++)
        {
            AIGameState.Action a;
            a = BestState.Actions.Dequeue();
            if (a.OpCode == 1)
            {
                foreach (var item in AITableCards)//Find Card1
                {
                    if (item.GetComponent <CardBehaviourScript>()._name == a.Card1)
                    {
                        currentCard = item.GetComponent <CardBehaviourScript>();
                        break;
                    }
                }
                foreach (var item in MyTableCards)//Find Card2
                {
                    if (item.GetComponent <CardBehaviourScript>()._name == a.Card2)
                    {
                        targetCard = item.GetComponent <CardBehaviourScript>();
                        break;
                    }
                }
                if (currentCard != null && targetCard != null)//MakeAction
                {
                    currentCard.AttackCard(currentCard, targetCard, true, delegate
                    {
                        currentCard.canPlay = false;
                    });
                }
            }
            else if (a.OpCode == 2)
            {
                foreach (var item in AITableCards)//Find Card1
                {
                    if (item.GetComponent <CardBehaviourScript>()._name == a.Card1)
                    {
                        currentCard = item.GetComponent <CardBehaviourScript>();
                        break;
                    }
                }
                if (a.Hero == "MyHero")
                {
                    targetHero = MyHero;
                }
                if (currentCard != null && targetHero != null)
                {
                    currentCard.AttackHero(currentCard, MyHero, true, delegate
                    {
                        currentCard.canPlay = false;
                    });
                }
            }
            else if (a.OpCode == 3)
            {
                foreach (var item in AITableCards)//Find Card1
                {
                    if (item.GetComponent <CardBehaviourScript>()._name == a.Card1)
                    {
                        currentCard = item.GetComponent <CardBehaviourScript>();
                        break;
                    }
                }
                foreach (var item in MyTableCards)//Find Card2
                {
                    if (item.GetComponent <CardBehaviourScript>()._name == a.Card2)
                    {
                        targetCard = item.GetComponent <CardBehaviourScript>();
                        break;
                    }
                }
                if (currentCard != null && targetCard != null)//MakeAction
                {
                    currentCard.AddToMonster(currentCard, targetCard, true, delegate
                    {
                        currentCard.Destroy(currentCard);
                    });
                }
            }
        }
        //AIGameState.AllStates=new List< AIGameState > ();
    }
    void RendomActions()
    {
        #region placing cards
        //float chanceToPlace = Random.value;

        if (AIHandCards.Count == 0)
        {
            EndTurn();
        }
        else
        {
            PlaceRandomCard(CardBehaviourScript.Team.AI);
        }
        #endregion
        #region attacking
        Hashtable attacks = new Hashtable();
        foreach (GameObject Card in AITableCards)
        {
            CardBehaviourScript card = Card.GetComponent <CardBehaviourScript>();

            if (card.canPlay)
            {
                float changeToAttackhero = Random.value;

                if (changeToAttackhero < 0.50f)
                {
                    card.AttackHero(card, MyHero, true, delegate
                    {
                        card.canPlay = false;
                    });
                }
                else if (MyTableCards.Count > 0)
                {
                    int        random       = Random.Range(0, MyTableCards.Count);
                    GameObject CardToAttack = MyTableCards[random];

                    attacks.Add(card, CardToAttack.GetComponent <CardBehaviourScript>());
                }
            }
        }

        foreach (DictionaryEntry row in attacks)
        {
            CardBehaviourScript tempCard = row.Key as CardBehaviourScript;
            CardBehaviourScript temp2    = row.Value as CardBehaviourScript;

            if (tempCard.cardtype == CardBehaviourScript.CardType.Monster)
            {
                tempCard.AttackCard(tempCard, temp2, true, delegate
                {
                    tempCard.canPlay = false;
                });
            }
            else if (tempCard.cardtype == CardBehaviourScript.CardType.Magic)
            {
                tempCard.AddToMonster(tempCard, temp2, true, delegate
                {
                    tempCard.canPlay = false;
                    tempCard.Destroy(tempCard);
                });
            }
        }
        #endregion
    }