Exemple #1
0
        public Behavior ReadSettings()
        {
            if (!File.Exists(FilePath.Settings))
            {
                Helpfunctions.Instance.logg("[Settings] cant find base settings.txt, using default settings");
                return(SetDefaultSettings());
            }
            Helpfunctions.Instance.ErrorLog("[Settings] reading settings.txt ");

            string[] lines = new string[] { };
            try
            {
                lines = File.ReadAllLines(FilePath.Settings);
            }
            catch
            {
                Helpfunctions.Instance.logg("[Settings] cant find read settings.txt, using default settings");
                return(SetDefaultSettings());
            }

            foreach (string ss in lines)
            {
                string s = ss.Replace(" ", "");
                if (s.Contains(";"))
                {
                    s = s.Split(';')[0];
                }
                if (s.Contains("#"))
                {
                    s = s.Split('#')[0];
                }
                if (s.Contains("//"))
                {
                    s = s.Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries)[0];
                }
                if (s.Contains(","))
                {
                    s = s.Split(',')[0];
                }
                if (s == "" || s == " ")
                {
                    continue;
                }
                s = s.ToLower();
                const string ignoring = "[Settings] ignoring the setting ";

                string searchword = "maxwide=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.maxwide = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "twotsamount=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.twotsamount = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "simenemysecondturn=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.simEnemySecondTurn = Convert.ToBoolean(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "enfacehp=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.enfacehp = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "playarround=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.playarround = Convert.ToBoolean(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "playaroundprob=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.playaroundprob = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "playaroundprob2=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.playaroundprob2 = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "enemyturnmaxwide=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.enemyTurnMaxWide = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "enemyturnmaxwidesecondtime=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.enemyTurnMaxWideSecondTime = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "enemysecondturnmaxwide=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.enemySecondTurnMaxWide = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "nextturndeep=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.nextTurnDeep = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "nextturnmaxwide=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.nextTurnMaxWide = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "nextturntotalboards=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.nextTurnTotalBoards = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "usesecretsplayarround=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.useSecretsPlayArround = Convert.ToBoolean(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "alpha=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.alpha = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "simulateplacement=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.simulatePlacement = Convert.ToBoolean(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "useexternalprocess=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.useExternalProcess = Convert.ToBoolean(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "passivewaiting=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.passiveWaiting = Convert.ToBoolean(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "behave=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    if (a.StartsWith("control"))
                    {
                        behave = new BehaviorControl();
                    }
                    if (a.StartsWith("rush"))
                    {
                        behave = new BehaviorRush();
                    }
                    if (a.StartsWith("mana"))
                    {
                        behave = new BehaviorMana();
                    }
                    if (a.StartsWith("face"))
                    {
                        behave = new BehaviorFace();
                    }
                    if (a.StartsWith("aggrowarlock"))
                    {
                        behave = new BehaviorAggroWarlock();
                    }
                    if (a.StartsWith("aggroshaman"))
                    {
                        behave = new BehaviorAggroshaman();
                    }
                }

                searchword = "concedeonbadboard=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.enemyConcede = Convert.ToBoolean(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "concedeonboardvalue=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.enemyConcedeValue = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "speed=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.speedy = Convert.ToBoolean(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "secretstandard =";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.SecretStandard = Convert.ToBoolean(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }

                searchword = "enemyherovaluemultiply=";
                if (s.StartsWith(searchword))
                {
                    string a = s.Replace(searchword, "");
                    try
                    {
                        this.enemyherovaluemultiply = Convert.ToInt32(a);
                    }
                    catch
                    {
                        Helpfunctions.Instance.ErrorLog(ignoring + searchword);
                    }
                }
            }
            ApplySettings();

            return(behave);
        }
        //private void startEnemyTurnSim(Playfield p, bool simulateTwoTurns, bool print, bool playaround, int playaroundprob, int playaroundprob2)
        //{
        //    if (p.ownHero.Hp >= 1 && p.enemyHero.Hp>=1)
        //    {
        //        //simulateEnemysTurn(simulateTwoTurns, playaround, print, pprob, pprob2);
        //        p.prepareNextTurn(p.isOwnTurn);
        //        //Helpfunctions.Instance.ErrorLog("tc " + p.turnCounter);
        //        Ai.Instance.enemySecondTurnSim[this.thread].simulateEnemysTurn(p, simulateTwoTurns, playaround, print, playaroundprob, playaroundprob2);
        //        /*
        //        if (p.turnCounter >= 2)
        //            Ai.Instance.enemySecondTurnSim.simulateEnemysTurn(p, simulateTwoTurns, playaround, print, playaroundprob, playaroundprob2);
        //        else
        //            Ai.Instance.enemyTurnSim.simulateEnemysTurn(p, simulateTwoTurns, playaround, print, playaroundprob, playaroundprob2);
        //        */
        //    }
        //    p.complete = true;
        //}

        public float doallmoves(Playfield playf, bool isLethalCheck, bool print = false)
        {
            //todo only one time!
            this.doEnemySecondTurn = Settings.Instance.simEnemySecondTurn;
            int  totalboards     = Settings.Instance.nextTurnTotalBoards;
            int  maxwide         = Settings.Instance.nextTurnMaxWide;
            int  maxdeep         = Settings.Instance.nextTurnDeep;
            bool playaround      = Settings.Instance.playarround;
            int  playaroundprob  = Settings.Instance.playaroundprob;
            int  playaroundprob2 = Settings.Instance.playaroundprob2;

            //Helpfunctions.Instance.logg("NXTTRN" + playf.mana);
            if (botBase == null)
            {
                botBase = Ai.Instance.botBase;
            }
            bool test = false;

            this.posmoves.Clear();
            this.addToPosmoves(playf, totalboards);
            bool             havedonesomething = true;
            List <Playfield> temp = new List <Playfield>();
            int deep = 0;

            //Helpfunctions.Instance.logg("NXTTRN" + playf.mana + " " + posmoves.Count);
            this.calculated = 0;
            Playfield bestold = null;

            while (havedonesomething)
            {
                //if (this.printNormalstuff) Helpfunctions.Instance.logg("ailoop");
                //GC.Collect();
                temp.Clear();
                temp.AddRange(this.posmoves);
                havedonesomething = false;
                float bestoldval = -20000000;
                foreach (Playfield p in temp)
                {
                    if (p.complete || p.ownHero.Hp <= 0)
                    {
                        continue;
                    }

                    List <Action> actions = movegen.getMoveList(p, isLethalCheck, usePenalityManager, useCutingTargets);
                    foreach (Action a in actions)
                    {
                        havedonesomething = true;
                        Playfield pf = new Playfield(p);
                        pf.doAction(a);
                        addToPosmoves(pf, totalboards);
                    }

                    if (isLethalCheck)
                    {
                        p.complete = true;
                    }
                    else
                    {
                        p.sEnemTurn = this.doEnemySecondTurn;
                        p.endTurn(this.simulateSecondTurn, playaround, false, playaroundprob, playaroundprob2);
                        //this.startEnemyTurnSim(p, this.simulateSecondTurn, false, playaround, playaroundprob, playaroundprob2);
                    }

                    //sort stupid stuff ouf

                    if (botBase.GetPlayfieldValue(p) > bestoldval)
                    {
                        bestoldval = botBase.GetPlayfieldValue(p);
                        bestold    = p;
                    }
                    if (!test)
                    {
                        posmoves.Remove(p);
                    }

                    if (this.calculated > totalboards)
                    {
                        break;
                    }
                }

                if (!test && bestoldval >= -10000 && bestold != null)
                {
                    this.posmoves.Add(bestold);
                }

                //Helpfunctions.Instance.loggonoff(true);

                /*if (this.printNormalstuff)
                 * {
                 *  int donec = 0;
                 *  foreach (Playfield p in posmoves)
                 *  {
                 *      if (p.complete) donec++;
                 *  }
                 *  Helpfunctions.Instance.logg("deep " + deep + " len " + this.posmoves.Count + " dones " + donec);
                 * }*/

                if (!test)
                {
                    cuttingposibilities(maxwide);
                }

                //if (this.printNormalstuff) Helpfunctions.Instance.logg("cut to len " + this.posmoves.Count);
                //Helpfunctions.Instance.loggonoff(false);
                deep++;

                if (this.calculated > totalboards)
                {
                    break;
                }
                if (deep >= maxdeep)
                {
                    break;                 //remove this?
                }
            }

            foreach (Playfield p in posmoves)//temp
            {
                if (!p.complete)
                {
                    if (isLethalCheck)
                    {
                        p.complete = true;
                    }
                    else
                    {
                        p.sEnemTurn = this.doEnemySecondTurn;
                        p.endTurn(this.simulateSecondTurn, playaround, false, playaroundprob, playaroundprob2);
                        //this.startEnemyTurnSim(p, this.simulateSecondTurn, false, playaround, playaroundprob, playaroundprob2);
                    }
                }
            }
            // Helpfunctions.Instance.logg("find best ");
            if (posmoves.Count >= 1)
            {
                float     bestval        = int.MinValue;
                int       bestanzactions = 1000;
                Playfield bestplay       = posmoves[0]; //temp[0]
                foreach (Playfield p in posmoves)       //temp
                {
                    float val = botBase.GetPlayfieldValue(p);
                    if (bestval <= val)
                    {
                        if (bestval == val && bestanzactions < p.playactions.Count)
                        {
                            continue;
                        }
                        bestplay       = p;
                        bestval        = val;
                        bestanzactions = p.playactions.Count;
                    }
                }
                this.bestboard = new Playfield(bestplay);

                if (print)
                {
                    Helpfunctions.Instance.ErrorLog("best board after your second turn (value included enemy second turn)----------");
                    bestplay.printBoard();
                    bestplay.value = int.MinValue;
                    //bestplay.sEnemTurn = this.doEnemySecondTurn;
                    //Ai.Instance.enemySecondTurnSim[this.thread].simulateEnemysTurn(bestplay, false, playaround, false, playaroundprob, playaroundprob2);
                    //Ai.Instance.enemySecondTurnSim.simulateEnemysTurn(bestplay, false, false, true, 100, 100); //dont play arround in enemys second turn
                }
                this.bestmove      = bestplay.getNextAction();
                this.bestmoveValue = bestval;
                this.bestboard     = new Playfield(bestplay);
                //Helpfunctions.Instance.logg("return");
                return(bestval);
            }
            //Helpfunctions.Instance.logg("return");
            this.bestmove      = null;
            this.bestmoveValue = -100000;
            this.bestboard     = playf;
            return(-10000);
        }
Exemple #3
0
        public void dosomethingclever(Behavior bbase)
        {
            //return;
            //turncheck
            //help.moveMouse(950,750);
            //help.Screenshot();
            this.botBase = bbase;
            hp.updatePositions();

            posmoves.Clear();
            posmoves.Add(new Playfield());
            posmoves[0].sEnemTurn = Settings.Instance.simulateEnemysTurn;

            /* foreach (var item in this.posmoves[0].owncards)
             * {
             *   help.logg("card " + item.handcard.card.name + " is playable :" + item.handcard.card.canplayCard(posmoves[0]) + " cost/mana: " + item.handcard.card.cost + "/" + posmoves[0].mana);
             * }
             */
            //help.logg("is hero ready?" + posmoves[0].ownHeroReady);

            help.loggonoff(false);
            //do we need to recalc?
            help.logg("recalc-check###########");
            if (this.dontRecalc && posmoves[0].isEqual(this.nextMoveGuess, true))
            {
                doNextCalcedMove();
            }
            else
            {
                help.logg("Lethal-check###########");
                bestmoveValue = -1000000;
                DateTime strt = DateTime.Now;
                if (useLethalCheck)
                {
                    strt = DateTime.Now;
                    doallmoves(false, true);
                    help.logg("calculated " + (DateTime.Now - strt).TotalSeconds);
                }

                if (bestmoveValue < 1500)
                {
                    posmoves.Clear();
                    posmoves.Add(new Playfield());
                    posmoves[0].sEnemTurn = Settings.Instance.simulateEnemysTurn;

                    List <Handmanager.Handcard> newcards = posmoves[0].getNewHandCards(Ai.Instance.nextMoveGuess);
                    foreach (var card in newcards)
                    {
                        if (!Silverfish.Instance.IsCardCreated(card))
                        {
                            Hrtprozis.Instance.removeCardFromTurnDeck(card.card.cardIDenum);
                        }
                    }

                    help.logg("no lethal, do something random######");
                    strt = DateTime.Now;
                    doallmoves(false, false);
                    help.logg("calculated " + (DateTime.Now - strt).TotalSeconds);
                }
            }

            //help.logging(true);
        }