Example #1
0
        private static void PrintStandardDeckOfCards()
        {
            var blackjackCardValueAssigner = new BlackjackCardValueAssigner();
            var standardDeckOfCards        = new StandardDeckOfCards(blackjackCardValueAssigner);

            Console.WriteLine("Card order out of the pack: ");
            PrintCards(standardDeckOfCards);

            standardDeckOfCards.Shuffle();

            Console.WriteLine("\nShuffled cards:");
            PrintCards(standardDeckOfCards);
        }
Example #2
0
        static void Main(string[] args)
        {
            // global exception handling to handle exception across application
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

            StandardDeckOfCards deckOfCards = new StandardDeckOfCards();

            bool flag = true;

            while (flag)
            {
                Console.WriteLine("Choose option:\n1: Play\n2: Shuffle\n3: Restart\n4: Display\n50: Exit");

                int option = Convert.ToInt32(Console.ReadLine());

                switch (option)
                {
                case 1:
                    deckOfCards.PlayACard();
                    break;

                case 2:
                    deckOfCards.Shuffle();
                    break;

                case 3:
                    deckOfCards.Reset();
                    break;

                case 4:
                    deckOfCards.DisplayCardsInDeck();
                    break;

                case 50:
                    flag = false;
                    break;

                default:
                    flag = false;
                    break;
                }
            }
        }
Example #3
0
        private static void TestShuffle()
        {
            int[,] cardCounts = new int[13, 4];
            var deckOfCards = new StandardDeckOfCards(new BlackjackCardValueAssigner());
            int runCount    = 100000000;

            for (int i = 0; i < runCount; i++)
            {
                deckOfCards.Shuffle();
                var card = deckOfCards.PullTopCard();
                ++cardCounts[(int)card.Type, (int)card.Suit];
                deckOfCards.Cards.Add(card);
            }

            for (int typeIndex = 0; typeIndex < 13; typeIndex++)
            {
                for (int suitIndex = 0; suitIndex < 4; suitIndex++)
                {
                    decimal cardOdds = (decimal)cardCounts[typeIndex, suitIndex] / (decimal)runCount;
                    Console.WriteLine((CardType)typeIndex + " of " + (CardSuit)suitIndex + ": " + cardOdds.ToString("P3"));
                }
            }
        }