Inspired by this challenge and related to this one.
Background
Badugi [bæduːɡiː] is a low-ball draw-poker variant.
The Pokerstars World Cup Of Online Poker $1K event starts within 3 hours and I'll need to know how good my hands are!
The game uses a standard deck of 52 cards of four suits and thirteen ranks. The suits are unordered and shall be labelled cdhs
; the ranks - ordered from highest K
to lowest A
- are KQJT98765432A
. As such the full deck may be represented as follows (space separated):
Kc Kd Kh Ks Qc Qd Qh Qs Jc Jd Jh Js Tc Td Th Ts 9c 9d 9h 9s 8c 8d 8h 8s 7c 7d 7h 7s 6c 6d 6h 6s 5c 5d 5h 5s 4c 4d 4h 4s 3c 3d 3h 3s 2c 2d 2h 2s Ac Ad Ah As
Each player is dealt four cards from the deck, there are four betting rounds with three drawing rounds in-between (a player always has four cards, they have the option of changing 0-4 of their cards with new ones from the dealer on each of the three drawing rounds).
If more than one player is still active after all these rounds there is a showdown, whereupon the strongest hand(s) win the wagered bets.
The game is played low-ball, so the lowest hand wins, and as mentioned above A
(ace) is low. Furthermore the hand ranking is different from other forms of poker, and can be somewhat confusing for beginners.
The played "hand" is the lowest ranked combination made from the highest number of both "off-suit" (all-different-suits) and "off-rank" (all-different-ranks) cards possible (from the four held cards). That is: if one holds four cards of both distinct suits and distinct ranks one has a 4-card hand (called a "badugi"); if one does not have a 4-card hand but does have some set or sets of three cards of both distinct suits and distinct ranks one has a 3-card hand (one chooses their best); if one has neither a 4-card hand or a 3-card hand one probably has a 2-card hand, but if not one has a 1-card hand.
As such the best possible hand is the 4-card hand
4-3-2-A
- the lowest off-rank cards of four different suits, often termed a "number-1". The weakest possible hand would be the 1-card handK
and is only possible by holding exactlyKc Kd Kh Ks
.Note that
4c 3h 2c As
is not a "number-1", since the4c
and2c
are of the same suit, but it is the strongest of the 3-card hands,3-2-A
, it draws with other3-2-1
s (likeKh 3d 2s Ah
) and beats all other 3-card hands but loses to all 4-card hands (which could be as weak asK-Q-J-T
).- The other possible 3-card hand that could be made from
4c 3h 2c As
is4-3-A
, but that is weaker (higher) so not chosen.
- The other possible 3-card hand that could be made from
Similarly
8d 6h 3s 2h
is a 3-card hand played as8-3-2
- there are two off-rank off-suit combinations of size 3 and8-3-2
is better (lower) than8-6-3
since the three (or "trey") is lower than the six.
Comparing hands against one another follows the same logic - any 4-card beats any 3-card, any 3-card beats any 2-card and any 2-card beats any 1-card, while hands of the same number of used cards are compared from their highest rank down to their lowest (for example: 8-4-2
beats 8-5-A
but not any of 8-4-A
, 8-3-2
or 7-6-5
)
The challenge:
Given two unordered-collections each of four cards, identify the one(s) which win a Badugi showdown (identify both if it is a draw).
The input may be anything reasonable:
- a single string of all eight cards as labelled above (with or without spaces) with the left four being one hand and the right the other (with an optional separator); or a list of characters in the same fashion
- a list of two strings - one per hand, or a list of lists of characters in the same fashion
- two separate strings or list inputs, one per hand
- the cards within the hands may be separated already too (so a list of lists of lists is fine)
Note, however:
- the cards may not be arranged into any order prior to input
- ...and the suits and ranks are fixed as the character labels specified here - If your language does not support such constructs just suggest something reasonable and ask if it is an acceptable alternative given your languages constraints.
The output should either be
- formatted the same as the input, or a printed representation thereof; or
- be one of three distinct and consistent results (e.g.:
"left"
,"right"
,"both"
; or1
,2
,3
; etc.)
Really - so long as it is clear which of the two inputs are being identified it should be fine.
Test cases
input -> output
(notes)
----------------------------------------------------------------------------
3c 2s 4d Ah - As 3h 2d 4h -> 3c 2s 4d Ah
(4-card 4-3-2-A beats 3-card 3-2-A)
3c 2s 4d Ah - As 2c 3d 4h -> 3c 2s 4d Ah - As 2c 3d 4h
(4-card 4-3-2-A draws with 4-card 4-3-2-A)
2d Ac 4h 3c - Kh Ad 9s 2c -> Kh Ad 9s 2c
(3-card 4-2-A loses to 4-card K-9-2-A)
Kc Tc Qc Jc - Ac Ad Ah As -> Ac Ad Ah As
(1-card T loses to 1-card A)
9c 9h Qc Qh - Qs Kh Jh Kd -> Qs Kh Jh Kd
(2-card Q-9 loses to 3-card K-Q-J)
2d 5h 7c 5s - 2h 3c 8d 6c -> 2d 5h 7c 5s
(3-card 7-5-2 beats 3-card 8-3-2)
3s 6c 2d Js - 6h Jd 3c 2s -> 6h Jd 3c 2s
(3-card 6-3-2 loses to 4-card J-6-3-2)
Ah 6d 4d Ac - 3h 2c 3s 2s -> 3h 2c 3s 2s
(2-card 4-A loses to 2-card 3-2)
2h 8h 6h 4h - 6d 2d 5d 8d -> 2h 8h 6h 4h - 6d 2d 5d 8d
(1-card 2 = 1-card 2)
This is code-golf, so the shortest code in bytes wins per-language, and the shortest code overall wins. Don't let golfing languages put you off submitting in other languages, and ...have fun!
[['3c', '2s', '4d', 'Ah'], ['As', '3h', '2d', '4h']]
reasonable? \$\endgroup\$O
to the front. \$\endgroup\$