CSE 332 Lab 3: Five Card Draw

Due by Sunday April 5 at 11:59 pm
Final grade percentage: 12 percent


This lab is intended to extend your use of C++ language features from the previous labs, and to make more extensive use of C++11 and STL features. To do this, you will extend your C++ programs from the previous labs to (1) maintain and display the status of a multi-player game of 5 card draw poker; (2) parse command-line arguments to identify the initial players in the game; (3) within each round of play allow players to discard cards from and add cards to their hands, and print out a ranking of the resulting hands; and (4) between rounds allow current players to leave the game and new players to enter the game, saving information for players who leave in files so that if they re-join the game later the files can be used to restore their statistics from previous rounds of play.

Both for this lab and for the next one, your are allowed (and encouraged) to work in teams of 2 or 3 people (but not more), though you also are allowed to complete the lab assignment individually if you prefer. If you do work in a team, you are allowed to use any of your team members' code from the previous lab assignments in this course this semester, in your solution for this lab.

In this lab and in the subsequent labs, you are encouraged to re-use and modify code from your previous lab solutions - if you choose do this, please put a completely new copy of any header and source files from your previous lab(s) in the new lab project directory you create. This can avoid some potential for error or confusion within Visual Studio, and also ensures you have a backup copy that you could go back to if a modification you try doesn't pan out.

In the next (final) lab assignment for this course you will build on these features to allow a user to choose among different card games to play.


    Part I - Readings:

  1. The following readings in the course text book may be useful as reference material while working on this lab assignment.

  2. Please read the following CSE 332 Programming Guidelines which relevant to the previous labs and please follow them as you implement your solution: A.1-A.17, B.1, B.2, B.10-B.13, B.15-B.18, B.20-B.25, B.28, B.29, B.31-B.33, and C.1-C.8.

    Please also review and follow these additional guidelines that may be relevant to this lab: B.3-B.8, B.19, B.26, B.27, and B.34 (pointers, smart pointers, and dynamic memory allocation); B.9 (virtual destructor); and B.14 (static variables).

    Part II - Program Design and Implementation:

    Note: the details of this assignment are again intentionally somewhat under-specified, leaving you some room to choose what you think is the best way to implement them, as long as what you do is reasonable and you explain your design decisions in comments in the code and in your ReadMe.txt file.

    Please also note that in this lab assignment and the next one, you are strongly encouraged to use smart pointers (especially shared_ptrs) and their corresponding dynamic allocation functions (e.g., make_shared), instead of using native C++ pointers with the new and delete operators: this more modern style of dynamic memory management can save you significant problems (and with them deductions when we grade your lab solution) due to memory leaks, double deletion, and other issues.

  3. Open up Visual Studio, and create a new Win32 Console Application Visual C++ project for lab 3. Copy the files from your lab 2 implementation over to this project as you will be extending them in this lab assignment (though you will replace your main function from lab 2 with the one specified below for this lab).
  4. Extend the Deck class from your previous lab implementation with:
  5. Extend the Hand class from your previous lab implementation with:
  6. Create a new header and source file for a Player struct, and in them declare and define (respectively) the following elements of that struct:

    Please also declare and define a non-member insertion operator (operator<<) that takes a reference to an ostream and a reference to a const Player. That operator should use the ostream to print out the player's name, number of wins, and number of losses with spaces between them and then return a reference to the ostream.

  7. Create a new header and source file for a Game abstract base class, and in them declare and define (respectively) the following elements of that class:

  8. Create a new header and source file for a FiveCardDraw class that is derived through public inheritance from the Game abstract base class, and in them declare and define (respectively) the following elements of that class:
  9. In your project's main function:

  10. Build your project, and fix any errors or warnings that occur. Please be sure to note all of the different kinds of errors or warnings you ran into (though you don't have to list every instance of each kind) in your ReadMe.txt file. If you were fortunate enough not to run into any errors or warnings, please note that instead, where you would have listed errors or warnings in your ReadMe.txt file.

  11. Open up a Windows console (terminal) window and change to the directory where your program's executable file was created by Visual Studio.

  12. Run the executable program through a series of trials that test it with good coverage of cases involving both well formed and badly formed inputs. In your ReadMe.txt file please document which cases you ran (i.e., what the command lines were) and summarize what your program did and whether that is correct behavior, in each case.

  13. In your ReadMe.txt file, make sure that your name and the lab number (lab 3) are at the top of the file, and that you've documented whether you ran into any errors or warnings while developing your solution (and if so what they were) and what the executable program did for each of the trials you ran. Be sure to save your changes to your ReadMe.txt file, as well as those to your source (and header) file(s) before preparing your solution zip file.

  14. Prepare a zip file that contains your project's source, header, and ReadMe.txt files (except for executable files, or stdafx.h, stdafx.cpp or other Windows-generated files you did not modify), by:

    Send the zip file containing your lab 3 solution as an e-mail attachment to the course e-mail account (cse332@seas.wustl.edu) by the submission deadline for this assignment. If you need to make changes to your lab solution you are welcome to send a new zip file, and we will grade the latest one received prior to the deadline (according to the receipt time stamp the server puts on the e-mail).

    Part III - Automated players: (optional, worth up to 5% extra credit)

    The goal of this optional part of the assignment is to have the program to play automatically for some of the players, instead of consulting the user for how to play their hands:

  15. Allow an asterisk (a * character) to be appended as the last character of any input string that represents a player's name (either one that starts in the game or joins the game later after a round), and have the program play for such players automatically. This means that wherever the program would have obtained user input, it should instead compute and then use an input on its own. For example, "Doyle" would be a user-played player, while the program should play automatically for "Doyle*". To make this easier to implement you could reasonably restrict names to have only alphabetic characters other than the optional terminal asterisk, though it's up to you whether or not to impose such restrictions (please document any restrictions you do impose in your readme file and in comments in your code).

  16. The Player class constructor and destructor should treat the characters up to but not including the terminal asterisk character of any automatic player's name, as the name of the file to try to open for input or output respectively. This allows automatic and/or user-driven versions of the same player to be used sequentially.

  17. After the initial hand of a round is dealt to a player, the game should discard (and then deal replacement cards from the deck) for each automatic player, as follows:

  18. After each round, choose whether each automatic player will stay in the game or quit, as follows:

    The program should compute an unsigned integer randomly distributed between 0 and 100: if the unsigned integer is less than or equal to the player's probability of remaining in the game the player should stay, and otherwise the player should quit the game.

  19. In your readme file, please add a section clearly marked "Extra Credit" and in it explain how you implemented those features, and also cut and paste output from your game with it showing examples of it making different choices for players discarding cards, remaining in the game, and leaving the game.

Posted 4:00pm Tuesday March 10 2015 by
Chris Gill