Beispiel #1
0
        public void ConfirmSixSidedDieReturns1To6()
        {
            var requiredRolls = new HashSet<int> { 1, 2, 3, 4, 5, 6 };

            var die = new DieHelper(1, 6);
            for (var idx = 0; idx < 1000; ++idx)
            {
                var roll = die.Roll();
                if (roll < 1 || roll > 6)
                {
                    Assert.Fail("Rolled: {0}", roll);
                }
                requiredRolls.Remove(roll);
            }

            foreach (var requiredRoll in requiredRolls)
            {
                Console.WriteLine("Roll remaining: {0}", requiredRoll);
            }

            Assert.AreEqual(0, requiredRolls.Count);
        }
        private string PlayMonopoly(int dieUpperLimit)
        {
            var squarePopularity = new List<int>();
            for (var idx = 0; idx < NumberOfSquares; ++idx)
            {
                squarePopularity.Add(0);
            }

            var dieHelper = new DieHelper(1, dieUpperLimit);

            var currentSquareIndex = 0;
            for (var turn = 0; turn < 100000000; ++turn)
            {
                var firstRoll = dieHelper.Roll();
                var secondRoll = dieHelper.Roll();

                var goToJailFromDoubles = GoToJailFromDoubles(firstRoll, secondRoll);
                if (goToJailFromDoubles)
                {
                    currentSquareIndex = jailSquareIndex;
                    squarePopularity[currentSquareIndex]++;
                    continue;
                }

                currentSquareIndex += (firstRoll + secondRoll);
                currentSquareIndex %= NumberOfSquares;

                if (currentSquareIndex == goToJailSquareIndex)
                {
                    currentSquareIndex = jailSquareIndex;
                    squarePopularity[currentSquareIndex]++;
                    continue;
                }

                var currentSquareType = squares[currentSquareIndex].SquareType;
                switch (currentSquareType)
                {
                    case MonopolyType.Chance:
                        var chanceCard = UseChance();
                        currentSquareIndex = ApplyChanceCard(currentSquareIndex, chanceCard);
                        break;

                    case MonopolyType.CommunityChest:
                        var communityChestCard = UseCommunityChest();
                        currentSquareIndex = ApplyCommunityChest(currentSquareIndex, communityChestCard);
                        break;
                }

                squarePopularity[currentSquareIndex]++;
            }

            return GetModalString(squarePopularity);
        }