Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROBLEM 2: Take Two [20 points] using Java Now that youve become proficient at playing the game, we will start adding in extra rules. For

PROBLEM 2: Take Two [20 points]

using Java Now that youve become proficient at playing the game, we will start adding in extra rules. For this one, if a player plays any two card (R2, Y2, G2 or B2), the next players turn is skipped and they must take two cards. You will apply the Rule of Two below: Rule of Two If the card last laid in the discard pile was numbered 2, the next player must choose between the following options: If they have another two card (R2, Y2, G2 or B2) in their hand, they will choose to play the one. o If they have more than one colour, they will pick in rainbow order: redyellow-green-blue. If they do not have a two card, on their turn they are skipped and must draw two cards from the top of the draw pile. Input Same as in Problem 1. Processing Same as in Problem 1 with the following exception: If a player lays down a card numbered 2, the next player must apply the Rule of Two as described above. Output format Same as in Problem 1 with the following exception: If a player lays down a card numbered 2 and the following player is unable to play another two card, output: {N}: TAKE TWO Where N = 1,2, or 3, the skipped player that had to draw two cards.

image text in transcribed

I have already done problem one from there and the code for the program would be :

Hand of player one (initially 5 cards) Hand of player two (initially 5 cards) Hand of player three (initially 5 cards) First card in the discard pile on which to you play on (1 card) Remaining cards in the draw pile (top to bottom, all remaining cards) Processing 1. Output the starting card on the discard pile. 2. Starting with player one, decide which card they will play (or pick up from the draw pile) and output their choice (or DRAW if they have no match and must try to pick up a card from the draw pile). 3. Repeat this for each player until a player has no more cards in their hand. This player becomes the winner of the game. Output format 0: {First/starting card on the discard pile} 1: {Card played by player 1*} 2: {Card played by player 2*} 3: {Card played by player 3*} 1: {Card played by player 1*} 2: {Card played by player 2*} 3: {Card played by player 3*} : : : {N}: {Last card played by player N} (WINNER) Where N = 1,2, or 3, the player first able to play all of their cards and empty their hand * If no card is able to be played by a player, output DRAW on their turn and pick up a card from the draw pile (if one exists). image text in transcribed

Sample input Sample output New hand after play R1 R4 Y6 G8 B2 R2 R8 Y7 Y8 B3 R3 R6 Y3 G4 G5 B6 0: B6 1: B2 2: R2 3: TAKE TWO 1: R1 2: R8 Y2 B7 Y1 G6 Y5 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 Y3 G4 G5 1: 62

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

Students also viewed these Databases questions