Generate the initial deck of cards.

Assignment Help C/C++ Programming
Reference no: EM13939766

//Game specification is to write a program that plays a variant of the solitaire game known as Klondike. The goal is to construct four sequences of cards. The foundation piles, each sequence is formed by putting cards of the same suit into the same pile ascending order beginning with the ace. The setup of the game begins by shuffling a deck of cards .Seven piles of cards are dealt out to form the tableau, The first pile has one card. The second has 2 etc. The top card on each pile is turned up. The others remain hidden. A card can be added to the foundation pile pile if its value is one greater than that of the topmost visible card and the color is opposite. All of the cards of the pile can be moved to another pile if the bottommost visible card can legally be added to the pile. When all of the visible cards are moved,the top hidden card is turned over. If there are no more hidden cards the empty spot can be occupied by the visible cards from the other pile. A card can be added to the foundation pile if its value is one greater than the topmost card and the suite is the same. The first card in the pile must be an ace of that suit. Cards can be moved to a fondation pile.

//Cards can be moved to a foundation pile from either the top visible card in the tableau pile or the waste pile. In the beginning of play the waste pile is empty .After adjustments are made to the initial tableau a card is taken form the remainder of the deck and placed as the first card in the waste pile. This card can be moved to either a foundation pile or a tableau pile if it fits. If it doesn't fit it remains in  the waste pile. Another card from the remaining deck is drawn and placed on the waste pile. if a drawn card can be placed on a pile this may open up the possibility of moving cards around in the tableau.

//It may also enable the top card in the waste pile to be placed The adjustments are made until nothing can be moved. Play continues until all of the original cards in the deck are in play and all adjustments are made. It is then permitted to move all of the cards in the waste pile back into the deck .Another round of play resumes until the deck is emptied.

//The program should have the capability to play the game. A combination of structures stacke and queues to represent the various groups of cards. You can represent a card using a structure with one component that is an integer value to hold a the face value and another that in an enumerated value to hold the suit. You can use a queue to represent the main deck of cards you will be taking cards from the top and occasionally putting others back on the bottom. A foundation pile can be most easily represented by a queue since it is required that the contents be displayed. The hidden portion of the
//tableau should be represented by a stack to facilitate adding and removing from the top of the pile.The waste pile is also best represented with a stack.

A suggested order of development is as follows
//*Generate the initial deck of cards. Store 52 cards in an array. Then randomly select cards from the set and insert them into a queue for the starting hand of the cards.* Initialize the foundation piles and the waste pile to be empty deal out the cards to the seven tableau stacks then take the top cared and place it in the corresponding visible queue.
//*Develop a printing routine to display the contents of the foundation piles and the visible parts of the tableau pile and the waste pile. A textual printout is all that is needed (graphical output is not necessary.
// *Develop the strategy to move around cards as the result of taking one card from the remaining deck on the top of the waste pile. Examine first whether this card can be placed on the foundation pile. If not can it br played onto one of the tableau piles? Next determine if the visible cards on the tableau piles can be moved to another to free up a hidden cards. If this happens the new card should be examined for moving to another pile. If no visible cards can be moved to another tableau pile then determine if the topmost visible cards can be moved to a foundation pile.
//* all of the stepts above should be repeated in a loop until there is no further card movement possible.
// organize the play for an entire round. Continue to take cards out of the remaining deck hand and deal them until the entire hand is used. check the contents of four foundation piles and determine if the game is over.* if the game is not over move the cards from the waste pile to the deck .
//continue playing until either the game is won or an entire round goes by without any movement of the cards on the table.

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

typedef struct{ //typedef selected to eliminate the need for structure tag
char *face;
char *suit;
}Card;

void populate_deck(Card *, char *[], char *[]);
void print_deck(Card*);
void shuffle (Card *);

main()

{

Card deck [52]; //declares an array of 52 cards

char*face[] = {"Ace","2","3","4","5","6","7","8","9","10",
"Jack","Queen","King"};
char *suit[] = {"Hearts","Diamonds","Clubs", "Spades"};

srand(time(NULL));
populate_deck(deck,face,suit);
print_deck(deck);
puts("\t Shuffled Deck\n");
shuffle (deck);
print_deck(deck);

}

void populate_deck(Card * wDeck, char *wFace[], char *wSuit[])
{
int i;
for(i=0; i<52; i++)
{
wDeck[i].face = wFace[i%13];
wDeck[i].suit = wSuit[i/13];
}
}

void print_deck(Card*wDeck)
{
int i;
for (i = 0; i<52;i++)
printf("%5s of %-8s%c",wDeck[i].face, wDeck[i].suit,
(i+1) % 2 ?'\t':'\n');
printf("\n");
}

void shuffle(Card *wDeck)
{
int i,j;
Card temp;
for (i = 0;i<52;i++)
{
j = rand() %52;
temp = wDeck[i];
wDeck[i]=wDeck[j];
wDeck[j] = temp;
}
}

Reference no: EM13939766

Questions Cloud

How civilization emerged in mesopotamia : How civilization emerged in Mesopotamia, Ancient Egypt and the Hittite empire? What are the characteristics of these civilizations that we have inherited
Appraise emile durkheim contention : Outline and critically appraise Emile Durkheim's contention that education establishes and maintains social consensus and solidarity through its socializing function.
Describe white blood cells migrating toward bacteria : When human immunodeficiency virus (HIV) attaches to a host cell what genetic material is released into the cell's cytoplasm?
About the investment opportunity : Assume NEWC has an investment opportunity (similar to the air bag opportunity in Other People's Money).The firm can spend $325 million on refurbishing its wire and cable plant to develop a product that will be sold in packets or units of twenty. Assu..
Generate the initial deck of cards. : It may also enable the top card in the waste pile to be placed The adjustments are made until nothing can be moved. Play continues until all of the original cards in the deck are in play and all adjustments are made
Discuss the difference between budgets and standard costs : Discuss the difference between budgets and standard costs. Describe the relationship that unit standards have with flexible budgeting. Why is historical experience often a poor basis for establishing standards?
What the president said about business and the economy : The paper should focus on what the president said about business and the economy
Number description assets liabilities equity income activity : Transaction Total Net Operating Financing InvestingNumber Description Assets Liabilities Equity Income Activity .
Teledex company manufactures products to customers : Teledex Company manufactures products to customers' specifications and operates a job- order costing system. Manufacturing overhead cost is applied to jobs on the basis of direct labor cost. The following estimates were made at the beginning of th..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  What are the values of queuefront and queuerear

What are the value of queueFront and queueRear after removing an element from the queue? Also what was the position of the removal queue element?

  Write a recursive and iterative versions of binary search

In C++ write a recursive and iterative versions of binary search and compare their run times using the array a[i]=i, i=0,..., n-1 and the given test method:

  Use the convention that all years have 360 days

In writing the days() function, use the convention that all years have 360 days and each month consists of 30 days. The function should return the number of days for any Date structure passed to it. Write a main () function to test your function.

  Develop a global function customerinformation

Use a parameterized constructor to initialize data members - Develop a global function "CustomerInformation" that prints the customers information (number of dept each customer can handel). ( Use copy constructor).

  Compute the squares of the numbers in the array

Write a java program to find the number in the given list. Write a java program to find the location of an element in the list.

  Which of the following assignments are valid

Which of the following assignments are valid? If an assignment is not valid, state the reason.When not given, assume that each variable is declared.

  The factorial of a positive integer n, denoted by n!

Write a program that computes the sequence of factorial values: 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120, 6! = 720, ....

  Write an automated checkout program to expedite customers

A local department store hires you  to write an automated checkout program to expedite customers in a hurry. The  checkout line can only accept five items for any one purchase

  How many generations do you want to wait

How many generations do you want to wait? How many jackalopes do you have?

  Compute the volume of write-back traffic in bytes

Compute the volume of write-back traffic in bytes. Provide a plot of the miss rate vs. the line size for line sizes of 32 bytes to 2 Kbytes. Note that line sizes are a power of 2.

  Draw a two-dimensional house seen from the front

Draw a two-dimensional house seen from the front, the way a child would: with a door, two windows, and a roof with a chimney. Feel free to add details; mabe have "smoke" come out of the chimney.

  Create a base employee class and a derived studentemployee

create a base employee class and a derived studentemployee class. below is the basic uml structure of both

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd