Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        internal EditWidgetConsiderationInput(InputAxis axis, IInputBroker broker)
        {
            InitializeComponent();
            EditingAxis = axis;
            InputBroker = broker;

            InputValueTrackBar.Minimum = 0;
            InputValueTrackBar.Maximum = 100;

            if ((EditingAxis != null) && (EditingAxis.Parameters != null))
            {
                if (EditingAxis.Parameters.Count == 0)
                {
                    InputValueTrackBar.Visible = false;
                }
                else if (EditingAxis.Parameters.Count == 1)
                {
                    InputValueTrackBar.Minimum = (int)(EditingAxis.Parameters[0].MinimumValue * 100.0f);
                    InputValueTrackBar.Maximum = (int)(EditingAxis.Parameters[0].MaximumValue * 100.0f);
                }
                else if (EditingAxis.Parameters.Count == 2)
                {
                    InputValueTrackBar.Minimum = (int)(EditingAxis.Parameters[0].MinimumValue * 100.0f);
                    InputValueTrackBar.Maximum = (int)(EditingAxis.Parameters[1].MaximumValue * 100.0f);
                }
                else
                {
                    // TODO - handle this?
                }
            }

            int range = InputValueTrackBar.Maximum - InputValueTrackBar.Minimum;

            InputValueTrackBar.SmallChange   = range / 10;
            InputValueTrackBar.LargeChange   = range / 4;
            InputValueTrackBar.TickFrequency = range / 25;

            InputValueTrackBar.Value = InputValueTrackBar.Minimum + (range / 2);
            InputValueTrackBar_Scroll(null, null);
        }
        internal EditWidgetConsiderationScore(Consideration consideration, IInputBroker broker)
        {
            InitializeComponent();
            EditConsideration = consideration;
            InputBroker       = broker;

            ConsiderationNameLabel.Text = EditConsideration.ReadableName + " (0.0) x";

            ResponseCurvePictureBox.Paint += (e, args) =>
            {
                Point previousPoint = ConvertXYToPoint(0.0, EditConsideration.Curve.ComputeValue(0.0));

                for (double x = 0.0; x <= 1.0; x += 0.001)
                {
                    double y = EditConsideration.Curve.ComputeValue(x);
                    Point  p = ConvertXYToPoint(x, y);

                    args.Graphics.DrawLine(Pens.Blue, previousPoint, p);
                    previousPoint = p;
                }

                double inputX = InputBroker.GetInputValue(EditConsideration.Input);
                inputX = EditConsideration.NormalizeInput(inputX);
                double inputY = EditConsideration.Curve.ComputeValue(inputX);

                string name = EditConsideration.ReadableName;
                ConsiderationNameLabel.Text = $"{name} ({inputX:f3}) x";
                ScoreLabel.Text             = $"= {inputY:f3}";

                Point offsetPoint = ConvertXYToPoint(inputX, inputY);
                offsetPoint.X -= 4;
                offsetPoint.Y -= 4;

                args.Graphics.FillEllipse(Brushes.Blue, new Rectangle(offsetPoint, new Size(8, 8)));
            };
        }
Ejemplo n.º 6
0
        internal EditWidgetConsiderationInput(InputAxis axis, IInputBroker broker)
        {
            InitializeComponent();
            EditingAxis = axis;
            InputBroker = broker;

            InputValueTrackBar.Minimum = 0;
            InputValueTrackBar.Maximum = 100;

            InputValueDropDown.Visible = false;

            if ((EditingAxis != null) && (EditingAxis.Parameters != null))
            {
                if (EditingAxis.Parameters.Count == 1)
                {
                    var rawparam = EditingAxis.Parameters[0];
                    if (rawparam is InputParameterNumeric)
                    {
                        var numericparam = rawparam as InputParameterNumeric;
                        InputValueTrackBar.Minimum = (int)(numericparam.MinimumValue * 100.0f);
                        InputValueTrackBar.Maximum = (int)(numericparam.MaximumValue * 100.0f);
                    }
                    else if (rawparam is InputParameterEnumeration)
                    {
                        InputValueTrackBar.Visible = false;
                        InputValueDropDown.Visible = true;
                        InputValueDropDown.Items.Clear();

                        var penum = rawparam as InputParameterEnumeration;
                        foreach (var valid in penum.ValidValues)
                        {
                            InputValueDropDown.Items.Add(valid);
                        }

                        if (penum.ValidValues.Count > 0)
                        {
                            InputValueDropDown.SelectedIndex = 0;
                        }
                    }
                }
                else if (EditingAxis.Parameters.Count == 2)
                {
                    InputValueTrackBar.Minimum = (int)((EditingAxis.Parameters[0] as InputParameterNumeric).MinimumValue * 100.0f);
                    InputValueTrackBar.Maximum = (int)((EditingAxis.Parameters[1] as InputParameterNumeric).MaximumValue * 100.0f);
                }
                else
                {
                    InputValueTrackBar.Visible = false;
                }
            }

            if (InputValueTrackBar.Visible)
            {
                int range = InputValueTrackBar.Maximum - InputValueTrackBar.Minimum;
                InputValueTrackBar.SmallChange   = range / 10;
                InputValueTrackBar.LargeChange   = range / 4;
                InputValueTrackBar.TickFrequency = range / 25;

                InputValueTrackBar.Value = InputValueTrackBar.Minimum + (range / 2);
                InputValueTrackBar_Scroll(null, null);
            }
        }