Home | | Schedule | | Assignments | | Lecture Notes
First checkpoint due: Thursday, Feb 3 (see below)
Full Project Due date: Thursday, Feb 10
Write a C++ program to play the solitaire card game known as Clock Solitaire. The game is played as follows: The cards in a 52-card deck are shuffled and then dealt out into 13 piles. (When playing with actual cards, 12 piles are arranged in a circle, as on the numbers on a clock, and the 13th pile is in the center. See this description of Clock Solitaire on Wikipedia). According to the Wikipedia description, play proceeds as follows:The twelve positions around the circle represent the 12 hour clock and the pile in the middle represent the hands.
Play starts by turning over the top card of the central pile. When a card is revealed, it is placed face up under the pile at the corresponding hour (i.e. Ace = 1 o'clock, 2 = 2 o'clock, etc. The Jack is 11 o'clock and the Queen is 12 o'clock) and the top card of the pile of that hour is turned over. If a King is revealed, it is placed face up under the central pile.
Play continues in this fashion and the game is won if all the cards are revealed. The game is lost if all four Kings are revealed and face-down cards are still present.
Your program must initialize a 52-card deck, shuffle the cards, and then play Clock Solitaire. Your program should output to stdout (the monitor) the value and suit of the cards in each of the 13 piles after they have been initially dealt (4 cards per pile). It should then output the value and suit of each card as it is picked up from the top of a pile, and note which pile the card is being placed in. When a card is placed face-up in a pile, the program should list (to the monitor) the value and suit of all the face-up cards currently in that pile. (Note--they should all have the same value, i.e. all the face-up cards in the 10th pile have the value of 10, and in the 11th pile should be Jacks). This should continue until there are 4 Kings in pile number 13, which ends the game. Your program should then output to the monitor how many face-down cards are remaining in each pile and how many total face-down cards are remaining. If zero cards are still face down, your program should output to the monitor: "You won!" Your output to stdout should be clear enough that anyone (including your instructor) can determine that the game is being played correctly.Helpful Hints:Finally, at the end of the card game, your program should output one number to a file; this number should be the total number of face-down cards remaining. If the game is a victory, the program should output zero.
2) In order for your program to give a different random shuffle with each execution of the program, you must provide a different "seed" variable each time the program is run. One way to do this is to get the current computer clock value in milliseconds. You can do this with the following code:
#include <sys/timeb.h> ... int seed; struct timeb tstruct; ftime( &tstruct ); seed = time(NULL) + tstruct.millitm; srand((unsigned)seed);You should assign the seed a value before you shuffle the deck.
Important details:
Make sure to do the following:
Write a C++ program, stats.cc, that reads in a set of integers from a file and prints out (to stdout) the mean and standard deviation of the integer set. The standard deviation is computed as follows:![]()
Your program should take the name of the input file as an argument to the program call, e.g. you might call the program with:stats myInputFile
which will cause the input to be read from the file named myInputFile.
Write a shell script that will do the following:Compile your Clock Solitaire programThe name of your script file should be: proj1_script.
Compile your Statistics program
Play 5 games of Clock Solitaire
Compute the mean and standard deviation for the 5 games
Play 100 games of Clock Solitaire
Compute the mean and standard deviation for the 100 games
Play 1000 games of Clock Solitaire
Compute the mean and standard deviation for the 1000 gamesYour script should not print out to the monitor all the steps of playing each card game. One way to avoid this unwanted output is to redirect the stdout of the card game program to a file.
Since each run of your clock_solitaire program will output to a file the number of cards left in your hand at the end of the game, you will want to concatenate these files together so that all the results will be in a single file that can be read by the stats program.
Your script should print to the monitor the computed mean and standard deviation for each of the above sets of games. It should also print an informative statement saying what values it is printing (i.e. it should not simply output three sets of numbers).
Completed project:
Constance Royden--croyden@mathcs.holycross.edu
Computer Science 346--Operating Systems
Date Created: January 9, 2004
Last Modified: January 26, 2011
Page Expires: January 8, 2012