Esempio n. 1
0
        public void DecideGoalBehavior()
        {
            lastBehaviorDecision = GameTimer.Instance.GetFrameTimestamp();
            IReadonlyListX <DecisionContext> goalContexts = activeGoal.GetExecutionContexts(entity);
            float maxScore = float.MinValue;

            activeContext  = null;
            activeBehavior = null;
            for (int i = 0; i < behaviors.Count; i++)
            {
                AIBehavior behavior = behaviors[i];
                if (!behavior.CanSatisfyGoalType(activeGoal.goalType))
                {
                    //    continue;
                }
                DecisionContext context;
                float           score = AIUtil.Score(goalContexts, behavior.considerations, maxScore, out context);
                if (score > maxScore)
                {
                    maxScore       = score;
                    activeBehavior = behavior;
                    activeContext  = context;
                }
            }
        }
Esempio n. 2
0
        public static float Score(IReadonlyListX <DecisionContext> contexts, Consideration[] considerations, float cutoff, out DecisionContext outputContext)
        {
            int length             = contexts.Count;
            int considerationCount = considerations.Length;

            float modFactor = 1f - (1f / considerationCount);
            float maxScore  = float.MinValue;

            outputContext = null;
            DecisionContext[] rawList = contexts.RawArray;
            for (int i = 0; i < length; i++)
            {
                DecisionContext context = rawList[i];

                float finalScore = 1 + 0; //todo -- bonus / personality influence

                for (int j = 0; j < considerationCount; j++)
                {
                    if (finalScore < 0 || finalScore < cutoff)
                    {
                        break;
                    }

                    Consideration consideration = considerations[j];
                    UnityEngine.Debug.Assert(consideration != null, nameof(consideration) + " != null");
                    float score       = consideration.curve.Evaluate(consideration.Score(context));
                    float makeUpValue = (1f - score) * modFactor;
                    float total       = score + (makeUpValue * score);
                    finalScore *= MathUtil.Clamp01(total);
                }

                if (finalScore > maxScore)
                {
                    maxScore      = finalScore;
                    outputContext = context;
                }
            }
            return(maxScore);
        }
Esempio n. 3
0
 public virtual float Score(DecisionContext context)
 {
     return(1f);
 }
Esempio n. 4
0
 public float Score(DecisionContext context, float maxScore)
 {
     return(1f);
 }
Esempio n. 5
0
 public abstract void SetContext(DecisionContext bestResultContext);