Home | | Schedule | | Assignments | | Lecture Notes
First checkpoint due: Friday, Jan 28 (see below)
Full Project Due date: Friday, Feb 4
Write a C++ program to play the solitaire card game known as Idiot's Delight. The game is played as follows: The cards in a 52-card deck are shuffled and then placed face down on a table. The player draws four cards, and then compares the first and fourth card in his/her hard. If the first and fourth card are of the same suit, the second and third card are discarded. If the first and fourth card are of the same value (e.g., both are kings), then all four cards are discarded. If the first and fourth card are neither the same suit nor the same value, then no cards are discarded. The player then draws a new card. Using the new card as "the fourth card", repeat above. (If the player has more than 4 cards in his or her hand then the comparison is made between the last card ("the fourth card") and the card positioned 3 spaces before it (the new "first card").NOTES:
- In some instances, multiple cards must be drawn to ensure the player has at least four cards in his/her hand.
- After cards are discarded, the player should check if more cards should be discarded. In other words, use the last drawn card in the player's hand as "the fourth card".
The game ends when the cards in the deck have all been drawn. The game is considered a victory if the player has no cards remaining in his/her hand.
Your program must initialize a 52-card deck, shuffle the cards, and then play Idiot's Delight. Your program should output to stdout (the monitor) the value and suit of the cards as they are drawn, list the cards currently in the player's hand and write out whether the last four cards, the middle 2 cards or no cards are discarded. 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 number of cards that are not discarded (i.e., the number of cards remaining in the player's hand). 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 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 Idiot's Delight programThe name of your script file should be: proj1_script.
Compile your Statistics program
Play 5 games of Idiot's Delight
Compute the mean and standard deviation for the 5 games
Play 100 games of Idiot's Delight
Compute the mean and standard deviation for the 100 games
Play 1000 games of Idiot's Delight
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 idiots_delight 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 7, 2005
Page Expires: January 8, 2006