Exemple #1
0
    public static CardMatchType GetCardMatchType(this List <Card> cards)
    {
        CardMatchType result = CardMatchType.HIGH_CARDS;

        if (HasOnePairCards(cards))
        {
            result = CardMatchType.ONE_PAIR;
        }

        if (HasTwoPairCards(cards))
        {
            result = CardMatchType.TWO_PAIR;
        }

        if (HasThreeOfAKindCards(cards))
        {
            result = CardMatchType.THREE_OF_A_KIND;
        }

        if (HasStraightCards(cards))
        {
            result = CardMatchType.STRAIGHT;
        }

        if (HasFlushCards(cards))
        {
            result = CardMatchType.FLUSH;
        }

        if (HasFullHouseCards(cards))
        {
            result = CardMatchType.FULL_HOUSE;
        }

        if (HasFourOfAKindCards(cards))
        {
            result = CardMatchType.FOUR_OF_A_KIND;
        }

        if (HasStraightFlushCards(cards))
        {
            result = CardMatchType.STRAIGHT_FLUSH;
        }

        if (HasRoyalFlushCards(cards))
        {
            result = CardMatchType.ROYAL_FLUSH;
        }

        return(result);
    }
    public static int EvaluateCardMatch(List <Card> card1, List <Card> card2, List <Card> communityCards)
    {
        List <Card> combinedCards1 = new List <Card>(card1);

        combinedCards1.AddRange(communityCards);

        List <Card> combinedCards2 = new List <Card>(card2);

        combinedCards2.AddRange(communityCards);

        combinedCards1.Sort((a, b) => b.rank.CompareTo(a.rank));
        combinedCards2.Sort((a, b) => b.rank.CompareTo(a.rank));

        CardMatchType p1MatchType = combinedCards1.GetCardMatchType();
        CardMatchType p2MatchType = combinedCards2.GetCardMatchType();

        // NOTE: Evaluate DRAW card matches
        if (p1MatchType == p2MatchType)
        {
            CardMatchType matchType = p1MatchType;
            Debug.Log($"DRAW matchType = {matchType}");

            // NOTE: We will not compare for Royal Flush since it is the highest.
            // It automatically results into a draw and will fall under default
            switch (matchType)
            {
            case CardMatchType.ONE_PAIR:
            case CardMatchType.TWO_PAIR:
            case CardMatchType.THREE_OF_A_KIND:
            case CardMatchType.FOUR_OF_A_KIND:
                return(ComparePairCards(card1, card2, communityCards));

            case CardMatchType.FLUSH:
                return(CompareFlushCards(card1, card2, communityCards));

            case CardMatchType.STRAIGHT:
            case CardMatchType.STRAIGHT_FLUSH:
                return(CompareStraightCards(card1, card2, communityCards));

            case CardMatchType.HIGH_CARDS:
                return(CompareHighCards(combinedCards1, combinedCards2));

            default:
                return(0);
            }
        }

        return(-1 * p1MatchType.CompareTo(p2MatchType));
    }