Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

//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

#include

#include

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;
}
}

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91610640
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in C/C++

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As