CSCI 132 Data Structures--Spring 2014

    Assignment 1

    Due at the beginning of class, Friday, February 7

    Home | | Syllabus | | Assignments | | Lecture Notes


    Programming Style: You will be graded not only on whether your programs work correctly, but also on programming style, such as the use of informative names, good comments, easily readable formatting, and a good balance between compactness and clarity.


    Let's Play Dice Poker!

    In this problem, you will complete the implementation of a program that simulates a dice game played between two players, player 1 and player 2. The game is a variation of the card game, Poker. The game consists of multiple rounds. In each round, the players each roll five dice. The combination of five dice values is ranked on a scale from 0 to 6 as follows:

    rank 6: Five of a Kind: all five dice have the same value
    rank 5: Four of a Kind: four of the five dice have the same value
    rank 4: Full House: the dice include three of one value and two of another
    rank 3: Three of a Kind: three dice have the same value and the remaining two have different values
    rank 2: Two Pairs: the dice include two pairs of the same values, and a fifth die of a different value
    rank 1: One Pair: two dice have the same value, and the remaining three have different values
    rank 0: Nothing: all five dice have different values

    The player with the highest ranking roll of the dice wins the round. The player who wins the most rounds is the winner of the game.

    In the ~csci132/assignments/assign1 folder is the skeleton of a program that simulates the playing of this dice game, with a few parts of the code filled in. There are 3 files, playDice.cc, player.h and player.cc. You should create a new directory in your home directory called "assignments", which you should protect by typing:

      chmod 700 assignments

    Copy the files from the csci132 directory into your own by typing:

      cp -r ~csci132/assignments/assign1 assignments/.

    You should be able to compile the code, but it does not do very much yet. The emacs compile command should look like:

      g++ -g -Wall player.cc playDice.cc -o playDice

    The code for the client program, playDice.cc is provided for you, as has the player.h file. Your job is to implement the player class so that the playDice program works correctly. Note that the player object has 3 private data members:

    • int diceArray[numDice];
      This keeps track of the result of tossing the dice in the most recent throw.
    • int rank;
      This keeps track of the score for the array of dice given in diceArray.
    • int points;
      This keeps track of the number of rounds won by this player.

    The player object has 8 public member functions and 1 private member function.

    • Player( );
      Initialize all data members to zero (including array elements);
    • void clearRank(void);
      Set rank of player to zero.
    • void clearPoints(void);
      Set number of points of current player to zero.
    • void throwDice(void);
      Generates a random number between 1 and 6 for each of the elements in diceArray.
      Prints out the value of each die after the roll.
      Also computes and sets the rank of the throw (using computeRank()).
    • void showRank(void);
      Prints out the rank and the meaning (e.g. "Full House, 4 points.") for current player.
    • int getRank(void);
      Returns the rank of the current diceArray.
    • int getPoints(void);
      Returns the number of points for the current player.
    • void addPoint(void);
      Adds one point to number of points for the current player.
    • void computeRank(void);
      Computes and sets the rank of the diceArray.

    The throwDice implementation should make use of the randomize function that has been provided for you:

    • int Randomize(int range);
      Return a random number between 1 and range (inclusive).
      You will probably want range to be 6 for your dice throws.


    Sample Output

    The following is the sample output for 1 game with 2 rounds of dice throwing:

    Would you like to play a game (y/n)?
    y
    How many rounds (less than 10) would you like to play?
    2
    
    Round #1:
    Player 1 throws: 
    Die #1 is a 6
    Die #2 is a 3
    Die #3 is a 5
    Die #4 is a 5
    Die #5 is a 6
    Two Pairs, 2 points.
    
    Player 2 throws: 
    Die #1 is a 2
    Die #2 is a 3
    Die #3 is a 5
    Die #4 is a 2
    Die #5 is a 4
    One Pair, 1 point.
    
    Player 1 wins this round!
    
    
    Round #2:
    Player 1 throws: 
    Die #1 is a 3
    Die #2 is a 4
    Die #3 is a 3
    Die #4 is a 4
    Die #5 is a 6
    Two Pairs, 2 points.
    
    Player 2 throws: 
    Die #1 is a 6
    Die #2 is a 4
    Die #3 is a 5
    Die #4 is a 1
    Die #5 is a 4
    One Pair, 1 point.
    
    Player 1 wins this round!
    
    Player 1 wins the game!
    Would you like to play again (y/n)?
    n
    Thank you for playing Dice Poker!
    


    What to turn in:

    • Turn in a hard copy of the file, player.cc.
      Make sure you include a file prologue with your name, class, lecture section, the date, and the assignment number, along with a description of the file contents and their purpose. Also include appropriate comments for each of the functions you implement (with proper pre and post conditions).
    • Turn in a printout of a sample run of your program with 1 game with 3 rounds.
    • Turn in a written discussion log, indicating whom you worked with, the dates and what you discussed.
    • Submit the soft copy of your program using the command:
      ~csci132/bin/submit csci132 assign1

    Home | | Syllabus | | Assignments | | Lecture Notes


    Constance Royden--croyden@mathcs.holycross.edu
    Computer Science 132--Data Structures
    Last Modified: January 28, 2014
    Page Expires: January 14, 2015