public static int OnePair(Hand hand) { long bits = (hand._Bits_CntRank & 0x2222222222222L); if (bits == 0) { return(-1); } return(BitsFunction.LargeBit(bits, 52) / 4); }
public static int TwoPair(Hand hand) { long bits = (hand._Bits_CntRank & 0x2222222222L); if (BitsFunction.CountBits(bits) >= 2) { return(BitsFunction.LargeBit(bits, 52) / 4); } return(-1); }
public static int FourOfAKind(Hand hand) { // 假設只用1副牌 long bits = (hand._Bits_CntRank & 0x4444444444444L); if (bits == 0) { return(-1); } return(BitsFunction.LargeBit(bits, 52) / 4); }
public static int Straight(Hand hand) { if (BitsFunction.CountBits(hand._Bits_Rank) < 5) { return(-1); } if ((hand._Bits_Rank & 0x1F00) == 0x1F00) { return(8); // AKQJT } if ((hand._Bits_Rank & 0x0F80) == 0x0F80) { return(7); // 9TJQK } if ((hand._Bits_Rank & 0x07C0) == 0x07C0) { return(6); // 89TJQ } if ((hand._Bits_Rank & 0x03E0) == 0x03E0) { return(5); // 789TJ } if ((hand._Bits_Rank & 0x01F0) == 0x01F0) { return(4); // 6789T } if ((hand._Bits_Rank & 0x00F8) == 0x00F8) { return(3); // 56789 } if ((hand._Bits_Rank & 0x007C) == 0x007C) { return(2); // 45678 } if ((hand._Bits_Rank & 0x003E) == 0x003E) { return(1); // 34567 } if ((hand._Bits_Rank & 0x001F) == 0x001F) { return(0); // 23456 } return(-1); }
public static int Flush(Hand hand) { // 不計花式大小, 只計牌大小 if (hand._Bits_CntSuit == 0x5000) { return(BitsFunction.LargeBit(hand._Bits_CardS, 13)); } if (hand._Bits_CntSuit == 0x0500) { return(BitsFunction.LargeBit(hand._Bits_CardH, 13)); } if (hand._Bits_CntSuit == 0x0050) { return(BitsFunction.LargeBit(hand._Bits_CardC, 13)); } if (hand._Bits_CntSuit == 0x0005) { return(BitsFunction.LargeBit(hand._Bits_CardD, 13)); } return(-1); }
public static int StraightFlush(Hand hand) { #region fast filter // 限5張牌時可快速檢查 if (hand.Count == 5) { // 如果沒有5張同色可能,不可能為Straight flush // 5(二進制101), 應該有2bit才對 // 這裡的檢查4條是可以過的 if (BitsFunction.CountBits(hand._Bits_CntSuit & 0x5555) != 2) { return(-1); } // 如果有某種牌超過一張,不可能為Straight flush if ((hand._Bits_CntRank & 0xEEEEEEEEEEEEEL) != 0) { return(-1); } } #endregion // Check Func <int, int> fnCheck = (bits) => { // fast filter if (bits < 0x001F) { return(-1); } // fast filter if (BitsFunction.CountBits(bits) < 5) { return(-1); } if ((bits & 0x1F00) == 0x1F00) { return(8); // AKQJT } if ((bits & 0x0F80) == 0x0F80) { return(7); // 9TJQK } if ((bits & 0x07C0) == 0x07C0) { return(6); // 89TJQ } if ((bits & 0x03E0) == 0x03E0) { return(5); // 789TJ } if ((bits & 0x01F0) == 0x01F0) { return(4); // 6789T } if ((bits & 0x00F8) == 0x00F8) { return(3); // 56789 } if ((bits & 0x007C) == 0x007C) { return(2); // 45678 } if ((bits & 0x003E) == 0x003E) { return(1); // 34567 } if ((bits & 0x001F) == 0x001F) { return(0); // 23456 } return(-1); }; // 大小不計花式 if (hand._Bits_CntSuit == 0x5000) { return(fnCheck(hand._Bits_CardS)); } if (hand._Bits_CntSuit == 0x0500) { return(fnCheck(hand._Bits_CardH)); } if (hand._Bits_CntSuit == 0x0050) { return(fnCheck(hand._Bits_CardC)); } if (hand._Bits_CntSuit == 0x0005) { return(fnCheck(hand._Bits_CardD)); } return(-1); }
public static int HighCard(Hand hand) { return(BitsFunction.LargeBit(hand._Bits_Rank, 13)); }