$24
Texas Hold ‘em
A playing card deck contains 52 cards. Each card has one suit (either clubs, diamonds, hearts or spades) and one card number (Pip cards: 1~10 in which ‘1’ is called “ace”. Face cards: Jack, Queen, and King). This assignment is based on a common card game in the world called “Texas Hold’em (德州撲克)”. There are five “community cards” on the table (which is open to everybody) and own two “hole cards” for each player (private to this
player alone). Each player seeks the best five-card poker hand from any combination of the seven cards of the five community cards and their own two hole cards. Only cards’ numerical ranks matter; suit values are irrelevant in this game. For example,
Community cards
Player1 Player2
The best five-card poker hand of player1:
The best five-card poker hand of player2:
Both players have a hand of Full House. In Taxes Hold ‘em, although player1 has “Ace of spade” in his card poker hand, suit values are irrelevant. Therefore they tie(平 手).
Here is another example,
Community cards
Player1 Player2
The best five-card poker hand of player1:
The best five-card poker hand of player2:
Both players have a hand of Two Pairs. In Texas Hold ‘em, the numerical rank is of sole importance and suit value are irrelevant. Both players have a pair of ace. They need to compare the second pair. Therefore, player 1 wins.
Hands are ranked by their patterns as follows (from the largest to the smallest).
Straight Flush (同花順). Five cards of the same suit with consecutive values, ranked by the highest card in the hand. Note that “A K Q J 10” is considered the largest straight and “5 4 3 2 A” is considered the smallest. In Texas Hold ‘em, Ace has 14 points, but Ace is represented as 1 point in “5 4 3 2 A”. That is, “5 4 3 2 A” < “6 5 4 3 2”<“76543”<…<“KQJ109”<“AKQJ10”.
Quads (鐵 支). Four cards with the same number.
Full House (葫蘆). Three cards of the same value, with the remaining two cards forming a pair.
Flush (同花). Hand contains five cards of the same suit.
Straight (順 子). This type of hand contains five cards with consecutive values, but five cards are not the same suit.
Trips (三條). Three of the cards in the hand have the same value and the remaining two cards do not have the same value.
Two Pairs (兩兩對). This type of hand contains two different pairs.
Pair (對 子). Two of the five cards in the hand have the same value and the last three cards do not have the same value.
High Card (胡亂). Hands which do not fit any category.
What you need to do?
Write a program that determines the best pattern of a card hand for each player and find the winner(s). In your input, there are n players (2 ≤ n ≤ 10), the 5 community cards, and n players’ own 2 hole cards. There is only one card deck in each Texas Hold ‘em game.
That is, each card appears only one time in each Texas Hold ‘em game. The suits are represented by the characters S, H, D, C (for spade, heart, diamond, and club). The values are represented by 2~9, T (representing 10), J, Q, K, and A. Your program should output the sorted pattern according to the following rules. Suits are ranked as Spade Heart Diamond Club.
The order of Input and Output order:
The number of players
5 Community cards
2 hole cards of Player 1
2 hole cards of Player 2
……
2 hole cards of Player n
The best pattern of Player 1
The best pattern of Player 2
……
The best pattern of Player n
Who win(s) this game
For Straight Flush, Flush, Straight, and High Card, your output should be sorted in descending order, its pattern and the winner(s). In Straight, you must choose the bigger suit if there are two (or more) cards with the same number you can select.
Sample input and Output 1: Illustration:
4
H6 H9 C3 S4 H8
S2 C5
H7 H5
CQ D2
HT HK
1:
H6
C5
S4 C3 S2 Straight
2:
H9
H8
H7 H6 H5 Straight Flush
3: CQ H9 H8 H6 S4 High Card
1
2
4: HK HT H9 H8 H6 Flush
Player 2 win(s) this game.
For Quads, you should first output the sorted suit of four of a kind, followed by the largest single card. You should also output its pattern and the winner(s).
Sample input and Output 2: Illustration:
2
ST SJ H9 CT D7
C8 D3
HT DT
SJ ST H9 C8 D7 Straight
ST HT DT CT SJ Quads Player 2 win(s) this game.
1
2
For Full House, you should first output the sorted suit of the largest three of a kind, followed by the sorted suit of the largest pair. You should also output its pattern and the winner(s).
Sample input and Output 3: Illustration:
2
CA D7 C6 HA H7
SA C8
S7 DA
SA HA CA H7 D7 Full House
HA DA CA S7 D7 Full House Player 1 2 win(s) this game.
1
2
For Trips, you should first output the sorted suit of three of a kind, followed by the sorted number of two larger single cards. You should also output its pattern and the winner(s).
Sample input and Output 4: Illustration:
3
CA DK C6 HA HJ
D3 DT
SA C8
S7 DA
HA DK HJ DT C6 High card
SA HA CA DK HJ Trips
HA DA CA DK HJ Trips Player 2 3 win(s) this game.
1
2
3
For Two Pairs, you should first output the sorted suit of larger pair and the sorted suit of smaller pair, followed by the largest single card. You should also output its pattern and the winner(s).
Sample input and Output 5: Illustration:
2
CK SJ DJ C4 S9
SK C9
D4 H2
SK CK SJ DJ S9 Two Pairs
SJ DJ D4 C4 CK Two Pairs Player 1 win(s) this game.
1
2
For Pair, you should first output the sorted suit pair, followed by the sorted number of three larger single cards. You should also output its pattern and the winner(s).
Sample input and Output 6: Illustration:
2
S5 C9 SA H6 D4
H9 S2
C8 D7
H9 C9 SA H6 S5 Pair
C9 C8 D7 H6 S5 Straight Player 2 win(s) this game.
1
2
NTHU Online Judge information: (Update recently)
Problem ID:
Problem title: 231001_11/10_Assignment1
Guidelines
Mark weightings: Correctness 50% + Readability 50%.
Correctness: Make sure you understand what the program should do in every case (including special cases).
Readability: Use comments to explain your logic.
You are welcome to discuss with each other, but DO NOT COPY OTHER PEOPLE’S WORK. Plagiarism is a serious offense. Not only will you get no points in this assignment, but you may also be reported to the university.
Program Style:
Your program should include a number of functions. Their functionality should be well-defined, easily understandable, and clearly documented as comments within the source code.
The efficiency of your program should be reasonable. However, don’t spend too much time just to speed it up while making the code difficult to read.