Operating Systems--Spring 2011

    Home | | Schedule | | Assignments | | Lecture Notes

    Project 1: Clock Solitaire

    First checkpoint due: Thursday, Feb 3 (see below)
    Full Project Due date: Thursday, Feb 10

    Introduction: With this project you will review your C++ programming skills and practice writing a LINUX script to run programs automatically and compute values. You will write two programs. The first plays a card game, Clock Solitaire, 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 LINUX script to compile and run the programs to compute statistics for playing Clock Solitaire multiple times.

    Step One: Clock Solitaire

    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.

    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.

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

    • Name the source file for your program clock_solitaire.cc
    • Turn in a working version of this program by Thursday, February 3 (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 Clock Solitaire program
    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 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 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).

     

    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 (clock_solitaire.cc) on Thursday, February 3.
      • Submit the soft copy of your clock_solitaire.cc file by typing:
        ~csci346/bin/submit csci346 project1check
      • Turn in a printout of your clock_solitaire.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 clock_solitaire.cc by Febrary 3, then you will only be able to earn 90% of the total points on your complete project.

    Completed project:

    • Turn in your completed project (clock_solitaire.cc, stats.cc and proj1_script) by Thursday, February 10.
      • 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 26, 2011
    Page Expires: January 8, 2012