Beispiel #1
0
        public CardCollectionOperationResult OverhandShuffle(Deck deck)
        {
            Deck rightHandHalf = new Deck(deck.GetRange(0, (deck.Count / 2)));
            Deck leftHandHalf = new Deck(deck.GetRange((deck.Count / 2), deck.Count));

            int overhandChunk =
                (Math.Max(rightHandHalf.Count, leftHandHalf.Count) / DEFAULT_OVERHAND_CHUNKS);

            deck = new Deck();

            while (rightHandHalf.Count > 0)
            {
                int takeChunk = Math.Min(overhandChunk, rightHandHalf.Count);
                deck.InsertRange(0, rightHandHalf.Take(takeChunk));
                rightHandHalf.RemoveRange(0, takeChunk);
            }

            while (leftHandHalf.Count > 0)
            {
                int takeChunk = Math.Min(overhandChunk, leftHandHalf.Count);
                deck.InsertRange(0, leftHandHalf.Take(takeChunk));
                leftHandHalf.RemoveRange(0, takeChunk);
            }

            return new CardCollectionOperationResult(deck);
        }
Beispiel #2
0
        public CardCollectionOperationResult RifleShuffle(Deck deck)
        {
            Deck rightHandHalf = new Deck(deck.GetRange(0, (deck.Count / 2)));
            Deck leftHandHalf = new Deck(deck.GetRange((deck.Count / 2), deck.Count));

            Random random = new Random();
            int rifleChunk = 0;

            deck = new Deck();

            while (rightHandHalf.Count > 0 || leftHandHalf.Count > 0)
            {
                if (rightHandHalf.Count > 0)
                {
                    rifleChunk = Math.Min(random.Next(1, 3), rightHandHalf.Count);
                    deck.AddRange(rightHandHalf.Take(rifleChunk));
                    rightHandHalf.RemoveRange(0, rifleChunk);
                }

                if (leftHandHalf.Count > 0)
                {
                    rifleChunk = Math.Min(random.Next(1, 3), leftHandHalf.Count);
                    deck.AddRange(leftHandHalf.Take(rifleChunk));
                    leftHandHalf.RemoveRange(0, rifleChunk);
                }
            }

            return new CardCollectionOperationResult(deck);
        }