In Checkpoint B, the game will be playable as a two-player game, albeit the competition will be a computer player who makes moves randomly. Implement these functions from the template following the description (specification) in their docstring: shuffle() replace_deck() deal_initial_hands() play_hand() should be extended to support 'random' mode The main function to drive the game has been provided. In 'interactive' mode, play_hand() should behave the same way as in Part A In 'random' mode, the computer selects actions randomly. Compared to 'interactive' mode: Every call to input() for the player should be replaced with a random choice Extra printed feedback for the player should be omitted For testing, we have hard-coded the seed 26 for the random source Hint: you can use random.randint(x, y) to select a number between x and y, inclusive. In particular, "flipping a coin" would be accomplished via random.randint(0, 1) Sample input/output When the inputs are: yes 1 no yes 9 The expected behavior is (inputs are shown in-line) -------------------------------------------------- Deck: [3, 2] Discard pile: [7] Your current rack is: [9, 5, 1] Computer rack is: [4, 8, 6] The top discard card is 7 Do you want it? (yes or no): yes Enter the card in your rack to discard: 1 Your new rack is: [9, 5, 7] Computer rack is: [4, 8, 1] -------------------------------------------------- Deck: [3, 2] Discard pile: [6] Your current rack is: [9, 5, 7] Computer rack is: [4, 8, 1] The top discard card is 6 Do you want it? (yes or no): no The card from the deck is 2 Do you want it? (yes or no): yes Enter the number of the card you want to kick out: 9 Your new rack is: [2, 5, 7]
In Checkpoint B, the game will be playable as a two-player game, albeit the competition will be a computer player who makes moves randomly.
Implement these functions from the template following the description (specification) in their docstring:
- shuffle()
- replace_deck()
- deal_initial_hands()
- play_hand() should be extended to support 'random' mode
The main function to drive the game has been provided.
- In 'interactive' mode, play_hand() should behave the same way as in Part A
- In 'random' mode, the computer selects actions randomly. Compared to 'interactive' mode:
- Every call to input() for the player should be replaced with a random choice
- Extra printed feedback for the player should be omitted
- For testing, we have hard-coded the seed 26 for the random source
Hint: you can use random.randint(x, y) to select a number between x and y, inclusive. In particular, "flipping a coin" would be accomplished via random.randint(0, 1)
Sample input/output
When the inputs are:
yes
1
no
yes
9
The expected behavior is (inputs are shown in-line)
--------------------------------------------------
Deck: [3, 2]
Discard pile: [7]
Your current rack is: [9, 5, 1]
Computer rack is: [4, 8, 6]
The top discard card is 7
Do you want it? (yes or no):
yes Enter the card in your rack to discard:
1 Your new rack is: [9, 5, 7]
Computer rack is: [4, 8, 1]
--------------------------------------------------
Deck: [3, 2]
Discard pile: [6]
Your current rack is: [9, 5, 7]
Computer rack is: [4, 8, 1]
The top discard card is 6
Do you want it? (yes or no): no
The card from the deck is 2
Do you want it? (yes or no): yes
Enter the number of the card you want to kick out: 9
Your new rack is: [2, 5, 7]
HUMAN WINS! with hand of [2, 5, 7]
Trending now
This is a popular solution!
Step by step
Solved in 3 steps