Example #1
0
        /// <summary>
        /// Match a continuous value to a discrete range. This is how floating point
        /// numbers can be used as input to a Bayesian network.
        /// </summary>
        /// <param name="d">The continuous value.</param>
        /// <returns>The range that the value was mapped into.</returns>
        public int MatchChoiceToRange(double d)
        {
            if (Choices.Count > 0 && Choices.First().IsIndex)
            {
                var result = (int)d;
                if (result > Choices.Count)
                {
                    throw new BayesianError("The item id " + result + " is not valid for event " + this.ToString());
                }
                return(result);
            }

            var index = 0;

            foreach (var choice in Choices)
            {
                if (d < choice.Max)
                {
                    return(index);
                }

                index++;
            }

            return(Math.Min(index, Choices.Count - 1));
        }
        public GameViewModel()
        {
            // this is the designtime data

            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                Image  = "Chicken.png";
                Answer = "Sample Answer";
                Choices.Add("Sample Choice");
                Choices.Add("Sample Choice");
                Choices.Add("Sample Choice");
                Choices.Add("Sample Choice");
                Choices.Add("Sample Choice");
                Selected = Choices.First();
            }
        }