コード例 #1
0
ファイル: TyState.cs プロジェクト: hgorelick/SabberStone
        /// <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)
        {
            var   regex = new Regex("[0-9]+/[0-9]+");
            Match match = regex.Match(text);

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

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

            return(false);
        }
コード例 #2
0
ファイル: TycheAgent.cs プロジェクト: hgorelick/SabberStone
        private PlayerTask GetSimulationTreeTask(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);
            }

            TyTaskNode bestNode = _simTree.GetBestNode();

            return(bestNode.Task);
        }
コード例 #3
0
ファイル: TycheAgent.cs プロジェクト: hgorelick/SabberStone
        public override HearthNode PlayTurn(HearthNode state)
        {
            var poGame = new POGame(state.Game, false);

            if (!_hasInitialized)
            {
                CustomInit(poGame);
            }

            if (_isTurnBegin)
            {
                OnMyTurnBegin(poGame);
            }

            List <PlayerTask> options = poGame._game.CurrentPlayer.Options();
            PlayerTask        chosen  = ChooseTask(poGame, options);

            HearthNode selected = state.Frontier.Find(h => h.Action.IsEqual(chosen));

            //if (selected == null)
            //	foreach (HearthNode p in state.PossibleActions)
            //	{
            //		if (p.Action.IsEqual(chosen))
            //			selected = p;
            //	}

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

                selected = state.Frontier.Find(h => h.Action.IsEqual(options.GetUniformRandom(_random)));
            }

            //selected.Process();
            try
            {
                state.BirthPossibility(selected);
            }
            catch (Exception)
            {
                Console.Write("Why");
            }

            if (selected.IsEndTurn)
            {
                OnMyTurnEnd();
            }

            return(selected);
        }
コード例 #4
0
ファイル: TyState.cs プロジェクト: hgorelick/SabberStone
        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());
                }
            }
        }
コード例 #5
0
ファイル: TyState.cs プロジェクト: hgorelick/SabberStone
        public static bool CorrectBuggySimulation(TyState lastPlayerState, TyState lastEnemyState, POGame lastState, PlayerTask task)
        {
            PlayerTaskType 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);
        }