Beispiel #1
0
        public Scenario.Context ChooseBehavior(IInputBroker broker, List <Scenario.IScenarioMember> targets, Scenario.DecisionHistory scores)
        {
            if (AgentArchetype == null)
            {
                return(null);
            }

            foreach (var set in AgentArchetype.BehaviorSets)
            {
                foreach (var behavior in set.EnabledBehaviors)
                {
                    if (behavior.CanTargetOthers || behavior.CanTargetSelf)
                    {
                        foreach (var scenarioTarget in targets)
                        {
                            if (!behavior.CanTargetOthers && (scenarioTarget != this))
                            {
                                continue;
                            }

                            if (!behavior.CanTargetSelf && (scenarioTarget == this))
                            {
                                continue;
                            }

                            var context = new Scenario.Context
                            {
                                ChosenBehavior = behavior,
                                Target         = scenarioTarget,
                                ThinkingAgent  = this
                            };

                            scores.ScoredContexts.Add(context);
                        }
                    }
                }
            }

            var scoredBehaviors = scores.ScoredContexts.Select(ctx => new { ctx, score = ctx.ChosenBehavior.Score(broker, ctx) }).OrderByDescending(x => x.score.FinalScore);

            if (scoredBehaviors == null || !scoredBehaviors.Any())
            {
                return(null);
            }

            foreach (var behavior in scoredBehaviors.ToList())
            {
                behavior.ctx.BehaviorScore = behavior.score;
            }


            var topBehavior = scoredBehaviors.First();

            if (topBehavior.score.FinalScore > 0.0f)
            {
                return(topBehavior.ctx);
            }

            return(null);
        }
Beispiel #2
0
        internal Scenario.ConsiderationScores Score(IInputBroker broker, Scenario.Context context)
        {
            var ret = new Scenario.ConsiderationScores
            {
                Considerations = new Dictionary <Consideration, Scenario.Score>()
            };

            double compensationFactor = 1.0 - (1.0 / (double)Considerations.Count);
            double result             = Weight;

            ret.InitialWeight = Weight;

            foreach (Consideration c in Considerations)
            {
                Scenario.Score considerationScore = c.Score(broker, context);
                double         modification       = (1.0 - considerationScore.FinalScore) * compensationFactor;
                considerationScore.FinalScore = considerationScore.FinalScore + (modification * considerationScore.FinalScore);

                result *= considerationScore.FinalScore;
                ret.Considerations.Add(c, considerationScore);
            }

            ret.FinalScore = result;
            return(ret);
        }
        internal Scenario.Score Score(IInputBroker broker, Scenario.Context context)
        {
            var score = new Scenario.Score();

            score.InputValue = broker.GetInputValue(Input, context);
            score.InputValue = NormalizeInput(score.InputValue);
            score.FinalScore = Curve.ComputeValue(score.InputValue);
            return(score);
        }
Beispiel #4
0
        public double GetInputValue(Consideration consideration, Scenario.Context context)
        {
            if (context == null)
            {
                return(GetInputValue(consideration));
            }

            throw new NotImplementedException();
        }
Beispiel #5
0
        public double GetInputValue(InputAxis axis, Scenario.Context context)
        {
            if (context == null)
            {
                return(GetInputValue(axis));
            }

            // TODO - figure out what input this should link to and retrieve the corresponding value
            return(0.0);
        }
 public double GetInputValue(InputAxis axis, Scenario.Context context)
 {
     return(0.0);
 }