嗨,我需要帮助来弄清楚如何从扑克手中找到两对。
我相信我需要计算不同纸牌的数量,然后根据以下逻辑判断两张纸牌是否为两副纸牌:两副纸牌是一张包含两张相同级别的纸牌,两张不同级别的纸牌和一张第二张纸牌的扑克手第三等级;我只是不确定如何去做。
任何帮助表示赞赏。
这是我的扑克牌桌
+----------+------+------+------+-----------+-----------+
| cardName | face | type | suit | faceValue | gameValue |
+----------+------+------+------+-----------+-----------+
| AC | no | A | C | 1 | 14 |
| 2C | no | 2 | C | 2 | 2 |
| 3C | no | 3 | C | 3 | 3 |
| 4C | no | 4 | C | 4 | 4 |
| 5C | no | 5 | C | 5 | 5 |
+----------+------+------+------+-----------+-----------+
和扑克牌手
+----------+--------+----+-----+----+----+----+----------+
| playerId | gameId | C1 | C2 | C3 | C4 | C5 | handType |
+----------+--------+----+-----+----+----+----+----------+
| 12789 | 17MET | QH | QS | 3D | 3C | 3H | |
| 12789 | 82SAT | 7C | 4S | 4D | 4C | 3H | |
| 56347 | 03DEC | 6S | 3S | 3H | 3C | 3D | |
| 56347 | 23WSA | KH | 10H | 7H | 3H | AH | |
| 56347 | 30DEC | AC | KH | KD | 3D | 3S | |
+----------+--------+----+-----+----+----+----+----------+
我需要最后一行
+----------+--------+----+-----+----+----+----+----------+
| playerId | gameId | C1 | C2 | C3 | C4 | C5 | handType |
+----------+--------+----+-----+----+----+----+----------+
| 56347 | 30DEC | AC | KH | KD | 3D | 3S | |
+----------+--------+----+-----+----+----+----+----------+
最佳答案
我会通过UNION预先将每张卡片进行汇总,以获取普通卡片,而不管西装如何。然后通过...申请一个小组
select PlayerID, GameID, left( c1,1 ) as OneCard
from PlayerHand
union all
select PlayerID, GameID, left( c2,1 ) as OneCard
from PlayerHand
union all
select PlayerID, GameID, left( c3,1 ) as OneCard
from PlayerHand
union all
select PlayerID, GameID, left( c4,1 ) as OneCard
from PlayerHand
union all
select PlayerID, GameID, left( c5,1 ) as OneCard
from PlayerHand
一个人/场游戏将为您提供以下内容
playerid gameid onecard
12789 17MET Q
12789 17MET Q
12789 17MET 3
12789 17MET 3
12789 17MET 3
现在,您可以轻松看到卡片并进行简单的汇总
select
preQuery.playerid,
preQuery.gameid,
preQuery.onecard,
count(*) as CntThisCard
from
( the entire union query above ) preQuery
group by
preQuery.playerid,
preQuery.gameid,
preQuery.onecard
having
count(*) > 1
根据您的数据,这将返回以下行...
playerid gameid onecard cntThisCard
12789 17MET Q 2
12789 17MET 3 3 This is a full-house
12789 82SAT 4 3 Three-of-a-kind
56347 03DEC 3 4 Four-of-a-kind
56347 23WSA (not returned in data set)
56347 30DEC K 2
56347 30DEC 3 2 Two-pair
所以现在,如何提取任何“手”,这也将被汇总...
select
QryLvl2.PlayerID,
QryLvl2.GameID
from
( the entire query above returning per-card count ) QryLvl2
where
QryLvl2.CntThisCard = 2
group by
QryLvl2.PlayerID,
QryLvl2.GameID
having
count(*) = 2
在这种情况下,由于您显式地寻找两对,因此我的where子句明确地仅寻找手中有2对的牌。通过count(*)= 2的组表示两张不同的牌,这将给您最后的问题。
但是从第二个中可以看出,您还可以立即识别出4张,满屋,3张,2对和单张高牌的更好手。
然后,您可以将纸牌表简化为用于确定一对Jack / 3的手牌/数字,而不是10和9的一手牌,因为您不关心纸牌的适合性,只关心与其他纸牌相比的面值手。