Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

First to Four-of-a-Kind Card Game vs Computer Player (Java Programming) Instructions: Write a java program that plays a simple card game with one human player

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

Instructions:

Write a java program that plays a simple card game with one human player and one computer player. The way to win this game is to be the first to get a Four-of-a-Kind. The game uses a deck of 52 cards with the usual card values and suits as a normal deck of cards.

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).

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. If the draw pile runs empty before a winner is declared, then the discard pile is shuffled back into the draw pile.

This process repeats until one player 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.

Rubric:

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.

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

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions

Question

What is an experiment?

Answered: 1 week ago