Subtask I: Now that you can represent cards, you'll attempt to represent poker hands. Poker is one of the most played card games in the world. In poker, a player constructs hands of playing cards. For the purpose of this problem, a hand has exactly 5 cards. These hands can be compared using a ranking system, and the player who has the highest-ranking hand wins that deal. Individual cards are ordered by their ranks: A (highest), K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, 2 (lowest). The Ace card is special. While it is normally the highest-ranked card, in a hand involving 5,4,3,2, A, it takes the place of the lowest card (has rank 1 in this particular case). You can learn more from Wikipedia. Poker Hand Representation: For this problem, a poker hand is represented as a set of 5 cards (each card is represented as detailed previously). Hence, the type Hand is given by Hand set [tunlerstr

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

For example, the card 3♦ will be represented as ("Diamond", "3").

Subtask I: Now that you can represent cards, you'll attempt to represent poker hands. Poker is one
of the most played card games in the world. In poker, a player constructs hands of playing cards. For
the purpose of this problem, a hand has exactly 5 cards. These hands can be compared using a ranking
system, and the player who has the highest-ranking hand wins that deal.
Individual cards are ordered by their ranks: A (highest), K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, 2 (lowest). The Ace
card is special. While it is normally the highest-ranked card, in a hand involving 5, 4,3,2, A, it takes the
place of the lowest card (has rank 1 in this particular case). You can learn more from Wikipedia.
Poker Hand Representation: For this problem, a poker hand is represented as a set of 5 cards (each
card is represented as detailed previously). Hence, the type Hand is given by
Hand = set [tuple[str, str]]
You are to implement the following functions:
• The function is_straight_flush(h: Hand) -> bool returns a Boolean indicating whether
the hand h is a straight flush. A straight flush is a hand that contains five cards in seq
of the same suit. Caution: The Ace can either be the highest or the lowest in the sequence. For
example:
nce, all
54, 44,34, 2A, AA
Av,K♥,Q♥,J♥, 10♥
100,9♥,8♥,7♥,6♥
• The function is_four_of_a_kind(h: Hand)
the hand h is a four of a kind. Four of a kind is a poker hand that contains all four cards of one
rank and any other card. For example, 3%,3A,3+,3♥, J♥.
• The function is_full_house (h: Hand) -> bool returns a Boolean indicating whether the
-> bool returns a Boolean indicating whether
hand h is a full-house hand. A full house is a hand that contains three matching cards of one
rank and two matching cards of another rank. For example, 4%,44,4+,7♥,74.
• The functionis_two_pair(h: Hand) -> bool returns a Boolean indicating whether the hand
h is a two-pair hand. A two pair contains two cards of the same rank, plus two cards of another
rank (that match each other but not the first pair), plus any card not of the ranks of the former
two. For example, 9♥,94,44,4%, 10%.
To use the type Hand discussed above, your code should like the following:
# near the top of the file but above all the functions
Hand = set [tuple[str, str]]
# write al1 your functions. for example,
def is_four_of_a_kind(h: Hand) -> bool:
#
#
Of course, different poker hands have different likelihood of occurring-some are harder
than others. For this goal, we're going to write functions to enumerate all possible poker hands and
classify them into different kinds of hands. Your program must generate these lists-don't just precre-
Subtask II:
ate and return them.
1. Implement a function all_hands() -> List[Hand] that takes no arguments and returns a list of
all possible 5-card hands. Did we mention the five cards are distinct? (Hint: Your list should have
size () = 2,598,960.) The use of five nested for-loops is strongly frowned upon.
2. Implement a function all_straight_flush() -> List[Hand] that takes no arguments and re-
turns a list of all possible 5-card hands that are straight flush. (Hint: Your list should have size 40.)
Transcribed Image Text:Subtask I: Now that you can represent cards, you'll attempt to represent poker hands. Poker is one of the most played card games in the world. In poker, a player constructs hands of playing cards. For the purpose of this problem, a hand has exactly 5 cards. These hands can be compared using a ranking system, and the player who has the highest-ranking hand wins that deal. Individual cards are ordered by their ranks: A (highest), K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, 2 (lowest). The Ace card is special. While it is normally the highest-ranked card, in a hand involving 5, 4,3,2, A, it takes the place of the lowest card (has rank 1 in this particular case). You can learn more from Wikipedia. Poker Hand Representation: For this problem, a poker hand is represented as a set of 5 cards (each card is represented as detailed previously). Hence, the type Hand is given by Hand = set [tuple[str, str]] You are to implement the following functions: • The function is_straight_flush(h: Hand) -> bool returns a Boolean indicating whether the hand h is a straight flush. A straight flush is a hand that contains five cards in seq of the same suit. Caution: The Ace can either be the highest or the lowest in the sequence. For example: nce, all 54, 44,34, 2A, AA Av,K♥,Q♥,J♥, 10♥ 100,9♥,8♥,7♥,6♥ • The function is_four_of_a_kind(h: Hand) the hand h is a four of a kind. Four of a kind is a poker hand that contains all four cards of one rank and any other card. For example, 3%,3A,3+,3♥, J♥. • The function is_full_house (h: Hand) -> bool returns a Boolean indicating whether the -> bool returns a Boolean indicating whether hand h is a full-house hand. A full house is a hand that contains three matching cards of one rank and two matching cards of another rank. For example, 4%,44,4+,7♥,74. • The functionis_two_pair(h: Hand) -> bool returns a Boolean indicating whether the hand h is a two-pair hand. A two pair contains two cards of the same rank, plus two cards of another rank (that match each other but not the first pair), plus any card not of the ranks of the former two. For example, 9♥,94,44,4%, 10%. To use the type Hand discussed above, your code should like the following: # near the top of the file but above all the functions Hand = set [tuple[str, str]] # write al1 your functions. for example, def is_four_of_a_kind(h: Hand) -> bool: # # Of course, different poker hands have different likelihood of occurring-some are harder than others. For this goal, we're going to write functions to enumerate all possible poker hands and classify them into different kinds of hands. Your program must generate these lists-don't just precre- Subtask II: ate and return them. 1. Implement a function all_hands() -> List[Hand] that takes no arguments and returns a list of all possible 5-card hands. Did we mention the five cards are distinct? (Hint: Your list should have size () = 2,598,960.) The use of five nested for-loops is strongly frowned upon. 2. Implement a function all_straight_flush() -> List[Hand] that takes no arguments and re- turns a list of all possible 5-card hands that are straight flush. (Hint: Your list should have size 40.)
3. Implement a function all_four_of_a_kind() -> List[Hand] that takes no arguments and re-
turns a list of all possible 5-card hands that are four of a kind. (Hint: Your list should have size
624.)
4. Implement a function all_full_house() -> List[Hand] that takes no arguments and returns
a list of all possible 5-card hands that are full house. (Hint: Your list should have size 3, 744.)
5. Implement a function all_two_pair() -> List[Hand] that takes no arguments and returns a
list of all possible 5-card hands that are two pair. (Hint: Your list should have size 123, 552.)
Performance Expectations: For Subtask I, each function should finish instantaneously (i.e., using
< 0.1 seconds). For Task II, running all these functions from start to finish should take < 30 seconds.
Transcribed Image Text:3. Implement a function all_four_of_a_kind() -> List[Hand] that takes no arguments and re- turns a list of all possible 5-card hands that are four of a kind. (Hint: Your list should have size 624.) 4. Implement a function all_full_house() -> List[Hand] that takes no arguments and returns a list of all possible 5-card hands that are full house. (Hint: Your list should have size 3, 744.) 5. Implement a function all_two_pair() -> List[Hand] that takes no arguments and returns a list of all possible 5-card hands that are two pair. (Hint: Your list should have size 123, 552.) Performance Expectations: For Subtask I, each function should finish instantaneously (i.e., using < 0.1 seconds). For Task II, running all these functions from start to finish should take < 30 seconds.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY