public void CardAttackHero(CardBehaviourScript _attacker, HeroBehaviourScript _target) { CardBehaviourScript attacker = AITableCards.Find(item => item._name == _attacker._name); Action a; a.Card1 = attacker._name; a.Card2 = ""; a.Hero = _target._name; a.OpCode = 2; Actions.Enqueue(a); attacker.AttackHero(attacker, PlayerHero, false, delegate { attacker.canPlay = false; }); }
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 }