Design and implement a C++ object to play a simple dice game of Twenty-Six1 which is a single player betting game using ten (10) dice.
CS 202 – Assignment #2 Purpose: Learn C++ basic class implementation. Points: 100 Assignment: Design and implement a C++ object to play a simple dice game of Twenty-Six1 which is a single player betting game using ten (10) dice. This game was popular in the mid-west USA in the early 1900's. We will create an object to simulate the dice game of Twenty-Six and use a main program to try various “winning” strategies. Game Play: Before the game begins, a “bank” amount must be obtained. The bank is the initial amount available for the player. As the game plays, the each round uses 1 from the bank. Based on the roll, the player may win nothing or up to 10. If the bank amount is depleted (down to 0), the player loses. The player may stop at any time, this receiving the current bank amount. To play the game, the player rolls a single dice (1 to 6) which is used as the “point” number. The player throws the ten (10) dice thirteen (13) times. The score is the number of times that the point number is thrown. A random number between 1 and 6 is used for each dice roll (via the C++ rand() function). Note, do not seed the random number generator. Warning: Apparently, you should not play this game in Chicago. 1 For more information, refer to: http://www.dice-play.com/Games/TwentySix.htm Point Count Payout 10 or less 10 13 5 26 4 27 5 28 6 29 8 30 10 Other 0 Published: New York Times, November 25, 1913 Linking Instructions: A make file is provided. As projects get larger, compiling a series of source files by hand becomes tedious. Make is a utility that will read a make file (named makefile by default), compile applicable sources, and build the executable file. Assuming the main file is named main.cpp and the class implementation file is named twentySix.cpp, the following are the instructions to build the executable. ed-vm% make Which will create an executable named main. It is possible to change the file names if desired. However, the provided make file assumes these file names. As such, you should not change the file names for this assignment. Provided Main A main is provided. The provided main() function will serve as a driver for the program which uses the twentySix game object for testing. The provided main will use the twentySix object in a variety of different ways. This will include some interactive and non-interactive uses for testing. Additionally, a number of incorrect values are used for testing. As such, the output of the provided main may initially be confusing. You can comment out parts of the provided main if you want to focus on specific aspects of the project. The main will not need to be submitted with the project. As such, you can not make changes to the provided main as such changes will not be in the main used for scoring. Submission: • All files must compile and execute on Ubuntu and compile with C++11. • Submit source files ◦ Submit a copy of the program implementation source file via the on-line submission ◦ Submit a copy of the program header file via the on-line submission ◦ Note, do not submit the provided main (we have it). • Once you submit, the system will score the project and provide feedback. ◦ If you do not get full score, you can (and should) correct and resubmit. ◦ You can re-submit an unlimited number of times before the due date/time. • Late submissions will be accepted for a period of 24 hours after the due date/time for any given lab. Late submissions will be subject to a ~2% reduction in points per an hour late. If you submit 1 minute - 1 hour late -2%, 1-2 hours late -4%, … , 23-24 hours late -50%. This means after 24 hours late submissions will receive an automatic 0. Program Header Block All program and header files must include your name, section number, assignment, NSHE number, input and output summary. The required format is as follows: /* Name: MY_NAME, NSHE, CLASS-SECTION, ASSIGNMENT Description:
Input: Output: */ Failure to include your name in this format will result in a loss of up to 5%. Code Quality Checks A C++ linter2 is used to perform some basic checks on code quality. These checks include, but are not limited to, the following: • Unnecessary 'else' statements should not be used. • Identifier naming style should be either camelCase or snake_case (consistently chosen). • Named constants should be used in place of literals. • Correct indentation should be used. • Redundant return/continue statements should not be used. • Selection conditions should be in the simplest form possible. • Function prototypes should be free of top level const. Not all of these items will apply to every program. Failure to to address these guidelines will result in a loss of up to 5%. Scoring Rubric Scoring will include functionality, code quality, and documentation. Below is a summary of the scoring rubric for this assignment. Criteria Weight Summary Compilation - Failure to compile will result in a score of 0. Program Header 5% Must include header block in the required format (see above). General Comments 10% Must include an appropriate level of program documentation. Line Length 5% No lines should exceed more than eighty (80) characters. Code Quality 5% Must meet some basic code quality checks (see above) Program Functionality (and on-time) 75% Program must meet the functional requirements as outlined in the assignment. Must be submitted on time for full score. 2 For more information, refer to: https://en.wikipedia.org/wiki/Lint_(software) Twenty-Six Class Implement a twenty-six class named twentySix to provide simulate the dice game twenty-six (as described). The twentySix UML class diagram is as follows: twentySix -initialBank: int -currentBank: int -displayGame: bool -pointValue: int -currentScore: int -currentPayout: int -diceRolls[13][10]: int -MIN_BANK = 10: static constexpr int -MAX_BANK = 200: static constexpr int +twentySix(int=10) +readInitialBankAmount(): void +setInitialBankAmount(int): void +getInitialBankAmount() const: int +getBankAmount() const: int +setDisplayMode(bool): void +readDisplayMode(): void +playOn() const: bool +playRound(): void -yesOrNo(string) const: bool -showGame() const: void You will need to create a header file (twentySix.h) and develop an implementation file (twentySix.cpp) based on the above UML diagram (which is represented in the provided header file). Your implementation and header files should be fully commented. Refer to the example executions for output formatting. Function Descriptions: The following are more detailed descriptions of the required functions. • The twentySix() constructor should initialize the class variables. If an initial bank amount is passed, the range must be verified. If invalid, an error message should be displayed and the initial bank should be set to zero. The current bank should be initialized with the initial bank value. The other integers, including the dice array, should be set to 0. The display game boolean should be set to true. • The readInitialBankAmount() function should read the initial bank amount from the user and verify that it is between MIN_BANK and MAX_BANK (inclusive). The function display an error message and re-prompt for incorrect input (an unlimited number of times). You may assume valid data type entry (i.e., actual numeric data). The current bank should be initialized with the initial bank value. • The setInitialBankAmount(int) function should set the initial bank amount to the passed value after verifying that it is between MIN_BANK and MAX_BANK (inclusive). If the value is invalid, an error message should be displayed and nothing changed. If the value is valid, the initial bank value should be set and current bank should be updated. • The getInitialBankAmount() function should return the initial bank amount value. • The getBankAmount() function should return the current bank amount value. • The setDisplayMode(bool) function should set the class variable for display game to the passed value. • The readDisplayMode() function should ask the user if the game details should be displayed ("Display Game Details? (Y/y/N/n): “). The function should set the display game class variable to true for 'yes' (display), false for 'no' (no display). This function should use the private yesOrNo(string) function. • The playOn() function should ask the user to play another round ("Play Another Round? (Y/y/N/n): ") and returns true for 'yes' and false for' no'. This function should use the private yesOrNo(string) function. • The private yesOrNo(string) function should prompt the user with the passed sting and read the response. The user may enter 'Y', 'y', 'N', or 'n' and the function should return true for 'yes' and false for' no'. The function display an error message and re-prompt for incorrect input (an unlimited number of times). • The playRound() function should play one round of twenty-six based on the provided rules. If the current bank is £ 0, the function should do nothing and return. Otherwise, the current bank should be decremented by 1, a point value established, the dice roll array populated, and the payout determined. All applicable class variables should be updated as appropriate. If the game display boolean is true, the game details should be displayed • The showGame() function should display the complete game details, including all dice rolls, in the format shown in the examples. The function will read the applicable class variables. Make sure your program includes the appropriate documentation. Example Execution: Below is an example program execution. ed-ubuntu:% ./main ************************************************************ Welcome to the CS 202 Game of Twenty Six Initial Bank amount must be between 10 and 200 Enter Initial bank Amount: 1 Error, invalid bank amount, please re-enter. Initial Bank amount must be between 10 and 200 Enter Initial bank Amount: 1000 Error, invalid bank amount, please re-enter. Initial Bank amount must be between 10 and 200 Enter Initial bank Amount: -3 Error, invalid bank amount, please re-enter. Initial Bank amount must be between 10 and 200 Enter Initial bank Amount: 15 ********************************* Twenty-Six Game - Round Results: Dice Rolls: 5 4 2 6 2 5 1 4 2 3 2 3 2 6 5 1