public void MakeSetOfDiceOfSameSidesWorks()
        {
            Dice dice = Dice.Make(2, Die.Make(3));

            Assert.AreEqual(2, dice.DieList.Count, "dice list has expected count");
            Assert.AreEqual(3, dice.DieList[0].Sides, "0th die has expected sides");
            Assert.AreEqual(3, dice.DieList[1].Sides, "1st die has expected sides");
        }
 public void DiceAreOrdered()
 {
     Assert.AreEqual(
         Dice.Make().Add(Die.Make(2)).Add(Die.Make(3)).DieList.Select(die => die.Sides),
         new[] { 2, 3 });
     Assert.AreEqual(
         Dice.Make().Add(Die.Make(3)).Add(Die.Make(2)).DieList.Select(die => die.Sides),
         new[] { 3, 2 });
 }
        public void AddedDiceAreAccessibleInSameOrder()
        {
            var dice = Dice.Make().Add(Die.Make(1)).Add(Die.Make(3)).Add(Die.Make(2));

            Assert.AreEqual(3, dice.DieList.Count, "dice list has expected count");
            Assert.AreEqual(1, dice.DieList[0].Sides, "0th die has expected sides");
            Assert.AreEqual(3, dice.DieList[1].Sides, "1st die has expected sides");
            Assert.AreEqual(2, dice.DieList[2].Sides, "2nd die has expected sides");
        }
Ejemplo n.º 4
0
        public void DiceOfAnySidesReturnsItsSidesCountAsHighest(
            [Range(1, 3)] int sides)
        {
            TheRandom.m_random = Substitute.For <Random>();
            TheRandom.Next(1, sides + 1).Returns(sides);

            Assert.That(Die.Make(sides).Roll() == sides);

            TheRandom.m_random = null;
        }
Ejemplo n.º 5
0
        public void DieOfAnySidesReturns1ForLowest(
            [Range(1, 3)] int sides)
        {
            TheRandom.m_random = Substitute.For <Random>();
            TheRandom.Next(1, sides + 1).Returns(1);

            Assert.That(Die.Make(sides).Roll() == 1);

            TheRandom.m_random = null;
        }
        public void MakeFromPreexistingDiceClones()
        {
            Dice diceOld = Dice.Make(1, Die.Make(3));

            diceOld.Add(Die.Make(1));

            Dice diceNew = Dice.Make(diceOld);

            Assert.AreEqual(2, diceNew.DieList.Count, "New dice has expected count");
            Assert.AreEqual(3, diceNew.DieList[0].Sides, "new dice's 0th item had expected sides");
            Assert.AreEqual(1, diceNew.DieList[1].Sides, "new dice's 1st item had expected sides");

            Assert.That(diceOld.DieList != diceNew.DieList, "DieLists are not the same object (ie it was cloned)");

            Assert.That(diceOld.DieList[0] == diceNew.DieList[0], "Expect actual Die objects not to be cloned (ie multi reference is ok)");
        }
        static void RollCharactersUntilTarget()
        {
            const int target = 16 + 13 + 16 + 17 + 16 + 15;

            Dice dice = Dice.Make(4, Die.Make(6));
            //Dice dice = Dice.Make(7, Dice.Make(4, Die.Make(6)));
            // dice.Roll().DropLowest().Result();

            int iLoop = 0;

            while (true)
            {
                ++iLoop;

                List <int> rg = new List <int>();

                for (int i = 0; i < 7; ++i)
                {
                    rg.Add(dice.Roll().DropLowest().Result());
                    Console.WriteLine(rg[i]);
                }

                rg.Sort();

                int sum = 0;
                for (int i = 1; i < 7; ++i)
                {
                    sum += rg[i];
                }

                Console.WriteLine("Total (dropped lowest): " + sum.ToString());

                if (sum >= target)
                {
                    break;
                }
            }

            Console.WriteLine("It took " + iLoop.ToString() + " tries to beat " + target.ToString());
        }
        static void Main(string[] args)
        {
            // Setup global random
            Util.TheRandom.m_random = new Random();

            var battleDice = new Dice(new[]
            {
                new Die(20),
                new Die(12),
                new Die(8),
                new Die(6),
                new Die(4),
                new Die(2),
            });

            // HistogramOfDiceBattle(battleDice, 10000);
            HistogramOfBestDieRoll(Dice.Make(2, Die.Make(20)), 1000000);
            // HistogramOfDieRoll(Dice.Make(3, Die.Make(6)), 1000000);
            // HistogramOfDieRoll(Dice.Make(4, Die.Make(6)), 1000000);

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }