HoldemHand.Hand.OutsMask C# (CSharp) Method

OutsMask() public static method

Creates a Hand mask with the cards that will improve the specified players mask against a list of opponents or if no opponents are list just the cards that improve the players current had. Please note that this only looks at single cards that improve the mask and will not specifically look at runner-runner possiblities.
public static OutsMask ( ulong player, ulong board ) : ulong
player ulong Players pocket cards
board ulong The board (must contain either 3 or 4 cards)
return ulong
        public static ulong OutsMask(ulong player, ulong board, params ulong[] opponents)
        {
            ulong retval = 0UL;

            #if DEBUG
            if (BitCount(player) != 2) throw new ArgumentException("player must have exactly 2 cards");
            if (BitCount(board) != 3 && BitCount(board) != 4) throw new ArgumentException("board must contain 3 or 4 cards");
            #endif

            // Get original mask value
            uint playerOrigHandVal = Hand.Evaluate(player | board);

            // Look ahead one card
            foreach (ulong card in Hand.Hands(0UL, board | player, 1))
            {
                // Get new mask value
                uint playerNewHandVal = Hand.Evaluate(player | board | card);
                // Get new board value
                uint boardHandVal = Hand.Evaluate(board | card);

                // Is the new mask better than the old one?
                bool handImproved = playerNewHandVal > playerOrigHandVal;

                // This compare ensures we move up in mask type.
                bool handStrongerThanBoard = Hand.HandType(playerNewHandVal) > Hand.HandType(boardHandVal) ||
                                            (Hand.HandType(playerNewHandVal) == Hand.HandType(boardHandVal) &&
                                            Hand.TopCard(playerNewHandVal) > Hand.TopCard(boardHandVal));

                // Check against opponents cards
                bool handBeatAllOpponents = true;
                if (handImproved && handStrongerThanBoard && opponents != null && opponents.Length > 0)
                {
                    foreach (ulong opponent in opponents)
                    {
                        uint opponentHandVal = Hand.Evaluate(opponent | board | card);
                        if (opponentHandVal > playerNewHandVal)
                        {
                            handBeatAllOpponents = false;
                            break;
                        }
                    }
                }

                // If the mask improved then we have an out
                if (handImproved && handStrongerThanBoard && handBeatAllOpponents)
                {
                    // Add card to outs mask
                    retval |= card;
                }
            }

            // return outs as a mask mask
            return retval;
        }