Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 Part 2: Single Player Rummy Game with Dice and strange deck (80 points) To clarify Part 2 specifications, I have provided sample tests for

2 Part 2: Single Player Rummy Game with Dice and strange deck (80 points)

To clarify Part 2 specifications, I have provided sample tests for each required function inside of its docstrings ina3_game_xxxxxx.py. Furthermore, you can find example run of the whole game below and its associated video at the link below. The behaviour implied by the sample tests/runs and the video should be considered as required spec- ifications in addition to what is explained in this document. Finally, you can also find one extra example run of the beginninng of the game that the end of the assgnment.

Here is the link to the video: https://youtu.be/Zwl2qTyPnHoDescription:

A card in a standard deck has a suit (in particular, one of four suits: r, , q, |) and a rank (one of 13 ranks: A, 2, 3, ..., 10, J, Q, K). Taking every pair of a suit and a rank gives rise to a standard deck of (4x13=) 52 cards. Imagine you have access to only an old fashion terminal that cannot display fancy characters like: r, , q, | but yet you would like to make a card game. You would first need to decide how to represent a card. One way to do that would be to represent a card by a 3 digit integer where the first digit (1 to 4) represents a suit and the two last digits (1 to 13) represent ranks. Lets call such a deck, a strange deck.

For part 2 of the assignment, you will need to make a (heavily) modified version of Rummy card game with this strange deck. In Rummy, the main goal is to build melds which consists of sets, two, three or four of a kind of the same rank; or progression, three or more cards in a sequence of consecutive ranks, of the same suit. So the set r10, q10, |10 forms three of a kind. And the set/sequence 7q, 8q, 9q, 10q, 11q forms a progression. In our strange deck, 210, 110, 310 would form three of a kind (since the first digit is a suit, so the ranks are 10, 10, 10) and the set 309, 307, 311, 308, 310 is a progression (since they all have a suit 3 and 07, 08, 09, 10, 11 is sequence of consecutive integers). Note that 201, 302, 303 is not a progression. Although 01, 02, 03 is a sequence of consecutive integers, the three cards do not have the same suit (some have suit 2 and some 3) so this is not a progression.

3

So the game that you will develop needs to go as follows: (The goal of the player is to get rid of all of her cards in as few rounds of the game as possible)

Step 0: The strange deck is created and shuffled. (In order to test your game more quickly you can reduce the numer of ranks to less than 13 and more than 3). In your implementation the created deck needs to be a list of integers representing a strange deck. Top of the deck is considered the last card in the list. 
Step 1: The player is dealt 7 cards from the top of the strange deck. 
Step 2: The following steps are repeated until the player runs out of the cards: 
 Step 3: The player rolls a dice If the player gets a 1: 
 The player can discard any one card she likes. After that, the current round 
 is over and the game goes back to Step 2. If instead the player gets num=2,3,4,5 or 6: 
 The player if first delt, from the top of the deck, num or len(deck) cards, whichever is smaller. 
 The player then keeps on discarding melds from her hand until she has no more melds. You program has to check that the set of cards that the player chooses indeed forms a valid meld before discarding them from the player's hand. Once she decides she is out of melds, the round is over 
 and the game goes back to Step 2. 
(Note that once the deck is empty and the player has no more melds, no melds can ever be created again. Thus the player has to wait for 1 on the dice. In order to avoid that unpleasantry your game should roll 1 i.e. set num to 1, in each round that starts with empty deck.) 
Finally, once the player is out of cards, the total number of rounds is reported. 

As usual, whenever you ask the player for some input you should make sure they give you the required kind of input. You may assume that the player will follow instructions and give you a correct type of date but not the correct values. For example, if you are asking for an integer between 3 and 99, you may assume that the player will give you an integer but not that she will give you an integer in the correct range. Thus you should keep on repeating the question until you get a valid answer. Similarly if you ask the player for a meld, you may assume that the player will give you a set of 3 digit integers, but you will need to test if these cards are indeed in the players hand and that they form a meld.

As in the previous assignment, I provided you with the starter code in the file called, a3_game_xxxxxx.py. Start by replacing xxxxxx in the file name with your student number. Then open the file. Your solution (code) for this part must go into that file in the clearly indicated spaces only. You are not allowed to delete or comment-out or change any parts of the provided code except for the keywords pass.

In a3_game_xxxxxx.py, there are many functions with code missing. You must complete and use all of those func- tions. Your function should behave as explained in the function description and the example runs. All rea given in the docstrings. You also need to complete the main.

def make_deck(num): '''(int)->list of int Returns a list of integers representing the strange deck with 4 suits and num ranks.

Precondition: 3=

>>> deck=make_deck(13) >>> deck [101, 201, 301, 401, 102, 202, 302, 402, 103, 203, 303, 403, 104, 204, 304, 404, 105, 205, 305, 405, 106, 206, 306, 406, 107, 207, 307, 407, 108, 208, 308, 408, 109, 209, 309, 409, 110, 210, 310, 410, 111, 211, 311, 411, 112, 212, 312, 412, 113, 213, 313, 413]

>>> deck=make_deck(4) >>> deck [101, 201, 301, 401, 102, 202, 302, 402, 103, 203, 303, 403, 104, 204, 304, 404] ''' pass

def shuffle_deck(deck): '''(list of int)->None Shuffles the given list of strings representing the playing deck

Here you should use random.shuffle function from random module. Since shufflling is random, exceptionally in this function your output does not need to match that show in examples below:

>>> deck=[101, 201, 301, 401, 102, 202, 302, 402, 103, 203, 303, 403, 104, 204, 304, 404] >>> shuffle_deck(deck) >>> deck [102, 101, 302, 104, 304, 103, 301, 403, 401, 404, 203, 204, 303, 202, 402, 201] >>> shuffle_deck(deck) >>> deck [402, 302, 303, 102, 104, 103, 203, 301, 401, 403, 204, 101, 304, 201, 404, 202] ''' pass

def deal_cards_start(deck): '''(list of int)-> list of int

Returns a list representing the player's starting hand. It is obtained by dealing the first 7 cards from the top of the deck. Precondition: len(dec)>=7 ''' pass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions