コード例 #1
0
        public override IEnumerable <CardCombination> DetectCombinations(ISet <Card> cards)
        {
            var onePairDetector     = new OnePairCombinationDetector();
            var setDetector         = new SetCombinationDetector();
            var onePairCombinations = onePairDetector.DetectCombinations(cards).OfType <OnePairCombination>();
            var setCombinations     = setDetector.DetectCombinations(cards).OfType <SetCombination>();

            foreach (var onePair in onePairCombinations)
            {
                foreach (var set in setCombinations)
                {
                    if (!AllCardsAreUnique(onePair, set))
                    {
                        continue;
                    }

                    yield return(new FullHouseCombination(setCards: set.Cards, pairCards: onePair.Cards));
                }
            }
        }
コード例 #2
0
        public override IEnumerable <CardCombination> DetectCombinations(ISet <Card> cards)
        {
            var onePairDetector     = new OnePairCombinationDetector();
            var onePairCombinations = onePairDetector.DetectCombinations(cards).OfType <OnePairCombination>().ToList();

            foreach (var pair1 in onePairCombinations)
            {
                foreach (var pair2 in onePairCombinations)
                {
                    if (ReferenceEquals(pair1, pair2))
                    {
                        continue;
                    }

                    bool allCardsAreUnique = AllCardsAreUnique(pair1, pair2);

                    if (allCardsAreUnique)
                    {
                        yield return(new TwoPairsCombination(pair1.Cards.Concat(pair2.Cards)));
                    }
                }
            }
        }