Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Purpose: To implement an ADT from a requirements specification, Degree of Difficulty: Moderate A pack of playing cards has four suits, 'H. D. 'S and
Purpose: To implement an ADT from a requirements specification, Degree of Difficulty: Moderate A pack of playing cards has four suits, 'H. D. 'S and 'C: Hearts, Diamonds, Spades and Clubs) and a value 1 through 13 making a total of 52 cards. The following symbols map to the following values: A-1, 2-2,3-3. 4-4,5-5.6-6, 7-7 8-8. 9-9. 10-10. J-11. 0-12, K-13 with A being the Ace, being the Jack, Q being the Queen and K being the King). The suit a card belongs to does not affect its value. so, 2H and 2 both have the value of 2. On the other hand, OH has a higher value of 12 compared to AH that has a value of 1 You are required to design and implement an ADT named card. A card is a data structure that carries out some operations on a pack of cards. Each card itself will be stored as a string, with a numeric value preceding a letter fex 'D' for the jack of diamonds "SH' being the 5 of hearts, etc) The card ADT has 6 operations: . Card.create Creates and returns a list of all possible cards that can be drawn from the 52 card playing deck. That is all possible combinations of the suits of cards TH D S Cl and the values 1 through 13 (but using A as 1. Jas 11 as 12. Kas 13) print ( Card.create()) C A#"28","3","4H","5","6","7","BH","98","104","JH","H",""...] # Repeated for the 3 other suits (0.3.c) . Card.deal (nun cards, tum players, deck) Randomly deals a number of cards to a number of play. ers from the given deck list of card stringsl. When a card is drawn, it is removed from the deck dealo returns each player's hand as a list of tists. It is up to you to decide what happens if the deck runs out of cards before all players have been dealt all of their cards cards_dealt - Card deal (5. 3. deck) print(cards_dealt) [["50","107","08","80". JH 1. [JC, 2.80"AS","9C). ["H","6","9","103","8"]). . Card.value(card) Takes in the string of a card, and returns its integer value. Remember. its suit does not affect its value. Also remember that A-1. J-11, Q-12. K-13. For example. Card value(KS)returns 13. and Card value('40") returns 4 Card.highest(list_of_carda) Takes a list of cards, and returns the the card string with the highest value. For example: highest card - Card.highest (C"50","101","98",C","J']) print (highest-card) # outputs: "98" . Card.lovest (list_of_cards) Takes a list of cards, and returns the string with the lowest value. For example: lovest.card - Card. lowest (["50","101","08","80","4H"]) print(lowest_card) outputs: "50
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started