/silverfish_control.cs
C# | 13779 lines | 11393 code | 1907 blank | 479 comment | 3665 complexity | 7ba55afcfdd4068b47dd83f15c5fa223 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- using HREngine.API;
- using HREngine.API.Actions;
- using HREngine.API.Utilities;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- //using System.Linq;
-
- namespace HREngine.Bots
- {
-
- public class Bot : IBot
- {
-
- private int dirtytarget=-1;
- PenalityManager penman = PenalityManager.Instance;
- Silverfish sf;
- public Bot()
- {
- OnBattleStateUpdate = HandleOnBattleStateUpdate;
- OnMulliganStateUpdate = HandleBattleMulliganPhase;
- this.sf = new Silverfish();
- sf.setnewLoggFile();
- //Ai.Instance.autoTester(this);
- //Ai.Instance.autoTesterParallel(this);
- }
- public int getPlayfieldValue(Playfield p)
- {
- int retval = 0;
- retval -= p.evaluatePenality;
- retval += p.owncards.Count * 1;
- retval += p.ownMaxMana;
- retval -= p.enemyMaxMana;
- retval += p.ownMinions.Count * 10 / (p.mana + 1);
- retval -= p.enemyMinions.Count * 10 / (p.mana + 1);
- if (p.ownHeroHp + p.ownHeroDefence > 10)
- {
- retval += p.ownHeroHp + p.ownHeroDefence;
- }
- else
- {
- retval -= (11 - p.ownHeroHp - p.ownHeroDefence) * (11 - p.ownHeroHp - p.ownHeroDefence);
- }
- retval += -p.enemyHeroHp - p.enemyHeroDefence;
- retval += p.ownWeaponAttack;// +ownWeaponDurability;
- if (!p.enemyHeroFrozen)
- {
- retval -= p.enemyWeaponDurability * p.enemyWeaponAttack;
- }
- else
- {
- if (p.enemyWeaponDurability >= 1)
- {
- retval += 12;
- }
- }
- retval += p.owncarddraw * 5;
- retval -= p.enemycarddraw * 5;
- retval += p.ownMaxMana;
- if (p.enemyMinions.Count >= 0)
- {
- int anz = p.enemyMinions.Count;
- int owntaunt = p.ownMinions.FindAll(x => x.taunt == true).Count;
- int froggs = p.ownMinions.FindAll(x => x.name == "frog").Count;
- owntaunt -= froggs;
- if (owntaunt == 0) retval -= 10 * anz;
- retval += owntaunt * 10 - 11 * anz;
- }
- int playmobs = 0;
- foreach (Action a in p.playactions)
- {
- if (a.useability && a.card.name == "lesserheal" && ((a.enemytarget >= 10 && a.enemytarget <= 20) || a.enemytarget == 200)) retval -= 5;
- if (!a.cardplay) continue;
- if (a.card.type == CardDB.cardtype.MOB) playmobs++;
- //if (a.card.name == "arcanemissiles" && a.numEnemysBeforePlayed == 0) retval -= 10; // arkane missles on enemy hero is bad :D
- if (a.card.name == "flamestrike" && a.numEnemysBeforePlayed <= 2) retval -= 20;
- //save spell for all classes: (except for rouge if he has no combo)
- if (p.ownHeroName != "thief" && a.card.type == CardDB.cardtype.SPELL && (a.numEnemysBeforePlayed == 0 || a.enemytarget == 200)) retval -= 11;
- if (p.ownHeroName == "thief" && a.card.type == CardDB.cardtype.SPELL && (a.enemytarget == 200)) retval -= 11;
- }
- int mobsInHand = 0;
- foreach (Handmanager.Handcard hc in p.owncards)
- {
- if (hc.card.type == CardDB.cardtype.MOB) mobsInHand++;
- }
- if (p.ownMinions.Count - p.enemyMinions.Count >= 4 && mobsInHand >= 1)
- {
- retval += mobsInHand * 20;
- }
- foreach (Minion m in p.ownMinions)
- {
- retval += m.Hp * 1;
- retval += m.Angr * 2;
- retval += m.card.rarity;
- if (m.windfury) retval += m.Angr;
- if (m.divineshild) retval += 1;
- if (m.stealth) retval += 1;
- //if (m.poisonous) retval += 1;
- if (m.divineshild && m.taunt) retval += 4;
- }
- foreach (Minion m in p.enemyMinions)
- {
- retval -= m.Hp * 2;
- if (!m.frozen)
- {
- retval -= m.Angr * 2;
- if (m.windfury) retval -= m.Angr;
- }
- retval -= m.card.rarity;
- if (m.taunt) retval -= 5;
- if (m.divineshild) retval -= 1;
- if (m.stealth) retval -= 1;
- if (m.poisonous) retval -= 4;
- if (penman.priorityTargets.ContainsKey(m.name) && !m.silenced) retval -= penman.priorityTargets[m.name];
- if (m.Angr >= 4) retval -= 20;
- if (m.Angr >= 7) retval -= 50;
- }
- retval -= p.enemySecretCount;
- retval -= p.lostDamage;//damage which was to high (like killing a 2/1 with an 3/3 -> => lostdamage =2
- retval -= p.lostWeaponDamage;
- if (p.ownMinions.Count == 0) retval -= 20;
- if (p.enemyMinions.Count == 0) retval += 20;
- if (p.enemyHeroHp <= 0) retval = 10000;
- //soulfire etc
- int deletecardsAtLast = 0;
- foreach (Action a in p.playactions)
- {
- if (!a.cardplay) continue;
- if (a.card.name == "soulfire" || a.card.name == "doomguard" || a.card.name == "succubus") deletecardsAtLast = 1;
- if (deletecardsAtLast == 1 && !(a.card.name == "soulfire" || a.card.name == "doomguard" || a.card.name == "succubus")) retval -= 20;
- }
- if (p.enemyHeroHp >= 1 && p.ownHeroHp + p.ownHeroDefence - p.guessingHeroDamage <= 0) retval -= 1000;
- if (p.ownHeroHp <= 0) retval = -10000;
- p.value = retval;
- return retval;
- }
- private HREngine.API.Actions.ActionBase HandleBattleMulliganPhase()
- {
- HRLog.Write("handle mulligan");
- if (HRMulligan.IsMulliganActive())
- {
- var list = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND);
- foreach (var item in list)
- {
- if (item.GetEntity().GetCost() >= 4)
- {
- HRLog.Write("Rejecting Mulligan Card " + item.GetEntity().GetName() + " because it cost is >= 4.");
- HRMulligan.ToggleCard(item);
- }
- }
- sf.setnewLoggFile();
- return null;
- //HRMulligan.EndMulligan();
- }
- return null;
- }
- /// <summary>
- /// [EN]
- /// This handler is executed when the local player turn is active.
- ///
- /// [DE]
- /// Dieses Event wird ausgelöst wenn der Spieler am Zug ist.
- /// </summary>
- private HREngine.API.Actions.ActionBase HandleOnBattleStateUpdate()
- {
-
- try
- {
- if (HRBattle.IsInTargetMode() && dirtytarget >= 0)
- {
- HRLog.Write("dirty targeting...");
- HREntity target = getEntityWithNumber(dirtytarget);
- dirtytarget = -1;
- return new HREngine.API.Actions.TargetAction(target);
- }
-
-
- //SafeHandleBattleLocalPlayerTurnHandler();
- sf.updateEverything(this);
- Action moveTodo = Ai.Instance.bestmove;
- if (moveTodo == null)
- {
- HRLog.Write("end turn");
- return null;
- }
- HRLog.Write("play action");
- moveTodo.print();
- if (moveTodo.cardplay)
- {
- HRCard cardtoplay = getCardWithNumber(moveTodo.cardEntitiy);
- if (moveTodo.enemytarget >= 0)
- {
- HREntity target = getEntityWithNumber(moveTodo.enemyEntitiy);
- HRLog.Write("play: " + cardtoplay.GetEntity().GetName() + " target: " + target.GetName() + " " + (moveTodo.owntarget+1));
- Helpfunctions.Instance.logg("play: " + cardtoplay.GetEntity().GetName() + " target: " + target.GetName());
- if (moveTodo.card.type == CardDB.cardtype.MOB)
- {
- return new HREngine.API.Actions.PlayCardAction(cardtoplay, target, moveTodo.owntarget + 1);
- }
- return new HREngine.API.Actions.PlayCardAction(cardtoplay, target);
- }
- else
- {
- HRLog.Write("play: " + cardtoplay.GetEntity().GetName() + " target nothing" + " " + (moveTodo.owntarget + 1));
- if (moveTodo.card.type == CardDB.cardtype.MOB)
- {
- return new HREngine.API.Actions.PlayCardAction(cardtoplay, null, moveTodo.owntarget + 1);
- }
- return new HREngine.API.Actions.PlayCardAction(cardtoplay);
- }
-
- }
- if (moveTodo.minionplay )
- {
- HREntity attacker = getEntityWithNumber(moveTodo.ownEntitiy);
- HREntity target = getEntityWithNumber(moveTodo.enemyEntitiy);
- HRLog.Write("minion attack: " + attacker.GetName() + " target: " + target.GetName());
- Helpfunctions.Instance.logg("minion attack: " + attacker.GetName() + " target: " + target.GetName());
- return new HREngine.API.Actions.AttackAction(attacker,target);
- }
- if (moveTodo.heroattack)
- {
- HREntity attacker = getEntityWithNumber(moveTodo.ownEntitiy);
- HREntity target = getEntityWithNumber(moveTodo.enemyEntitiy);
- this.dirtytarget = moveTodo.enemyEntitiy;
- //HRLog.Write("heroattack: attkr:" + moveTodo.ownEntitiy + " defender: " + moveTodo.enemyEntitiy);
- HRLog.Write("heroattack: " + attacker.GetName() + " target: " + target.GetName());
- Helpfunctions.Instance.logg("heroattack: " + attacker.GetName() + " target: " + target.GetName());
- if (HRPlayer.GetLocalPlayer().HasWeapon())
- {
- HRLog.Write("hero attack with weapon");
- return new HREngine.API.Actions.AttackAction(HRPlayer.GetLocalPlayer().GetWeaponCard().GetEntity(), target);
- }
- HRLog.Write("hero attack without weapon");
- return new HREngine.API.Actions.AttackAction(HRPlayer.GetLocalPlayer().GetHero(), target);
- }
- if (moveTodo.useability)
- {
- HRCard cardtoplay = HRPlayer.GetLocalPlayer().GetHeroPower().GetCard();
- if (moveTodo.enemytarget >= 0)
- {
- HREntity target = getEntityWithNumber(moveTodo.enemyEntitiy);
- HRLog.Write("use ablitiy: " + cardtoplay.GetEntity().GetName() + " target " + target.GetName());
- Helpfunctions.Instance.logg("use ablitiy: " + cardtoplay.GetEntity().GetName() + " target " + target.GetName());
- return new HREngine.API.Actions.PlayCardAction(cardtoplay, target);
- }
- else
- {
- HRLog.Write("use ablitiy: " + cardtoplay.GetEntity().GetName() + " target nothing");
- Helpfunctions.Instance.logg("use ablitiy: " + cardtoplay.GetEntity().GetName() + " target nothing");
- return new HREngine.API.Actions.PlayCardAction(cardtoplay);
- }
- }
- }
- catch (Exception Exception)
- {
- HRLog.Write(Exception.Message);
- HRLog.Write(Environment.StackTrace);
- }
- return null;
- //HRBattle.FinishRound();
- }
- private HREntity getEntityWithNumber(int number)
- {
- foreach (HREntity e in this.getallEntitys())
- {
- if (number == e.GetEntityId()) return e;
- }
- return null;
- }
- private HRCard getCardWithNumber(int number)
- {
- foreach (HRCard e in this.getallHandCards())
- {
- if (number == e.GetEntity().GetEntityId()) return e;
- }
- return null;
- }
- private List<HREntity> getallEntitys()
- {
- List<HREntity> result = new List<HREntity>();
- HREntity ownhero = HRPlayer.GetLocalPlayer().GetHero();
- HREntity enemyhero = HRPlayer.GetEnemyPlayer().GetHero();
- HREntity ownHeroAbility = HRPlayer.GetLocalPlayer().GetHeroPower();
- List<HRCard> list2 = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.PLAY);
- List<HRCard> list3 = HRCard.GetCards(HRPlayer.GetEnemyPlayer(), HRCardZone.PLAY);
- result.Add(ownhero);
- result.Add(enemyhero);
- result.Add(ownHeroAbility);
- foreach (HRCard item in list2)
- {
- result.Add(item.GetEntity());
- }
- foreach (HRCard item in list3)
- {
- result.Add(item.GetEntity());
- }
-
-
- return result;
- }
- private List<HRCard> getallHandCards()
- {
- List<HRCard> list = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND);
- return list;
- }
- protected virtual void SafeHandleBattleLocalPlayerTurnHandler()
- {
-
- }
- protected virtual HRCard GetMinionByPriority(HRCard lastMinion = null)
- {
- return null;
- }
-
- }
- public class Silverfish
- {
- private bool singleLog = false;
- Settings sttngs = Settings.Instance;
- List<Minion> ownMinions = new List<Minion>();
- List<Minion> enemyMinions = new List<Minion>();
- List<Handmanager.Handcard> handCards = new List<Handmanager.Handcard>();
- int ownPlayerController = 0;
- List<string> ownSecretList = new List<string>();
- int enemySecretCount = 0;
- int currentMana = 0;
- int ownMaxMana = 0;
- int numMinionsPlayedThisTurn = 0;
- int cardsPlayedThisTurn = 0;
- int ueberladung = 0;
- string ownHeroWeapon = "";
- int heroWeaponAttack = 0;
- int heroWeaponDurability = 0;
- bool heroImmuneToDamageWhileAttacking = false;
- string enemyHeroWeapon = "";
- int enemyWeaponAttack = 0;
- int enemyWeaponDurability = 0;
- int heroAtk = 0;
- int heroHp = 30;
- int heroDefence = 0;
- string heroname = "";
- bool ownheroisread = false;
- int heroNumAttacksThisTurn = 0;
- bool heroHasWindfury = false;
- bool herofrozen = false;
- int enemyAtk = 0;
- int enemyHp = 30;
- string enemyHeroname = "";
- int enemyDefence = 0;
- bool enemyfrozen = false;
- CardDB.Card heroAbility = new CardDB.Card();
- bool ownAbilityisReady = false;
- int anzcards = 0;
- int enemyAnzCards = 0;
- int ownHeroFatigue = 0;
- int enemyHeroFatigue = 0;
- int ownDecksize = 0;
- int enemyDecksize = 0;
- private Dictionary<int, HRCard> RejectedCardList;
- private PlayCardAction NextFixedAction { get; set; }
- public Silverfish()
- {
- HRLog.Write("init Silverfish");
- string path = (HRSettings.Get.CustomRuleFilePath).Remove(HRSettings.Get.CustomRuleFilePath.Length - 13) + "UltimateLogs" + System.IO.Path.DirectorySeparatorChar;
- System.IO.Directory.CreateDirectory(path);
- sttngs.setFilePath((HRSettings.Get.CustomRuleFilePath).Remove(HRSettings.Get.CustomRuleFilePath.Length - 13));
- if (!singleLog)
- {
- sttngs.setLoggPath(path);
- }
- else
- {
- sttngs.setLoggPath((HRSettings.Get.CustomRuleFilePath).Remove(HRSettings.Get.CustomRuleFilePath.Length - 13));
- sttngs.setLoggFile("UILogg.txt");
- Helpfunctions.Instance.createNewLoggfile();
- }
- /*OnBattleStateUpdate = UpdateBattleState;
- OnMulliganStateUpdate = UpdateMulliganState;
- RejectedCardList = new Dictionary<int, HRCard>();
- NextFixedAction = null;*/
- }
- public void setnewLoggFile()
- {
- if (!singleLog)
- {
- sttngs.setLoggFile("UILogg" + DateTime.Now.ToString("_yyyy-MM-dd_HH-mm-ss") + ".txt");
- Helpfunctions.Instance.createNewLoggfile();
- }
- else
- {
- sttngs.setLoggFile("UILogg.txt");
- }
- }
- public void updateEverything(Bot botbase)
- {
- HRPlayer ownPlayer = HRPlayer.GetLocalPlayer();
- HRPlayer enemyPlayer = HRPlayer.GetEnemyPlayer();
- ownPlayerController = ownPlayer.GetHero().GetControllerId();//ownPlayer.GetHero().GetControllerId()
- // create hero + minion data
- getHerostuff();
- getMinions();
- getHandcards();
- // send ai the data:
- Hrtprozis.Instance.clearAll();
- Handmanager.Instance.clearAll();
- Hrtprozis.Instance.setOwnPlayer(ownPlayerController);
- Handmanager.Instance.setOwnPlayer(ownPlayerController);
- Hrtprozis.Instance.updatePlayer(this.ownMaxMana, this.currentMana, this.cardsPlayedThisTurn, this.numMinionsPlayedThisTurn, this.ueberladung, ownPlayer.GetHero().GetEntityId(), enemyPlayer.GetHero().GetEntityId());
- Hrtprozis.Instance.updateSecretStuff(this.ownSecretList, this.enemySecretCount);
- Hrtprozis.Instance.updateOwnHero(this.ownHeroWeapon, this.heroWeaponAttack, this.heroWeaponDurability, this.heroImmuneToDamageWhileAttacking, this.heroAtk, this.heroHp, this.heroDefence, this.heroname, this.ownheroisread, this.herofrozen, this.heroAbility, this.ownAbilityisReady, this.heroNumAttacksThisTurn, this.heroHasWindfury);
- Hrtprozis.Instance.updateEnemyHero(this.enemyHeroWeapon, this.enemyWeaponAttack, this.enemyWeaponDurability, this.enemyAtk, this.enemyHp, this.enemyDefence, this.enemyHeroname, this.enemyfrozen);
- Hrtprozis.Instance.updateMinions(this.ownMinions, this.enemyMinions);
- Handmanager.Instance.setHandcards(this.handCards, this.anzcards, this.enemyAnzCards);
- Hrtprozis.Instance.updateFatigueStats(this.ownDecksize, this.ownHeroFatigue, this.enemyDecksize, this.enemyHeroFatigue);
- // print data
- Hrtprozis.Instance.printHero();
- Hrtprozis.Instance.printOwnMinions();
- Hrtprozis.Instance.printEnemyMinions();
- Handmanager.Instance.printcards();
- // calculate stuff
- HRLog.Write("calculating stuff...");
- Ai.Instance.dosomethingclever(botbase);
- HRLog.Write("calculating ended!");
- }
- private void getHerostuff()
- {
- HRPlayer ownPlayer = HRPlayer.GetLocalPlayer();
- HRPlayer enemyPlayer = HRPlayer.GetEnemyPlayer();
- HREntity ownhero = ownPlayer.GetHero();
- HREntity enemyhero = enemyPlayer.GetHero();
- HREntity ownHeroAbility = ownPlayer.GetHeroPower();
- //player stuff#########################
- //this.currentMana =ownPlayer.GetTag(HRGameTag.RESOURCES) - ownPlayer.GetTag(HRGameTag.RESOURCES_USED) + ownPlayer.GetTag(HRGameTag.TEMP_RESOURCES);
- this.currentMana = ownPlayer.GetNumAvailableResources();
- this.ownMaxMana = ownPlayer.GetTag(HRGameTag.RESOURCES);//ownPlayer.GetRealTimeTempMana();
- Helpfunctions.Instance.logg("#######################################################################");
- Helpfunctions.Instance.logg("#######################################################################");
- Helpfunctions.Instance.logg("start calculations, current time: " + DateTime.Now.ToString("HH:mm:ss"));
- Helpfunctions.Instance.logg("#######################################################################");
- Helpfunctions.Instance.logg("mana " + currentMana + "/" + ownMaxMana);
- Helpfunctions.Instance.logg("own secretsCount: " + ownPlayer.GetSecretDefinitions().Count);
- enemySecretCount = HRCard.GetCards(enemyPlayer, HRCardZone.SECRET).Count;
- enemySecretCount = 0;
- Helpfunctions.Instance.logg("enemy secretsCount: " + enemySecretCount);
- this.ownSecretList = ownPlayer.GetSecretDefinitions();
- this.numMinionsPlayedThisTurn = ownPlayer.GetTag(HRGameTag.NUM_MINIONS_PLAYED_THIS_TURN);
- this.cardsPlayedThisTurn = ownPlayer.GetTag(HRGameTag.NUM_CARDS_PLAYED_THIS_TURN);
- //if (ownPlayer.HasCombo()) this.cardsPlayedThisTurn = 1;
- this.ueberladung = ownPlayer.GetTag(HRGameTag.RECALL_OWED);
- //get weapon stuff
- this.ownHeroWeapon = "";
- this.heroWeaponAttack = 0;
- this.heroWeaponDurability = 0;
- this.ownHeroFatigue = ownhero.GetFatigue();
- this.enemyHeroFatigue = enemyhero.GetFatigue();
- //this.ownDecksize = HRCard.GetCards(ownPlayer, HRCardZone.DECK).Count;
- //this.enemyDecksize = HRCard.GetCards(enemyPlayer, HRCardZone.DECK).Count;
- this.enemyHeroWeapon = "";
- this.enemyWeaponAttack = 0;
- this.enemyWeaponDurability = 0;
- if (enemyPlayer.HasWeapon())
- {
- HREntity weapon = enemyPlayer.GetWeaponCard().GetEntity();
- this.enemyHeroWeapon = CardDB.Instance.getCardDataFromID(weapon.GetCardId()).name;
- this.enemyWeaponAttack = weapon.GetATK();
- this.enemyWeaponDurability = weapon.GetDurability();
- }
- //own hero stuff###########################
- this.heroAtk = ownhero.GetATK();
- this.heroHp = ownhero.GetHealth() - ownhero.GetDamage();
- this.heroDefence = ownhero.GetArmor();
- this.heroname = Hrtprozis.Instance.heroIDtoName(ownhero.GetCardId());
- bool exausted = false;
- exausted = ownhero.IsExhausted();
- this.ownheroisread = true;
- this.heroImmuneToDamageWhileAttacking = (ownhero.IsImmune()) ? true : false;
- this.herofrozen = ownhero.IsFrozen();
- this.heroNumAttacksThisTurn = ownhero.GetNumAttacksThisTurn();
- this.heroHasWindfury = ownhero.HasWindfury();
- //int numberofattacks = ownhero.GetNumAttacksThisTurn();
- //HRLog.Write(ownhero.GetName() + " ready params ex: " + exausted + " " + heroAtk + " " + numberofattacks + " " + herofrozen);
- if (exausted == true)
- {
- this.ownheroisread = false;
- }
- if (exausted == false && this.heroAtk == 0)
- {
- this.ownheroisread = false;
- }
- if (herofrozen) ownheroisread = false;
- if (ownPlayer.HasWeapon())
- {
- HREntity weapon = ownPlayer.GetWeaponCard().GetEntity();
- this.ownHeroWeapon = CardDB.Instance.getCardDataFromID(weapon.GetCardId()).name;
- this.heroWeaponAttack = weapon.GetATK();
- this.heroWeaponDurability = weapon.GetTag(HRGameTag.DURABILITY) - weapon.GetTag(HRGameTag.DAMAGE);//weapon.GetDurability();
- this.heroImmuneToDamageWhileAttacking = false;
- if (this.ownHeroWeapon == "gladiatorslongbow")
- {
- this.heroImmuneToDamageWhileAttacking = true;
- }
- //HRLog.Write("weapon: " + ownHeroWeapon + " " + heroWeaponAttack + " " + heroWeaponDurability);
- }
- //enemy hero stuff###############################################################
- this.enemyAtk = enemyhero.GetATK();
- this.enemyHp = enemyhero.GetHealth() - enemyhero.GetDamage();
- this.enemyHeroname = Hrtprozis.Instance.heroIDtoName(enemyhero.GetCardId());
- this.enemyDefence = enemyhero.GetArmor();
- this.enemyfrozen = enemyhero.IsFrozen();
- //own hero ablity stuff###########################################################
- this.heroAbility = CardDB.Instance.getCardDataFromID(ownHeroAbility.GetCardId());
- this.ownAbilityisReady = (ownHeroAbility.IsExhausted()) ? false : true; // if exhausted, ability is NOT ready
- }
- private void getMinions()
- {
- ownMinions.Clear();
- enemyMinions.Clear();
- HRPlayer ownPlayer = HRPlayer.GetLocalPlayer();
- HRPlayer enemyPlayer = HRPlayer.GetEnemyPlayer();
- // ALL minions on Playfield:
- List<HRCard> list = HRCard.GetCards(ownPlayer, HRCardZone.PLAY);
- list.AddRange(HRCard.GetCards(enemyPlayer, HRCardZone.PLAY));
- List<HREntity> enchantments = new List<HREntity>();
- foreach (HRCard item in list)
- {
- HREntity entitiy = item.GetEntity();
- int zp = entitiy.GetZonePosition();
- if (entitiy.GetCardType() == HRCardType.MINION && zp >= 1)
- {
- //HRLog.Write("zonepos " + zp);
- CardDB.Card c = CardDB.Instance.getCardDataFromID(entitiy.GetCardId());
- Minion m = new Minion();
- m.name = c.name;
- m.card = c;
- m.Angr = entitiy.GetATK();
- m.maxHp = entitiy.GetHealth();
- m.Hp = m.maxHp - entitiy.GetDamage();
- m.wounded = false;
- if (m.maxHp > m.Hp) m.wounded = true;
- m.exhausted = entitiy.IsExhausted();
- m.taunt = (entitiy.HasTaunt()) ? true : false;
- m.charge = (entitiy.HasCharge()) ? true : false;
- m.numAttacksThisTurn = entitiy.GetNumAttacksThisTurn();
- int temp = entitiy.GetNumTurnsInPlay();
- m.playedThisTurn = (temp == 0) ? true : false;
- m.windfury = (entitiy.HasWindfury()) ? true : false;
- m.frozen = (entitiy.IsFrozen()) ? true : false;
- m.divineshild = (entitiy.HasDivineShield()) ? true : false;
- m.stealth = (entitiy.IsStealthed()) ? true : false;
- m.poisonous = (entitiy.IsPoisonous()) ? true : false;
- m.immune = (entitiy.IsImmune()) ? true : false;
- m.silenced = (entitiy.GetTag(HRGameTag.SILENCED) >= 1) ? true : false;
- m.zonepos = zp;
- m.id = m.zonepos - 1;
- m.entitiyID = entitiy.GetEntityId();
- m.enchantments.Clear();
- //HRLog.Write( m.name + " ready params ex: " + m.exhausted + " charge: " +m.charge + " attcksthisturn: " + m.numAttacksThisTurn + " playedthisturn " + m.playedThisTurn );
- m.Ready = false; // if exhausted, he is NOT ready
- if (!m.playedThisTurn && !m.exhausted && !m.frozen && (m.numAttacksThisTurn == 0 || (m.numAttacksThisTurn == 1 && m.windfury)))
- {
- m.Ready = true;
- }
- if (m.playedThisTurn && m.charge && (m.numAttacksThisTurn == 0 || (m.numAttacksThisTurn == 1 && m.windfury)))
- {
- //m.exhausted = false;
- m.Ready = true;
- }
- if (!m.silenced && (m.name == "ancientwatcher" || m.name == "ragnarosthefirelord"))
- {
- m.Ready = false;
- }
- if (entitiy.GetControllerId() == this.ownPlayerController) // OWN minion
- {
- this.ownMinions.Add(m);
- }
- else
- {
- this.enemyMinions.Add(m);
- }
- }
- // minions added
- if (entitiy.GetCardType() == HRCardType.WEAPON)
- {
- //HRLog.Write("found weapon!");
- if (entitiy.GetControllerId() == this.ownPlayerController) // OWN weapon
- {
- this.ownHeroWeapon = CardDB.Instance.getCardDataFromID(entitiy.GetCardId()).name;
- this.heroWeaponAttack = entitiy.GetATK();
- this.heroWeaponDurability = entitiy.GetDurability();
- //this.heroImmuneToDamageWhileAttacking = false;
- }
- else
- {
- this.enemyHeroWeapon = CardDB.Instance.getCardDataFromID(entitiy.GetCardId()).name;
- this.enemyWeaponAttack = entitiy.GetATK();
- this.enemyWeaponDurability = entitiy.GetDurability();
- }
- }
- if (entitiy.GetCardType() == HRCardType.ENCHANTMENT)
- {
- enchantments.Add(entitiy);
- }
- }
- foreach (HRCard item in list)
- {
- foreach (HREntity e in item.GetEntity().GetEnchantments())
- {
- enchantments.Add(e);
- }
- }
- // add enchantments to minions
- setEnchantments(enchantments);
- }
- private void setEnchantments(List<HREntity> enchantments)
- {
- foreach (HREntity bhu in enchantments)
- {
- //create enchantment
- Enchantment ench = CardDB.getEnchantmentFromCardID(bhu.GetCardId());
- ench.creator = bhu.GetCreatorId();
- ench.controllerOfCreator = bhu.GetControllerId();
- ench.cantBeDispelled = false;
- //if (bhu.c) ench.cantBeDispelled = true;
- foreach (Minion m in this.ownMinions)
- {
- if (m.entitiyID == bhu.GetAttached())
- {
- m.enchantments.Add(ench);
- //HRLog.Write("add enchantment " +bhu.GetCardId()+" to: " + m.entitiyID);
- }
- }
- foreach (Minion m in this.enemyMinions)
- {
- if (m.entitiyID == bhu.GetAttached())
- {
- m.enchantments.Add(ench);
- }
- }
- }
- }
- private void getHandcards()
- {
- handCards.Clear();
- this.anzcards = 0;
- this.enemyAnzCards = 0;
- List<HRCard> list = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND);
- list.AddRange(HRCard.GetCards(HRPlayer.GetEnemyPlayer(), HRCardZone.HAND));
- foreach (HRCard item in list)
- {
- HREntity entitiy = item.GetEntity();
- if (entitiy.GetControllerId() == this.ownPlayerController && entitiy.GetZonePosition() >= 1) // own handcard
- {
- CardDB.Card c = CardDB.Instance.getCardDataFromID(entitiy.GetCardId());
- c.cost = entitiy.GetCost();
- c.entityID = entitiy.GetEntityId();
- Handmanager.Handcard hc = new Handmanager.Handcard();
- hc.card = c;
- hc.position = entitiy.GetZonePosition();
- hc.entity = entitiy.GetEntityId();
- handCards.Add(hc);
- this.anzcards++;
- }
- if (entitiy.GetControllerId() != this.ownPlayerController && entitiy.GetZonePosition() >= 1) // enemy handcard
- {
- this.enemyAnzCards++;
- }
- }
- }
- }
- // the ai :D
- //please ask/write me if you use this in your project
- public class Action
- {
- public bool cardplay = false;
- public bool heroattack = false;
- public bool useability = false;
- public bool minionplay = false;
- public CardDB.Card card;
- public int cardEntitiy = -1;
- public int owntarget = -1; //= target where card/minion is placed
- public int ownEntitiy = -1;
- public int enemytarget = -1; // target where red arrow is placed
- public int enemyEntitiy = -1;
- public int druidchoice = 0; // 1 left card, 2 right card
- public int numEnemysBeforePlayed = 0;
- public bool comboBeforePlayed = false;
- public void print()
- {
- Helpfunctions help = Helpfunctions.Instance;
- help.logg("current Action: ");
- if (this.cardplay)
- {
- help.logg("play " + this.card.name);
- if (this.druidchoice >= 1) help.logg("choose choise " + this.druidchoice);
- help.logg("with position " + this.cardEntitiy);
- if (this.owntarget >= 0)
- {
- help.logg("on position " + this.ownEntitiy);
- }
- if (this.enemytarget >= 0)
- {
- help.logg("and target to " + this.enemytarget + " " + this.enemyEntitiy);
- }
- }
- if (this.minionplay)
- {
- help.logg("attacker: " + this.owntarget + " enemy: " + this.enemytarget);
- help.logg("targetplace " + this.enemyEntitiy);
- }
- if (this.heroattack)
- {
- help.logg("attack with hero, enemy: " + this.enemytarget);
- help.logg("targetplace " + this.enemyEntitiy);
- }
- if (this.useability)
- {
- help.logg("useability ");
- if (this.enemytarget >= 0)
- {
- help.logg("on enemy: " + this.enemytarget + "targetplace " + this.enemyEntitiy);
- }
- }
- help.logg("");
- }
- }
- public class Playfield
- {
- public bool logging = false;
- public int evaluatePenality = 0;
- public int ownController = 0;
- public int ownHeroEntity = -1;
- public int enemyHeroEntity = -1;
- public int value = Int32.MinValue;
- public int guessingHeroDamage = 0;
- public int mana = 0;
- public int enemyHeroHp = 30;
- public string ownHeroName = "";
- public string enemyHeroName = "";
- public bool ownHeroReady = false;
- public int ownHeroNumAttackThisTurn = 0;
- public bool ownHeroWindfury = false;
- public List<string> ownSecretsIDList = new List<string>();
- public int enemySecretCount = 0;
- public int ownHeroHp = 30;
- public int ownheroAngr = 0;
- public bool ownHeroFrozen = false;
- public bool enemyHeroFrozen = false;
- public bool heroImmuneWhileAttacking = false;
- public int ownWeaponDurability = 0;
- public int ownWeaponAttack = 0;
- public string ownWeaponName = "";
- public int enemyWeaponAttack = 0;
- public int enemyWeaponDurability = 0;
- public List<Minion> ownMinions = new List<Minion>();
- public List<Minion> enemyMinions = new List<Minion>();
- public List<Handmanager.Handcard> owncards = new List<Handmanager.Handcard>();
- public List<Action> playactions = new List<Action>();
- public bool complete = false;
- public int owncarddraw = 0;
- public int ownHeroDefence = 0;
- public int enemycarddraw = 0;
- public int enemyAnzCards = 0;
- public int enemyHeroDefence = 0;
- public bool ownAbilityReady = false;
- public int doublepriest = 0;
- public int spellpower = 0;
- public bool auchenaiseelenpriesterin = false;
- public bool playedmagierinderkirintor = false;
- public bool playedPreparation = false;
- public int winzigebeschwoererin = 0;
- public int startedWithWinzigebeschwoererin = 0;
- public int zauberlehrling = 0;
- public int startedWithZauberlehrling = 0;
- public int managespenst = 0;
- public int startedWithManagespenst = 0;
- public int soeldnerDerVenture = 0;
- public int startedWithsoeldnerDerVenture = 0;
- public int beschwoerungsportal = 0;
- public int startedWithbeschwoerungsportal = 0;
- public int ownWeaponAttackStarted = 0;
- public int ownMobsCountStarted = 0;
- public int ownCardsCountStarted = 0;
- public int ownHeroHpStarted = 30;
- public int enemyHeroHpStarted = 30;
- public int mobsplayedThisTurn = 0;
- public int startedWithMobsPlayedThisTurn = 0;
- public int cardsPlayedThisTurn = 0;
- public int ueberladung = 0; //=recall
- public int ownMaxMana = 0;
- public int enemyMaxMana = 0;
- public int lostDamage = 0;
- public int lostHeal = 0;
- public int lostWeaponDamage = 0;
- public int ownDeckSize = 0;
- public int enemyDeckSize = 0;
- public int ownHeroFatigue = 0;
- public int enemyHeroFatigue = 0;
- public CardDB.Card ownHeroAblility;
- Helpfunctions help = Helpfunctions.Instance;
- private void addMinionsReal(List<Minion> source, List<Minion> trgt)
- {
- foreach (Minion m in source)
- {
- Minion mc = new Minion(m);
- trgt.Add(mc);
- }
- }
- private void addCardsReal(List<Handmanager.Handcard> source)
- {
- foreach (Handmanager.Handcard m in source)
- {
- Handmanager.Handcard mc = new Handmanager.Handcard();
- mc.card = new CardDB.Card(m.card);
- mc.position = m.position;
- mc.entity = m.entity;
- this.owncards.Add(mc);
- }
- }
- public Playfield()
- {
- this.ownController = Hrtprozis.Instance.getOwnController();
- this.ownHeroEntity = Hrtprozis.Instance.ownHeroEntity;
- this.enemyHeroEntity = Hrtprozis.Instance.enemyHeroEntitiy;
- this.mana = Hrtprozis.Instance.currentMana;
- this.ownMaxMana = Hrtprozis.Instance.ownMaxMana;
- this.enemyMaxMana = Hrtprozis.Instance.enemyMaxMana;
- this.evaluatePenality = 0;
- this.ownSecretsIDList = Hrtprozis.Instance.ownSecretList;
- this.enemySecretCount = Hrtprozis.Instance.enemySecretCount;
- addMinionsReal(Hrtprozis.Instance.ownMinions, ownMinions);
- addMinionsReal(Hrtprozis.Instance.enemyMinions, enemyMinions);
- addCardsReal(Handmanager.Instance.handCards);
- this.enemyHeroHp = Hrtprozis.Instance.enemyHp;
- this.ownHeroName = Hrtprozis.Instance.heroname;
- this.enemyHeroName = Hrtprozis.Instance.enemyHeroname;
- this.ownHeroHp = Hrtprozis.Instance.heroHp;
- this.complete = false;
- this.ownHeroReady = Hrtprozis.Instance.ownheroisread;
- this.ownHeroWindfury = Hrtprozis.Instance.ownHeroWindfury;
- this.ownHeroNumAttackThisTurn = Hrtprozis.Instance.ownHeroNumAttacksThisTurn;
- this.ownHeroFrozen = Hrtprozis.Instance.herofrozen;
- this.enemyHeroFrozen = Hrtprozis.Instance.enemyfrozen;
- this.ownheroAngr = Hrtprozis.Instance.heroAtk;
- this.heroImmuneWhileAttacking = Hrtprozis.Instance.heroImmuneToDamageWhileAttacking;
- this.ownWeaponDurability = Hrtprozis.Instance.heroWeaponDurability;
- this.ownWeaponAttack = Hrtprozis.Instance.heroWeaponAttack;
- this.ownWeaponName = Hrtprozis.Instance.ownHeroWeapon;
- this.owncarddraw = 0;
- this.ownHeroDefence = Hrtprozis.Instance.heroDefence;
- this.enemyHeroDefence = Hrtprozis.Instance.enemyDefence;
- this.enemyWeaponAttack = 0;//dont know jet
- this.enemyWeaponDurability = Hrtprozis.Instance.enemyWeaponDurability;
- this.enemycarddraw = 0;
- this.enemyAnzCards = Handmanager.Instance.enemyAnzCards;
- this.ownAbilityReady = Hrtprozis.Instance.ownAbilityisReady;
- this.ownHeroAblility = Hrtprozis.Instance.heroAbility;
- this.doublepriest = 0;
- this.spellpower = 0;
- value = -1000000;
- this.mobsplayedThisTurn = Hrtprozis.Instance.numMinionsPlayedThisTurn;
- this.startedWithMobsPlayedThisTurn = Hrtprozis.Instance.numMinionsPlayedThisTurn;// only change mobsplayedthisturm
- this.cardsPlayedThisTurn = Hrtprozis.Instance.cardsPlayedThisTurn;
- this.ueberladung = Hrtprozis.Instance.ueberladung;
- this.ownHeroFatigue = Hrtprozis.Instance.ownHeroFatigue;
- this.enemyHeroFatigue = Hrtprozis.Instance.enemyHeroFatigue;
- this.ownDeckSize = Hrtprozis.Instance.ownDeckSize;
- this.enemyDeckSize = Hrtprozis.Instance.enemyDeckSize;
- //need the following for manacost-calculation
- this.ownHeroHpStarted = this.ownHeroHp;
- this.enemyHeroHpStarted = this.enemyHeroHp;
- this.ownWeaponAttackStarted = this.ownWeaponAttack;
- this.ownCardsCountStarted = this.owncards.Count;
- this.ownMobsCountStarted = this.ownMinions.Count;
- this.playedmagierinderkirintor = false;
- this.playedPreparation = false;
- this.zauberlehrling = 0;
- this.winzigebeschwoererin = 0;
- this.managespenst = 0;
- this.soeldnerDerVenture = 0;
- this.beschwoerungsportal = 0;
- this.startedWithbeschwoerungsportal = 0;
- this.startedWithManagespenst = 0;
- this.startedWithWinzigebeschwoererin = 0;
- this.startedWithZauberlehrling = 0;
- this.startedWithsoeldnerDerVenture = 0;
- foreach (Minion m in this.ownMinions)
- {
- if (m.silenced) continue;
- if (m.name == "prophetvelen") this.doublepriest++;
- spellpower = spellpower + m.card.spellpowervalue;
- if (m.name == "auchenaisoulpriest") this.auchenaiseelenpriesterin = true;
- if (m.name == "pint-sizedsummoner")
- {
- this.winzigebeschwoererin++;
- this.startedWithWinzigebeschwoererin++;
- }
- if (m.name == "sorcerersapprentice")
- {
- this.zauberlehrling++;
- this.startedWithZauberlehrling++;
- }
- if (m.name == "manawraith")
- {
- this.managespenst++;
- this.startedWithManagespenst++;
- }
- if (m.name == "venturecomercenary")
- {
- this.soeldnerDerVenture++;
- this.startedWithsoeldnerDerVenture++;
- }
- if (m.name == "summoningportal")
- {
- this.beschwoerungsportal++;
- this.startedWithbeschwoerungsportal++;
- }
- foreach (Enchantment e in m.enchantments)// only at first init needed, after that its copied
- {
- if (e.CARDID == "NEW1_036e" || e.CARDID == "NEW1_036e2") m.cantLowerHPbelowONE = true;
- }
- }
- foreach (Minion m in this.enemyMinions)
- {
- if (m.silenced) continue;
- if (m.name == "manawraith")
- {
- this.managespenst++;
- this.startedWithManagespenst++;
- }
- }
- }
- public Playfield(Playfield p)
- {
- this.ownController = p.ownController;
- this.ownHeroEntity = p.ownHeroEntity;
- this.enemyHeroEntity = p.enemyHeroEntity;
- this.evaluatePenality = p.evaluatePenality;
- foreach (string s in p.ownSecretsIDList)
- { this.ownSecretsIDList.Add(s); }
- this.enemySecretCount = p.enemySecretCount;
- this.mana = p.mana;
- this.ownMaxMana = p.ownMaxMana;
- this.enemyMaxMana = p.enemyMaxMana;
- addMinionsReal(p.ownMinions, ownMinions);
- addMinionsReal(p.enemyMinions, enemyMinions);
- addCardsReal(p.owncards);
- this.enemyHeroHp = p.enemyHeroHp;
- this.ownHeroName = p.ownHeroName;
- this.enemyHeroName = p.enemyHeroName;
- this.ownHeroHp = p.ownHeroHp;
- this.playactions.AddRange(p.playactions);
- this.complete = false;
- this.ownHeroReady = p.ownHeroReady;
- this.ownHeroNumAttackThisTurn = p.ownHeroNumAttackThisTurn;
- this.ownHeroWindfury = p.ownHeroWindfury;
- this.ownheroAngr = p.ownheroAngr;
- this.ownHeroFrozen = p.ownHeroFrozen;
- this.enemyHeroFrozen = p.enemyHeroFrozen;
- this.heroImmuneWhileAttacking = p.heroImmuneWhileAttacking;
- this.owncarddraw = p.owncarddraw;
- this.ownHeroDefence = p.ownHeroDefence;
- this.enemyWeaponAttack = p.enemyWeaponAttack;
- this.enemycarddraw = p.enemycarddraw;
- this.enemyAnzCards = p.enemyAnzCards;
- this.enemyHeroDefence = p.enemyHeroDefence;
- this.ownWeaponDurability = p.ownWeaponDurability;
- this.ownWeaponAttack = p.ownWeaponAttack;
- this.ownWeaponName = p.ownWeaponName;
- this.lostDamage = p.lostDamage;
- this.lostWeaponDamage = p.lostWeaponDamage;
- this.lostHeal = p.lostHeal;
- this.ownAbilityReady = p.ownAbilityReady;
- this.ownHeroAblility = p.ownHeroAblility;
- this.doublepriest = 0;
- this.spellpower = 0;
- value = -1000000;
- this.mobsplayedThisTurn = p.mobsplayedThisTurn;
- this.startedWithMobsPlayedThisTurn = p.startedWithMobsPlayedThisTurn;
- this.cardsPlayedThisTurn = p.cardsPlayedThisTurn;
- this.ueberladung = p.ueberladung;
- this.ownDeckSize = p.ownDeckSize;
- this.enemyDeckSize = p.enemyDeckSize;
- this.ownHeroFatigue = p.ownHeroFatigue;
- this.enemyHeroFatigue = p.enemyHeroFatigue;
- //need the following for manacost-calculation
- this.ownHeroHpStarted = p.ownHeroHpStarted;
- this.enemyHeroHp = p.enemyHeroHp;
- this.ownWeaponAttackStarted = p.ownWeaponAttackStarted;
- this.ownCardsCountStarted = p.ownCardsCountStarted;
- this.ownMobsCountStarted = p.ownMobsCountStarted;
- this.startedWithWinzigebeschwoererin = p.startedWithWinzigebeschwoererin;
- this.playedmagierinderkirintor = p.playedmagierinderkirintor;
- this.startedWithZauberlehrling = p.startedWithZauberlehrling;
- this.startedWithWinzigebeschwoererin = p.startedWithWinzigebeschwoererin;
- this.startedWithManagespenst = p.startedWithManagespenst;
- this.startedWithsoeldnerDerVenture = p.startedWithsoeldnerDerVenture;
- this.startedWithbeschwoerungsportal = p.startedWithbeschwoerungsportal;
- this.zauberlehrling = 0;
- this.winzigebeschwoererin = 0;
- this.managespenst = 0;
- this.soeldnerDerVenture = 0;
- foreach (Minion m in this.ownMinions)
- {
- if (m.silenced) continue;
- if (m.name == "prophetvelen") this.doublepriest++;
- spellpower = spellpower + m.card.spellpowervalue;
- if (m.name == "auchenaisoulpriest") this.auchenaiseelenpriesterin = true;
- if (m.name == "pint-sizedsummoner") this.winzigebeschwoererin++;
- if (m.name == "sorcerersapprentice") this.zauberlehrling++;
- if (m.name == "manawraith") this.managespenst++;
- if (m.name == "venturecomercenary") this.soeldnerDerVenture++;
- if (m.name == "summoningportal") this.beschwoerungsportal++;
- }
- foreach (Minion m in this.enemyMinions)
- {
- if (m.silenced) continue;
- if (m.name == "manawraith") this.managespenst++;
- }
- }
- public bool isEqual(Playfield p)
- {
- if (this.enemySecretCount != p.enemySecretCount)
- {
- help.logg("enemy secrets changed ");
- return false;
- }
- if (this.mana != p.mana || this.enemyMaxMana != p.enemyMaxMana || this.ownMaxMana != p.ownMaxMana)
- {
- help.logg("mana changed " + this.mana + " " + p.mana + " " + this.enemyMaxMana + " " + p.enemyMaxMana + " " + this.ownMaxMana + " " + p.ownMaxMana);
- return false;
- }
- if (this.ownDeckSize != p.ownDeckSize || this.enemyDeckSize != p.enemyDeckSize || this.ownHeroFatigue != p.ownHeroFatigue || this.enemyHeroFatigue != p.enemyHeroFatigue)
- {
- help.logg("deck/fatigue changed " + this.ownDeckSize + " " + p.ownDeckSize + " " + this.enemyDeckSize + " " + p.enemyDeckSize + " " + this.ownHeroFatigue + " " + p.ownHeroFatigue + " " + this.enemyHeroFatigue + " " + p.enemyHeroFatigue);
- }
- if (this.cardsPlayedThisTurn != p.cardsPlayedThisTurn || this.mobsplayedThisTurn != p.mobsplayedThisTurn || this.ueberladung != p.ueberladung)
- {
- help.logg("stuff changed " + this.cardsPlayedThisTurn + " " + p.cardsPlayedThisTurn + " " + this.mobsplayedThisTurn + " " + p.mobsplayedThisTurn + " " + this.ueberladung + " " + p.ueberladung);
- return false;
- }
- …
Large files files are truncated, but you can click here to view the full file