Пример #1
0
        public float GetStateValue(TyState playerState, TyState enemyState, Controller player, Controller opponent, PlayerTask task)
        {
            TyDebug.Assert(IsMyPlayer(player));
            TyDebug.Assert(!IsMyPlayer(opponent));

            if (EstimateSecretsAndSpells)
            {
                TySecretUtil.CalculateValues(playerState, enemyState, player, opponent);
                TySecretUtil.EstimateValues(enemyState, opponent);

                Spell spell = task.TryGetSpell();

                if (spell != null && !spell.IsSecret)
                {
                    TySpellUtil.CalculateValues(playerState, enemyState, player, opponent, task, spell);
                }
            }

            if (HasLost(enemyState))
            {
                return(Single.PositiveInfinity);
            }

            else if (HasLost(playerState))
            {
                return(Single.NegativeInfinity);
            }

            return(GetStateValueFor(playerState, enemyState) - GetStateValueFor(enemyState, playerState));
        }
Пример #2
0
        public TyStateWeights(params float[] defaultValues)
            : this()
        {
            TyDebug.Assert(defaultValues.Length == (int)WeightType.Count);

            for (int i = 0; i < _weights.Length; i++)
            {
                _weights[i] = defaultValues[i];
            }
        }
Пример #3
0
        /// <summary> Estimates how good the given child state is. </summary>
        public static float GetStateValue(POGame parent, POGame child, PlayerTask task, TyStateAnalyzer analyzer)
        {
            float valueFactor = 1.0f;

            TyState myState    = null;
            TyState enemyState = null;

            Controller player   = null;
            Controller opponent = null;

            //it's a buggy state, mostly related to equipping/using weapons on heroes etc.
            //in this case use the old state and estimate the new state manually:
            if (child == null)
            {
                player   = parent._game.CurrentPlayer;
                opponent = parent._game.CurrentOpponent;

                myState    = TyState.FromSimulatedGame(parent, player, task);
                enemyState = TyState.FromSimulatedGame(parent, opponent, null);

                //if the correction failes, assume the task is x% better/worse:
                if (!TyState.CorrectBuggySimulation(myState, enemyState, parent, task))
                {
                    valueFactor = 1.25f;
                }
            }

            else
            {
                player   = child._game.CurrentPlayer;
                opponent = child._game.CurrentOpponent;

                //happens sometimes even with/without TURN_END, idk
                if (!analyzer.IsMyPlayer(player))
                {
                    player   = child._game.CurrentOpponent;
                    opponent = child._game.CurrentPlayer;
                }

                myState    = TyState.FromSimulatedGame(child, player, task);
                enemyState = TyState.FromSimulatedGame(child, opponent, null);
            }

            TyDebug.Assert(analyzer.IsMyPlayer(player));
            TyDebug.Assert(!analyzer.IsMyPlayer(opponent));
            return(analyzer.GetStateValue(myState, enemyState, player, opponent, task) * valueFactor);
        }
Пример #4
0
 public bool IsMyPlayer(Controller c)
 {
     TyDebug.Assert(OwnPlayerId != -1);
     return(c.PlayerId == OwnPlayerId);
 }