public static int GapCount(ulong mask)
{
int start, end;
if (BitCount(mask) != 2) return -1;
uint bf = CardMask(mask, Clubs) |
CardMask(mask, Diamonds) |
CardMask(mask, Hearts) |
CardMask(mask, Spades);
if (BitCount(bf) != 2) return -1;
for (start = 12; start >= 0; start--)
{
if ((bf & (1UL << start)) != 0)
break;
}
for (end = start - 1; end >= 0; end--)
{
if ((bf & (1UL << end)) != 0)
break;
}
// Handle wrap
if (start == 12 && end == 0) return 0;
if (start == 12 && end == 1) return 1;
if (start == 12 && end == 2) return 2;
if (start == 12 && end == 3) return 3;
return (start-end-1 > 3 ? -1 : start-end-1);
}