Operating Systems--Spring 2005

    Home | | Schedule | | Assignments | | Lecture Notes

    Project 1: Idiot's Delight

    First checkpoint due: Friday, Jan 28 (see below)
    Full Project Due date: Friday, Feb 4

    Introduction: With this project you will review your C++ programming skills and practice writing a UNIX script to run programs automatically and compute values. You will write two programs. The first plays a card game, Idiot's Delight, and outputs a value at the end of the game. The second program computes some statistics from a set of numbers stored in a file. Once the programs are written and work correctly, you will write a UNIX script to compile and run the programs to compute statistics for playing Idiot's Delight multiple times.

    Step One: Idiot's Delight

    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.

    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.

    Helpful Hints:
    1) I have provided two classes that you may use in writing your program: The Card class and the Deck class. These are specified and implemented in the card.cc and card.h files that can be found in the directory:
      ~csci346/projects/project1
    These classes allow you to work with a Deck object and Card objects. Member functions of the two classes allow you to shuffle the deck, deal a card from the top of the deck, write out the value and suit of a card, get the suit or value of a card, etc. You can find out all the member functions by looking at the declaration of the classes in card.h. The implementation file, card.cc, lists all the pre and post conditions for each member function.

    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:

    • Name the source file for your program idiots_delight.cc
    • Turn in a working version of this program by Friday, January 28 (checkpoint 1)
      • Submit this for the checkpoint by using the submit program:
        ~csci346/bin/submit csci346 project1check
      • Turn in a hard copy of your program in class.

     

    Step Two: Statistics Collection

    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.

     

    Step Three: Shell Script

    Write a shell script that will do the following:
    Compile your Idiot's Delight program
    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 games
    The name of your script file should be: proj1_script.

    Your 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).

     

    Miscellaneous Notes

    • To receive a high grade on this programming assignment, your programs must be correct, efficient and have good design and style. Thus, be smart about the structure of your programs and be sure to test your programs thoroughly before submitting them.
    • All of your submitted files must have program prologues that include
      • Your name
      • The date
      • The project number
      • The program (or script) name
      • The purpose of the program or script

    Turning in your project:

    Checkpoint 1:
    • You are required to submit the part one of the project (idiots_delight.cc) on Friday, January 28.
      • Submit the soft copy of your idiots_delight.cc file by typing:
        ~csci346/bin/submit csci346 project1check
      • Turn in a printout of your idiots_delight.cc file in class.
    • Turning in a working program by this date is worth 10% of your grade.
    • If you do not turn in your idiots_delight.cc by January 28, then you will only be able to earn 90% of the total points on your complete project.

    Completed project:

    • Turn in your completed project (idiots_delight.cc, stats.cc and proj1_script) by Friday, February 4.
      • Submit the soft copies of these files by typing: ~csci346/bin/submit csci346 project1
      • Turn in a printout of each of the files in class.


    Home | | Schedule | | Assignments | | Lecture Notes


    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