Question: First to Four-of-a-Kind Card Game vs Computer Player (Java Programming) Your task is to write a java program that plays a simple card game with

First to Four-of-a-Kind Card Game vs Computer Player (Java Programming)

Your task is to write a java program that plays a simple card game with one human player and one computer player. The game uses a deck of 52 cards with the usual values and suits.

The objective of the game is to get four cards with the same value, a four-of-a-kind. For example, the 10 of hearts, diamonds, clubs and spades.

At the beginning of the game, the cards are shuffled and each player is given four cards.

The remaining cards are placed into a queue called the draw pile. There is another pile called the discard pile that starts out empty. The discard pile is a stack (an ArrayDeque in Java).

If neither player has been dealt a winning hand, the players take turns until one of them wins. At each turn the player can either draw a new card from the draw pile or pick up the top card on the discard pile.

In this game the human player always goes first. Because the discard pile starts out empty, the human player must initially pick up a card from the draw pile. After that, the human player must select a card to put into the discard pile. The computer will select from the draw pile or the discard pile and this will go vice-versa until there is a four-of-a-kind.

If the draw pile becomes empty before the game ends, then the discard pile will be shuffled back in.

The first player to get a four-of-a-kind wins. At that point, the game should display the message You win! if the human player won or I win! if the computer player won. The program should then terminate.

The Absolute Necessities of the Program Include:

The program creates the deck of cards, shuffles it, and gives each player four cards.

The human player is notified what card is on top of the discard pile (which is implemented as a stack), and he can either take that card or draw a card from the draw pile (which is implemented as a queue).

The human player can discard either a card that was already in his hand or the card he just acquired during his turn. This card is then placed on top of the discard pile.

The computer player is capable of both taking a card from the draw pile or picking up the card on top of the discard pile, and it does not do the same thing every time. It may choose which to do either randomly or according to some strategy, whichever you prefer.

The computer player does not always discard the same card every time. It may choose which card to discard randomly or according to some strategy, whichever you prefer.

If the draw pile becomes empty before either player has won the game, all of the cards in the discard pile are shuffled and moved back to the draw pile.

The program correctly recognizes when someone wins and displays the appropriate message.

An example execution of this game is shown in the program output below:

Your cards are:

Queen of Hearts

Seven of Hearts

Eight of Hearts

Seven of Diamonds

-----------------------------------

The discard pile is currently empty -- you must draw a card

You drew the Five of Spades

----------------------------------------

Now your cards are:

1. Queen of Hearts

2. Seven of Hearts

3. Eight of Hearts

4. Seven of Diamonds

5. Five of Spades

---------------------------------

Which one do you want to discard?

1

-------------------------------------

Computer will draw a new card.

Computer will discard the Two of Spades

--------------------------------------

Your cards are:

Five of Spades

Seven of Hearts

Eight of Hearts

Seven of Diamonds

--------------------------------

The top card in the discard pile is the Two of Spades

-------------------------------------

Do you want to pick up the Two of Spades (1) or draw a card (2)?

2

You drew the Queen of Diamonds

------------------------------------------------

Now your cards are:

1. Five of Spades

2. Seven of Hearts

3. Eight of Hearts

4. Seven of Diamonds

5. Queen of Diamonds

-----------------------------------

Which one do you want to discard?

1

--------------------------------------------

Etc, etc until the game is completed

Sorry for the length of the instructions, want to be thorough.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!