CS303E Assignment 9

Due: Monday, July 115 by 11 pm

Provided Program File Name (Use this to complete your program.): racko.py

Submit to Assignment 9 on Gradescope via Canvas

Purpose: To practice working with lists, writing functions to a specification, and determining how to use functions to accomplish a task.

Limitations: You may only use the Python syntax and language features covered in the book chapters 1 - 7. Do not call the sorted function in the is_sorted function you write. Implement that function without creating any new lists.

Review the assignment guidelines.

This assignment is a little different than most assignments so far. The program you are writing is not trivial. Therefore I am providing some of the code and specifying the functions you must complete. You can add other functions if you like, but you must complete the specified functions and use them to complete the program.

Based on a Nifty Assignment.

Explanation of game play:

Rack-O is a card and number game created by the game company Milton Bradley. The goal is to get your hand of cards into sorted, ascending order.

The deck consists of 60 cards, numbered 1 through 60.

Each player has a rack of 10 cards. Our program allows the users to have racks of between 5 and 10 cards. The rest of this explanation assumes we are using the standard rack size of 10.

The deck is shuffled and each player is dealt 10 cards. The cards are placed, in the order dealt, into a player's rack. First card dealt goes to slot 1, second card dealt goes to slot 2, and forth up to the 10th card being dealt and placed in the 10th slot. Players cannot move the cards around in the rack.

After dealing 10 cards to each player to create their initial rack, the top card of the deck is flipped over to form the discard pile.

Players then take turns trying to get a rack of cards with the numbers in sorted, ascending order.

During their turn a player can either:

1. Take the top card of the discard pile and replace one card in their rack with that card from the discard pile. The card that was previously in the rack goes to the top of the discard pile. If a player takes the top card of the discard pile they must use it to replace one the cards in their rack. They cannot simply place it back at the top of the discard pile.

2. Take the top card of the deck. A player may choose to replace one card in their rack with the card they drew (and the card that was previously in the rack goes to the top of the discard pile) or the player may choose to not use the drawn card in which case the drawn card is placed on the top of the discard pile.

After a player takes a turn if the cards in their rack are in sorted ascending order, the game is over and they win.

If all of the cards are ever drawn from the deck the discard pile is shuffled to become the draw deck, the top card is flipped over to become the top of a new discard pile, and play proceeds. Note, there are tests where the deck runs out of cards. You must implement that behavior to pass all the tests on GradeScope.

Download the provided racko.py file. Complete the main function and the specified functions. Do not change the function names or parameter lists. You may add additional functions, but the program must use the specified functions to play the game. Note, we are treating the first element of the list, at index 0, as the top of the deck. Likewise the first element of the discard list is treated as the top of the discard pile. It may be more efficient to treat the end of the list as the top of the decks, but the lists in this case are so small we will stick with the intuitive approach, treating the start of the list, the element at index 0, as the top of a deck of cards.

Complete the following functions and use them to complete the program so that is allows to people at the same keyboard to play a game of Rack-O.

Here is a file with multiple runs of the program. Given the same inputs and the same seed your output shall match this exactly.
The first run is  small game with rack sizes of 5. The second game is one with rack sizes of 10. The third game shows what happens when the deck is empty and the discard pile must be shuffled to become the deck.

Note, there are tests where the deck runs out of cards. You must implement that behavior to pass all the tests on GradeScope.

 I strongly recommend you check your output and the expected output with a diff program such as https://www.diffchecker.com/.

Recall, you must complete the header included in racko.py.