Beispiel #1
0
        public void SortHand()
        {
            ICardSorter sorter = new BigTwoCardSorter();

            Card[] sortedHand = sorter.Sort(Hand.Cards);
            Hand = new PlayerHand(sortedHand);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the single lowest card we have that isn't part of a stronger hand
        /// </summary>
        /// <returns></returns>
        private Card GetLowestCard()
        {
            // Sort the cards, then pick the first card (which is now the lowest) that matches
            ICardSorter sorter = new BigTwoCardSorter();

            Card[] sortedCards = sorter.Sort(Hand.Cards);

            // We don't want to break up a stronger hand if we don't have to
            // For example, we don't want to return a 7 of hearts if we also have a 7 of spades.
            Card card = sortedCards.FirstOrDefault(c => !Hand.IsCardPartOfStrongerHand(c)) ?? sortedCards.First();

            return(card);
        }
Beispiel #3
0
        /// <summary>
        /// Gets a single card that beats the card passed in, tries to preserve stronger hands
        /// </summary>
        /// <param name="activeCard">The card to beat</param>
        /// <returns></returns>
        private PlayedCards GetSingleCard(Card activeCard)
        {
            ICardSorter sorter = new BigTwoCardSorter();

            Card[] sortedCards = sorter.Sort(Hand.Cards);

            // Again, we don't want to break up a stronger hand if we don't have to
            Card cardToPlay = sortedCards.FirstOrDefault(
                c => c.IsGreaterThan(activeCard) && !Hand.IsCardPartOfStrongerHand(c)
                );

            if (cardToPlay == null)
            {
                // Looks like we may have to break up a stronger hand
                cardToPlay = sortedCards.FirstOrDefault(
                    c => c.IsGreaterThan(activeCard) || c.GameValue > activeCard.GameValue
                    );
            }

            return(new PlayedCards(this, new[] { cardToPlay }));
        }