Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design and develop Card, Deck, and Tableau classes The Card class (20 marks) represents a playing card, where each has a rank (2, 3, ,

Design and develop Card, Deck, and Tableau classes

The Card class (20 marks) represents a playing card, where each has a rank (‘2’, ‘3’, …, ‘9’, ‘T’, ‘J’, ‘Q’, ‘K’, and ‘A’) and a suit (‘C’, ‘D’, ‘H’, and ‘S’) field. When two cards have the same rank, suit ranking should be used to determine their order. The suit ranking follows alphabetical order (from lowest to highest): clubs, diamonds, hearts, and spades. This class should implement the __init__, __repr__, and __str__ methods and support comparisons (==, !=, <, <=, >, >=).

The Deck class (20 marks) represents a deck of cards (stored in a list of Card fields) and uses the Card class. A deck of cards may have up to 52 cards. The class must support the following methods/operations:

• __init__(self): Create a standard deck of cards (no jokers). The deck should contain cards in ascending order (2C, 3C, …, AS).

• __len__(self), __repr__(self), and __str__(self)

• shuffle(self): Shuffle the deck to mix up the cards.

• draw(self): Select and return one card (the top card) from the deck. This card is removed from the deck.

The Tableau class (40 marks) represents a tableau of playing cards (a list of lists of Card fields). A tableau is a collection of piles of cards from the same deck of cards. There can be up to nine piles. The first pile has one card, the second has two cards, and so on. The picture below shows a tableau that has four piles. In the picture the Jack of Clubs is the card at the top of the third pile. The Tableau class uses the Card class and the Deck class. It should support the following methods/operations:

• __init__(self): Create an empty tableau of cards which includes its shuffled complete deck.

• __repr__(self) and __str__(self). The str method should return the string below for the tableau in the picture. 9D 10S 7H JH 8D QC KH JC QD KC

• add_pile(self): Adds the next pile to the tableau by drawing the correct number of cards from the tableau’s deck.

• find_lowest_top(self): Return, without removing, the lowest card among those at the top of the piles and the pile number where it is located. In the picture above, the lowest card is in pile 2 and it is the 8 of Diamonds.

• find_highest_top(self): Return, without removing, the highest card among those at the top of the piles and the pile number where it is located. In the picture above, the highest card is in pile 4 and it is the King of Clubs.

• is_ascending(self): Check if the top cards in the piles are in ascending order (from left to right).

• is_descending(self): Check if the top cards in the piles are in descending order (from left to right). • get_tops(self): Return a Python list of the top cards in the piles

• get_tops(self): Return a Python list of the top cards in the piles

Step by Step Solution

There are 3 Steps involved in it

Step: 1

The Card class encapsulates the characteristics of a single playing card It stores information on th... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Basic Statistics For The Behavioral Sciences

Authors: Gary Heiman

7th Edition

1133956521, 9781133956525

More Books

Students also viewed these Programming questions