public static long HandDistance(ulong pocket, ulong board)
{
#if DEBUG
if (BitCount(pocket) != 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
uint hv = 0U;
SortedDictionary<uint, long> dict = new SortedDictionary<uint, long>();
// Current Hand
uint pocketHandVal = Hand.Evaluate(pocket | board);
// Build a List of unique hands
foreach (ulong p in Hand.Hands(0UL, board, 2))
{
hv = Hand.Evaluate(p | board);
if (!dict.ContainsKey(hv))
dict.Add(hv, 1);
}
// Find current mask in the sorted list
long count = dict.Count-1;
foreach (uint handval in dict.Keys)
{
if (handval == pocketHandVal)
return count;
count--;
}
return -1;
}