public override PlayerTask GetMove(POGame.POGame poGame)
        {
            if (!_hasInitialized)
            {
                CustomInit(poGame);
            }

            if (_isTurnBegin)
            {
                OnMyTurnBegin(poGame);
            }

            var options = poGame.CurrentPlayer.Options();

            PlayerTask choosenTask = ChooseTask(poGame, options);

            //should not happen, but if, just return anything:
            if (choosenTask == null)
            {
                if (TyConst.LOG_UNKNOWN_CORRECTIONS)
                {
                    TyDebug.LogError("Choosen task was null!");
                }

                choosenTask = options.GetUniformRandom(_random);
            }

            if (choosenTask.PlayerTaskType == PlayerTaskType.END_TURN)
            {
                OnMyTurnEnd();
            }

            return(choosenTask);
        }
Example #2
0
        /// <summary> Searches for XX/YY in the given text and parses it to int. </summary>
        private static bool FindNumberValues(string text, ref int first, ref int second)
        {
            Regex regex = new Regex("[0-9]+/[0-9]+");
            var   match = regex.Match(text);

            if (match.Success)
            {
                var numbers = match.Value.Split("/", StringSplitOptions.RemoveEmptyEntries);
                if (numbers.Length == 2)
                {
                    if (int.TryParse(numbers[0], out first))
                    {
                        if (int.TryParse(numbers[1], out second))
                        {
                            return(true);
                        }
                    }
                }
            }

            if (TyConst.LOG_UNKNOWN_CORRECTIONS)
            {
                TyDebug.LogError("Could find number values in " + text);
            }

            return(false);
        }
Example #3
0
        private static void RemoveMinion(Minion minion, TyState ownerState, TyState opponentState, PlayerTask task)
        {
            //remove the minion value from the overall minion values and remove it from the board
            ownerState.MinionValues -= TyMinionUtil.ComputeMinionValue(minion);
            ownerState.NumMinionsOnBoard--;

            if (minion.HasDeathrattle)
            {
                if (!CorrectForSummonAndEquip(minion.Card, ownerState, opponentState) && TyConst.LOG_UNKNOWN_CORRECTIONS)
                {
                    TyDebug.LogError("Unknown deathrattle from " + minion.Card.FullPrint());
                    TyDebug.LogWarning("After task " + task.FullPrint());
                }
            }
        }
        private PlayerTask GetSimulationTreeTask(POGame.POGame poGame, List <PlayerTask> options)
        {
            double time = TyUtility.GetSecondsSinceStart() - _turnTimeStart;

            if (time >= TyConst.MAX_TURN_TIME)
            {
                TyDebug.LogError("Turn takes too long, fall back to greedy.");
                return(GetGreedyBestTask(poGame, options));
            }

            _simTree.InitTree(_analyzer, poGame, options);

            //-1 because TurnEnd won't be looked at:
            int optionCount = options.Count - 1;
            int numEpisodes = (int)((optionCount) * _curEpisodeMultiplier);

            double simStart = TyUtility.GetSecondsSinceStart();

            /*
             * for (int i = 0; i < numEpisodes; i++)
             * {
             *      if (!IsAllowedToSimulate(simStart, i, numEpisodes, optionCount))
             *              break;
             *
             *      bool shouldExploit = ((double)i / (double)numEpisodes) > EXPLORE_TRESHOLD;
             *      _simTree.SimulateEpisode(_random, i, shouldExploit);
             * }
             *
             */
            int i = 0;

            while (IsAllowedToSimulate(simStart, i, numEpisodes, optionCount))
            {
                bool shouldExploit = ((double)i / (double)numEpisodes) > EXPLORE_TRESHOLD;
                _simTree.SimulateEpisode(_random, i, shouldExploit);
                i++;
            }

            var bestNode = _simTree.GetBestNode();

            return(bestNode.Task);
        }
Example #5
0
        public static bool CorrectBuggySimulation(TyState lastPlayerState, TyState lastEnemyState, POGame.POGame lastState, PlayerTask task)
        {
            var taskType = task.PlayerTaskType;

            //Testing.TyDebug.LogError(task.FullPrint());

            bool corrected = false;

            if (taskType == PlayerTaskType.END_TURN)
            {
                CorrectTurnEnd(lastPlayerState, lastEnemyState, lastState, task, ref corrected);
            }

            else if (taskType == PlayerTaskType.HERO_ATTACK)
            {
                CorrectHeroAttack(lastPlayerState, lastEnemyState, lastState, task, ref corrected);
            }

            else if (taskType == PlayerTaskType.PLAY_CARD)
            {
                CorrectPlayCard(lastPlayerState, lastEnemyState, lastState, task, ref corrected);
            }

            else if (taskType == PlayerTaskType.MINION_ATTACK)
            {
                CorrectMinionAttack(lastPlayerState, lastEnemyState, lastState, task, ref corrected);
            }

            else if (taskType == PlayerTaskType.HERO_POWER)
            {
                CorrectHeroPower(lastPlayerState, lastEnemyState, lastState, task, ref corrected);
            }

            if (TyConst.LOG_UNKNOWN_CORRECTIONS && !corrected)
            {
                TyDebug.LogError("Unknown buggy PlayerTask: " + task.FullPrint());
            }

            return(corrected);
        }