Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Course: Data structure and algorithm In the following games, to manage the dynamics of cards in piles, we need to use different data structures. Please

Course: Data structure and algorithm

In the following games, to manage the dynamics of cards in piles, we need to use different data structures. Please read the card game description and work on the questions as below. The most important question is which data structure(s) would be used in each game:

Card Game 1. Idiot's Delight

Players :1

Object: To clear all the cards in your hand.

Setup: Shuffle a deck of cards. Hold the deck of cards in your hand and deal four cards face up in a row, forming four stacks (also called four piles).

Play: On your turn, you keep doing any one of the following operations, till all the cards are cleared in your hand:

- If there are two cards of the same rank showing, discard both of them.

- If there are two cards of the same suit showing, discard the one with lower rank.

- Deal four new cards, one on top of each stack (also called pile).

Card Game 2. War

Players: 2

Object: To force the other player to run out of cards.

Setup: Deal out the entire deck, 26 cards to each player. Each player's cards are kept in a face-down pile.

Play: In each round, each player turns up the top card on his pile. The player with the higher-ranking card takes both cards and adds them to the bottom of his pile. A tie is resolved by a "war": each player plays three cards from his pile face-down and another face-up. The high card among these last two wins all ten cards. Subsequent ties are handled similarly, with the eventual winner of the round taking an even larger pile of cards.

Game End: If a player is unable to play a card (even during a war), he loses.

In order to help understand the lab and find the answer, please consider the following questions for each game:

1. How many different types of objects?

2. Which class(es) do you want to define? What could be the attributes and operations in each class?

3. Do we need to separate the Card class from the Card Deck class?

4. How would you like to represent, store, and manage the Card deck?

5. As for those dynamic card piles, what is the common operations? Should card piles use a data structure same as the Card Deck?

6. What could be the data structure of card piles?

Please use your sketchbook and write down your answer (or draw your answer). Take a snapshot of your sketchbook and submit it.

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 Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

6. How do you expect to use active listening during the meeting?

Answered: 1 week ago

Question

LO2 Distinguish among three types of performance information.

Answered: 1 week ago