Пример #1
0
        public async Task BeSufficientlyRandom_WhenUsingDefaultRNG()
        {
            await Task.Run(() =>
            {
                Dictionary <int, int> rollCounts = new Dictionary <int, int>();
                for (int i = 1; i <= 20; i++)
                {
                    rollCounts[i] = 0;
                }

                DieResult die;
                RollData data = new RollData()
                {
                    Config = new RollerConfig()
                };
                var numTrials = 10000000;
                var perRoll   = numTrials / 20;
                var tolerance = perRoll * 0.005;

                for (int i = 0; i < numTrials; i++)
                {
                    die = RollNode.DoRoll(data, RollType.Normal, 20);
                    rollCounts[(int)die.Value]++;
                }

                for (int i = 1; i <= 20; i++)
                {
                    int off = Math.Abs(rollCounts[i] - perRoll);
                    if (off > tolerance)
                    {
                        Assert.Inconclusive("Default RNG fell outside of allowed tolerance of 0.5% ({0}/{1})", off, tolerance);
                    }
                }
            });
        }
Пример #2
0
        public Preferences(string sData)
        {
            try
            {
                XmlDocument cXmlDocument = new XmlDocument();
                cXmlDocument.LoadXml(sData);
                XmlNode cXmlNode  = cXmlDocument.NodeGet("data");
                XmlNode cNodeRoll = cXmlNode.NodeGet("roll");

                _nRollPrerenderQueueMax = cNodeRoll.AttributeOrDefaultGet <int>("prerender_queue", 40);

                RollNode cRN = new RollNode(cNodeRoll);
                if (null != cRN.aTextItems.FirstOrDefault(o => o.nDuration < nRollPrerenderQueueMax * 2))
                {
                    throw new Exception("duration of any text must be > " + nRollPrerenderQueueMax * 2);
                }
                _aTextItems = cRN.aTextItems;
                _cPlaylist  = new Playlist(cRN.cNodePL);
                _cRoll      = new btl.Roll(cNodeRoll);
            }
            catch (Exception ex)
            {
                (new Logger()).WriteDebug("Preferences error: [error=" + ex.ToString() + "][source_xml=" + sData + "]");
                throw;
            }
        }
Пример #3
0
        public void Successfully_DontRerollNestedRolls()
        {
            var conf = new RollerConfig()
            {
                GetRandomBytes = GetRNG(2, 2, 2, 2, 3, 3, 3, 3, 3)
            };
            var roll = new RollNode(RollType.Normal, _1d8, Six);
            var node = new GroupNode(Two, new List <DiceAST> {
                roll
            });

            EvaluateNode(node, Data(conf), 7, "2{3d6} => (9) + (12) => 21");
        }
Пример #4
0
        public Preferences(string sData)
        {
            try
            {
                XmlDocument cXmlDocument = new XmlDocument();
                cXmlDocument.LoadXml(sData);
                XmlNode cXmlNode  = cXmlDocument.NodeGet("data");
                XmlNode cNodeRoll = cXmlNode.NodeGet("roll");

                RollNode cRN = new RollNode(cNodeRoll);
                cRN.MakeNodeRollFitInSize();

                _cRoll = new btl.Roll(cNodeRoll);
            }
            catch (Exception ex)
            {
                (new Logger()).WriteDebug("Preferences error: [error=" + ex.ToString() + "][source_xml=" + sData + "]");
                throw;
            }
        }
Пример #5
0
 internal void AddRollExpression(RollNode roll)
 {
     RollExpressions.Add(roll);
     RollValues.Add(new ValueSnapshot(roll));
 }