Ejemplo n.º 1
0
        public override Maybe <Hand> IsMatch(IEnumerable <Card> cards)
        {
            ThrowIfDuplicate(cards);

            if (cards.Count() < 5)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> highPair  = HandHelper.GetOfAKind(cards, 2);
            List <Card> remaining = HandHelper.GetRemainingCards(cards, highPair);
            List <Card> lowPair   = HandHelper.GetOfAKind(remaining, 2);
            List <Card> twoPairs  = highPair.Concat(lowPair).ToList();

            if (twoPairs.Count != 4)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> highCards  = HandHelper.GetRemainingCards(cards, twoPairs);
            Card        highCard   = highCards.OrderByDescending(c => c.Value).First();
            List <Card> finalCards = new List <Card>(twoPairs);

            finalCards.Add(highCard);

            return(CreateCopy <Hand>(finalCards));
        }
Ejemplo n.º 2
0
        public override Maybe <Hand> IsMatch(IEnumerable <Card> cards)
        {
            ThrowIfDuplicate(cards);

            if (cards.Count() < 5)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> treeOfAKind = HandHelper.GetOfAKind(cards, 3);;

            if (treeOfAKind.Count != 3)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> remainingCard = cards.ToList()
                                        .FindAll(c => c.Value != treeOfAKind.First().Value);

            List <Card> pair = HandHelper.GetOfAKind(remainingCard, 2);

            if (pair.Count != 2)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> finalCards = new List <Card>(treeOfAKind);

            finalCards.AddRange(pair);

            return(CreateCopy <Hand>(finalCards));
        }
Ejemplo n.º 3
0
        public override Maybe <Hand> IsMatch(IEnumerable <Card> cards)
        {
            ThrowIfDuplicate(cards);

            if (cards.Count() < 2)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> pair = HandHelper.GetOfAKind(cards, 2);

            if (pair.Count != 2)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> highCards = HandHelper.GetHighCards(cards, pair);

            List <Card> finalCards = new List <Card>(pair);

            finalCards.AddRange(highCards);

            return(CreateCopy <Hand>(finalCards));
        }
Ejemplo n.º 4
0
        public override Maybe <Hand> IsMatch(IEnumerable <Card> cards)
        {
            ThrowIfDuplicate(cards);

            if (cards.Count() < 5)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> fourOfAKind = HandHelper.GetOfAKind(cards, 4);

            if (fourOfAKind.Count != 4)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> highCards = HandHelper.GetHighCards(cards, fourOfAKind);

            List <Card> finalCards = new List <Card>(fourOfAKind);

            finalCards.Add(highCards.First());

            return(CreateCopy <Hand>(finalCards));
        }
Ejemplo n.º 5
0
        public override Maybe <Hand> IsMatch(IEnumerable <Card> cards)
        {
            ThrowIfDuplicate(cards);

            if (cards.Count() < 5)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> threeOfAKind = HandHelper.GetOfAKind(cards, 3);

            if (threeOfAKind.Count != 3)
            {
                return(Maybe <Hand> .None);
            }

            List <Card> highCards = HandHelper.GetHighCards(cards, threeOfAKind);

            List <Card> finalCards = new List <Card>(threeOfAKind);

            finalCards.AddRange(highCards);

            return(CreateCopy <Hand>(finalCards));
        }