コード例 #1
0
        public static bool ThreeOfAKind(BitHand startingHand, BitHand bestHand)
        {
            var hand = startingHand.Hand;

            var clubCards    = GetClubs(hand);
            var diamondCards = GetDiamonds(hand);
            var heartCards   = GetHearts(hand);
            var spadeCards   = GetSpades(hand);

            var cdh = (clubCards & diamondCards & heartCards);
            var cds = (clubCards & diamondCards & spadeCards);
            var chs = (clubCards & heartCards & spadeCards);
            var dhs = (diamondCards & heartCards & spadeCards);

            var trip    = (cdh | cds | chs | dhs);
            var hasTrip = trip > 0;

            if (hasTrip)
            {
                //  getting the max of the various cdh, cds, etc isn't going to work since they're basically just
                //  numbers without suits.  They've got no real context.  maxTrip just gives me a place to start.
                //  the Trip var tells us which card is triplicated, so we use that to create a mask to AND against
                //  the original hand to give us the three of a kind in the hand.
                var tripMask = (trip) | (trip << 16) | (trip << 32) | (trip << 48);

                var tripCards = tripMask & startingHand;
                bestHand.Reset(tripCards);
            }
            return(hasTrip);
        }
コード例 #2
0
        public static bool Pair(BitHand startingHand, BitHand bestHand)
        {
            var hand = startingHand.Hand;

            var clubCards    = GetClubs(hand);
            var diamondCards = GetDiamonds(hand);
            var heartCards   = GetHearts(hand);
            var spadeCards   = GetSpades(hand);

            ulong cd = clubCards & diamondCards,
                  ch = clubCards & heartCards,
                  cs = clubCards & spadeCards,
                  dh = diamondCards & heartCards,
                  ds = diamondCards & spadeCards,
                  hs = heartCards & spadeCards;

            var pair    = cd | ch | cs | dh | ds | hs;
            var hasPair = pair > 0;

            if (hasPair)
            {
                var pairMask = (pair) | (pair << 16) | (pair << 32) | (pair << 48);

                var pairCards = pairMask & startingHand;
                bestHand.Reset(pairCards);
            }

            return(hasPair);
        }
コード例 #3
0
        private static bool IsFlush(BitHand startingHand, BitHand bestHand, ulong flushMask)
        {
            var hand = startingHand.Hand;

            var clubCards    = hand & SuitCards[Card.CardSuit.Clubs];
            var diamondCards = hand & SuitCards[Card.CardSuit.Diamonds];
            var heartCards   = hand & SuitCards[Card.CardSuit.Hearts];
            var spadeCards   = hand & SuitCards[Card.CardSuit.Spades];

            var possibleClubFlush    = flushMask & clubCards;
            var possibleDiamondFlush = flushMask & diamondCards;
            var possibleHeartFlush   = flushMask & heartCards;
            var possibleSpadeFlush   = flushMask & spadeCards;

            var handFlushMask = possibleClubFlush | possibleDiamondFlush | possibleHeartFlush |
                                possibleSpadeFlush;

            var handFlush = handFlushMask & startingHand;

            if (handFlush == startingHand)
            {
                bestHand.Reset(handFlush);
                return(true);
            }
            return(false);
        }