Пример #1
0
        private static int Fast(ConsoleCardPrinter consoleCardPrinter)
        {
            int  numberOfHands  = 0;
            bool isStillRunning = true;

            While(new ParallelOptions {
                MaxDegreeOfParallelism = 5
            }, () => { return(isStillRunning); }, state =>
            {
                var deck = new Deck(new GuidShuffler(), new ANormalDeck());
                deck.Shuffle();
                var hand = deck.TakeOneHand();

                if (CheckIfHandHoldFourAces(hand))
                {
                    var cards = hand.Cards();
                    consoleCardPrinter.Print(cards);
                    isStillRunning = false;
                }

                deck.Reset();

                numberOfHands++;
            });

            return(numberOfHands);
        }
Пример #2
0
        private static int Slow(ConsoleCardPrinter consoleCardPrinter)
        {
            bool isStillRunning = true;
            int  numberOfHands  = 0;
            var  deck           = new Deck(new GuidShuffler(), new ANormalDeck());

            do
            {
                deck.Shuffle();
                var hand = deck.TakeOneHand();

                if (CheckIfHandHoldFourAces(hand))
                {
                    var cards = hand.Cards();
                    consoleCardPrinter.Print(cards);
                    isStillRunning = false;
                }

                deck.Reset();

                numberOfHands++;
            } while (isStillRunning);

            return(numberOfHands);
        }
Пример #3
0
        static void Main(string[] args)
        {
            var consoleCardPrinter = new ConsoleCardPrinter();
            bool isStillRunning = true;
            int numberOfHands = 0;

            var stopwatch = new Stopwatch();
            stopwatch.Start();
            Console.WriteLine("SLOW...");
            numberOfHands = Slow(consoleCardPrinter);
            stopwatch.Stop();
            Console.WriteLine("DONE in {0} - {1}", stopwatch.Elapsed, numberOfHands);
            
            stopwatch.Reset();
            stopwatch.Start();
            Console.WriteLine("FAST...");
            numberOfHands = Fast(consoleCardPrinter);
            stopwatch.Stop();

            Console.WriteLine("DONE in {0} - {1}", stopwatch.Elapsed, numberOfHands);
            Console.ReadLine();
        }
Пример #4
0
        static void Main(string[] args)
        {
            var  consoleCardPrinter = new ConsoleCardPrinter();
            bool isStillRunning     = true;
            int  numberOfHands      = 0;

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            Console.WriteLine("SLOW...");
            numberOfHands = Slow(consoleCardPrinter);
            stopwatch.Stop();
            Console.WriteLine("DONE in {0} - {1}", stopwatch.Elapsed, numberOfHands);

            stopwatch.Reset();
            stopwatch.Start();
            Console.WriteLine("FAST...");
            numberOfHands = Fast(consoleCardPrinter);
            stopwatch.Stop();

            Console.WriteLine("DONE in {0} - {1}", stopwatch.Elapsed, numberOfHands);
            Console.ReadLine();
        }
Пример #5
0
        private static int Fast(ConsoleCardPrinter consoleCardPrinter)
        {
            int numberOfHands = 0;
            bool isStillRunning = true;
            While(new ParallelOptions {MaxDegreeOfParallelism = 5}, () => { return isStillRunning; }, state =>
            {
                var deck = new Deck(new GuidShuffler(), new ANormalDeck());
                deck.Shuffle();
                var hand = deck.TakeOneHand();

                if (CheckIfHandHoldFourAces(hand))
                {
                    var cards = hand.Cards();
                    consoleCardPrinter.Print(cards);
                    isStillRunning = false;
                }

                deck.Reset();

                numberOfHands++;
            });

            return numberOfHands;
        }
Пример #6
0
        private static int Slow(ConsoleCardPrinter consoleCardPrinter)
        {
            bool isStillRunning = true;
            int numberOfHands = 0;
            var deck = new Deck(new GuidShuffler(), new ANormalDeck());
            do
            {
                deck.Shuffle();
                var hand = deck.TakeOneHand();

                if (CheckIfHandHoldFourAces(hand))
                {
                    var cards = hand.Cards();
                    consoleCardPrinter.Print(cards);
                    isStillRunning = false;
                }

                deck.Reset();

                numberOfHands++;
            } while (isStillRunning);

            return numberOfHands;
        }