コード例 #1
0
        private List <ActionValue> EvalBestWeightedRandomTopPercent(Context context)
        {
            List <ActionValue> actionValues = GetOrderedActionValues(context);
            float minVal   = actionValues[0].value * (1 - BestPercent);
            float valueSum = actionValues[0].value;

            for (int i = 1; i < actionValues.Count; i++)
            {
                if (actionValues[i].value >= minVal)
                {
                    valueSum += actionValues[i].value;
                }
                else
                {
                    break;
                }
            }
            float randomNumber = UnityEngine.Random.Range(0, valueSum);
            int   index        = 0;

            for (int i = 0; i < BestN; i++)
            {
                if (actionValues[i].value >= randomNumber)
                {
                    index = i;
                    break;
                }
            }
            ActionValue tmp = actionValues[index];

            actionValues[index] = actionValues[0];
            actionValues[0]     = tmp;
            return(actionValues);
        }
コード例 #2
0
        private List <ActionValue> EvalRandom(Context context)
        {
            List <ActionValue> actionValues = GetOrderedActionValues(context);
            int         index = UnityEngine.Random.Range(0, actionValues.Count);
            ActionValue tmp   = actionValues[index];

            actionValues[index] = actionValues[0];
            actionValues[0]     = tmp;
            return(actionValues);
        }
コード例 #3
0
        private List <ActionValue> EvalBestRandomFromN(Context context)
        {
            int index = UnityEngine.Random.Range(0, BestN);
            List <ActionValue> actionValues = GetOrderedActionValues(context);
            ActionValue        tmp          = actionValues[index];

            actionValues[index] = actionValues[0];
            actionValues[0]     = tmp;
            return(actionValues);
        }
コード例 #4
0
        private List <ActionValue> EvalBestWeightedRandomFromN(Context context)
        {
            List <ActionValue> actionValues = GetOrderedActionValues(context);
            float valueSum     = actionValues.GetRange(0, BestN).Sum(av => av.value);
            float randomNumber = UnityEngine.Random.Range(0, valueSum);
            int   index        = 0;

            for (int i = 0; i < BestN; i++)
            {
                if (actionValues[i].value >= randomNumber)
                {
                    index = i;
                    break;
                }
            }
            ActionValue tmp = actionValues[index];

            actionValues[index] = actionValues[0];
            actionValues[0]     = tmp;
            return(actionValues);
        }
コード例 #5
0
        private List <ActionValue> EvalBestRandomTopPercent(Context context)
        {
            List <ActionValue> actionValues = GetOrderedActionValues(context);
            int   topCount = 1;
            float minVal   = actionValues[0].value * (1 - BestPercent);

            for (int i = 1; i < actionValues.Count; i++)
            {
                if (actionValues[i].value >= minVal)
                {
                    topCount++;
                }
                else
                {
                    break;
                }
            }
            int         index = UnityEngine.Random.Range(0, topCount);
            ActionValue tmp   = actionValues[index];

            actionValues[index] = actionValues[0];
            actionValues[0]     = tmp;
            return(actionValues);
        }