Example #1
0
        private static void InnerCustomOperation(Func <roll_t[], roll_t> f, List <roll_t> before, DiceRoll[] dice, fp_t existing_p, DiceRoll d)
        {
            DiceRoll r = dice[before.Count];

            foreach (var m in r.rolls)
            {
                var a = before.ToList();
                a.Add(m.Key);

                if (before.Count + 1 == dice.Length)
                {
                    // innermost dice, modify d
                    var n = f(a.ToArray());
                    if (!d.rolls.ContainsKey(n))
                    {
                        d.rolls[n] = 0;
                    }
                    d.rolls[n] += existing_p * m.Value;
                }
                else
                {
                    // we need to go deeper!
                    InnerCustomOperation(f, a, dice, existing_p * m.Value, d);
                }
            }
        }
Example #2
0
        public static DiceRoll operator *(roll_t a, DiceRoll b)
        {
            DiceRoll r = b;

            for (int i = 1; i < a; i++)
            {
                r += b;
            }

            return(r);
        }
Example #3
0
        public static DiceRoll CustomOperation(Func <roll_t[], roll_t> f, params DiceRoll[] dice)
        {
            // embrace your inner Haskell, Peter and use recursion
            DiceRoll d = new DiceRoll();
            DiceRoll s = new DiceRoll();

            InnerCustomOperation(f, new List <roll_t> (), dice, 1, d);
            foreach (var m in d.rolls)
            {
                s.rolls[m.Key] = m.Value.CanonicalForm;
            }
            return(s);
        }
Example #4
0
        public static DiceRoll operator +(DiceRoll a, DiceRoll b)
        {
            DiceRoll r = new DiceRoll();
            DiceRoll s = new DiceRoll();

            foreach (var m in a.rolls)
            {
                foreach (var n in b.rolls)
                {
                    if (!r.rolls.ContainsKey((roll_t)(m.Key + n.Key)))
                    {
                        r.rolls[(roll_t)(m.Key + n.Key)] = 0;
                    }
                    r.rolls[(roll_t)(m.Key + n.Key)] += m.Value * n.Value;
                }
            }
            foreach (var m in r.rolls)
            {
                s.rolls[m.Key] = m.Value.CanonicalForm;
            }
            return(s);
        }
        public void AddRolls(DiceRoll roll, string title, OxyColor?c = null, bool show_expected = false, bool stem = true, MarkerType marker_type = MarkerType.Cross)
        {
            OxyColor colour;

            if (c == null)
            {
                colour = NextColour();
            }
            else
            {
                colour = c.Value;
            }

            var points = new List <DataPoint> ();

            for (int i = roll.Min(); i <= roll.Max(); i++)
            {
                if (roll.rolls.ContainsKey(i))
                {
                    points.Add(new DataPoint(i, (double)roll.rolls[i]));
                }
                else if (!stem)
                {
                    points.Add(new DataPoint(i, 0));
                }
            }

            if (show_expected)
            {
                LineAnnotation Line = new LineAnnotation()
                {
                    StrokeThickness = 2,
                    Color           = colour,
                    Type            = LineAnnotationType.Vertical,
                    Text            = "Expected",
                    TextColor       = colour,
                    X = (double)roll.Expected(),
                    //Y = 0.0f
                };
                Model.Annotations.Add(Line);
            }

            if (stem)
            {
                var series = new StemSeries {
                    MarkerStroke    = colour,
                    MarkerSize      = 3,
                    MarkerFill      = colour,
                    MarkerType      = marker_type,
                    StrokeThickness = 0,
                    //Smooth = true,
                    Color = colour,
                    Title = title
                };
                series.MarkerStroke = series.Color;
                series.Points.AddRange(points);
                Model.Series.Add(series);
            }
            else
            {
                var series = new LineSeries {
                    MarkerType      = marker_type,
                    MarkerSize      = 7,
                    StrokeThickness = 0,
                    //Smooth = true,
                    Color = colour,
                    Title = title
                };
                series.Points.AddRange(points);
                Model.Series.Add(series);
            }
        }