コード例 #1
0
        public void Test_Dice_Configuration()
        {
            Dice dice = new Dice(Die.CreateSixEyedDie(), Die.CreateSixEyedDie(), new Die(20));

            SortedDictionary <int, int> results = new SortedDictionary <int, int>();

            int rolls = 1_000_000;

            for (int i = 0; i < rolls; i++)
            {
                int rollResult = dice.Roll();

                if (!results.ContainsKey(rollResult))
                {
                    results[rollResult] = 1;
                }
                else
                {
                    results[rollResult]++;
                }
            }

            foreach (int rollResultKey in results.Keys)
            {
                Console.WriteLine($"{rollResultKey}: {results[rollResultKey] / (decimal)rolls}");
            }
        }
コード例 #2
0
        private static Simulation CreateSimulation(int numberOfIterations)
        {
            CardDeck redCardDeck   = new CardDeck(DataLoader.LoadRedCards().ToList());
            CardDeck greenCardDeck = new CardDeck(DataLoader.LoadGreenCards().ToList());

            List <Space> spaces    = DataLoader.LoadSpaces().ToList();
            Gameboard    gameboard = new Gameboard(spaces);

            Die  die  = Die.CreateSixEyedDie();
            Dice dice = new Dice(die, die);

            IReporter reporter = CreateReporter(spaces, numberOfIterations);

            var simulation = new Simulation(gameboard, redCardDeck, greenCardDeck, dice, reporter);

            simulation.NumberOfIterations = numberOfIterations;

            return(simulation);
        }