Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are coding a simple game called Pig. Players take turns rolling a die. The die determines how many points they get. You may get

You are coding a simple game called Pig. Players take turns rolling a die. The die determines how many points they get. You may get points each turn your roll (turn points), you also have points for the entire game (grand points). The first player with 100 grand points is the winner. The rules are as follows: Each turn, the active player faces a decision (roll or hold): Roll the die. If its is a: 1: You lose your turn, no turn total points are added to your grand total. 2-6: The number you rolled is added to your turn total. Hold: Your turn total is added to your grand total. Its now the next players turn.

Make a simple AI with a random number. Each tun decide what the computer will do by rolling a 6 sided die, a D6: on 1-3 hold, on a 4-6 roll again.

Your code must be readable inside Canvas (no garbage files). Your code must compile under the gcc compiler (g++ compiler is an alias to gcc). Your code must execute under Ubuntu 14.00 or greater. Your output must be logically correct. Do not optimize for computer performance. Global variables in any form are forbidden. This includes #define statements, too. You can, and should, put classes and structs right under your include statements and using namespace std; statement. You cannot use any data structures from the standard template library. No or or anything like that. You can use C-Style arrays, however. You can also build your own dynamic memory structures. Style guide elements apply: comments, layout, Program Greeting, Source File Header, and variables etc. etc.

These are additional features for your program. Specifications arebundled into groups: "A", "B", and "C". These groups correspond tothe highest grade you can get for your code (i.e. completing "C" spec-ifications means I start evaluating your assignment from a C). Thisgives you some control over your potential grade. The more workyou do, the better grade you can get. There is also a loose associationwith difficulty, "C" elements tend to be a bit easier than "A" elements.

"C" Specification Bundle. // Specification C1 - Fixed Seed 1 This program will need to generate random numbers. Set the random number seed to a specific integer. That way, it will always generate the same random number sequence - easier to fix bugs that way. Use the unsigned variable seed to hold the seed value.

// Specification C2 - Student Name Allow name to accept first plus last name (ie 2 words). Do not use 2 cins or 2 string variables, just 1 variable. Read this in from the keyboard after your program greeting runs. Display it somewhere in the output.

// Specification C3 - Numeric Menu Use a numeric menu to collect the human players actions. See figure 1 for an example menu.

// Specification C4 - ProgramGreeting Create a void ProgramGreeting() function which runs imme-diately upon program start (then initialization code, then your menu). You are free to put anything you want in this function many students put ASCII art here. Do not use cin to pause output, we want this function to run and done. Remember you will use this in every homework assignment in this class.

"B" Specification Bundle. // Specification B1 - Display Turn Stats Keep track of the points each player scores each turn as well as the overall points both sides have each turn in the game.

//Specification B2 - Source File HeaderPut a header on the very top of your source file. First line pro- gram name.cpp, second line your name and this class, third lineassignment due date. Ill look for comments like this:

// pig.cpp 3

// Pat Jones, CISP 413 // 12/34/56

"A" Specification Bundle. // Specification A1 - D6() function This method returns a randomly generated int between 1 and 6 every time its called. Replace the code which does that in your assignment with this. Make sure the function name is D6. 4 The 4 A reminder. function prototype should look something like this:Its OK to put this specification comment at line 1 for this assign-ment. In future assignments this will still be required, but it will no longer appear as a specification it will appear in the require- ments section.

// Specification B3 - hiScore on Heap Store the games high score in a variable in the heap. Call this variable hiScore. Dont forget to clean up after yourself before the program quits. This holds the high score for all the games you have played since the program began execution now. You do not need to store anything in a text file - that would be between games high score.

// Specification B4 Display hiScore Display the value you stored in B3 on the console at the end of the game. If you played multiple games, it is the highest score of all games played

"A" Specification Bundle. // Specification A1 - D6() function This method returns a randomly generated int between 1 and 6 every time its called. Replace the code which does that in your assignment with this. Make sure the function name is D6. The function prototype should look something like this:

int D6(); Your program can use whichever random number function (A1 or A2) you wish, or even both of them. If you only use one, I suggest you use the ProgramGreeting to test the other function to make sure it works correctly

// Specification A2 - RandomNumber() function Create a function which generates a random number between arguments lo and hi. The function prototype should look like this:

Make sure you call your function RandomNumber.

// Specification A3 - Protect RandomNumber() input Using an if statement, protect your RandomNumber() function from bad data. Return a -1 error code if RandomNumber() receives bad input. Argument rules are: 1. Hi must be greater than lo. 2. Lo cannot be less than 1. 3. Hi cannot be greater than 100. In your ProgramGreeting() function exercise these three rules to make sure they are working in your program.

// Specification A4 - Input Validation Detect and re-prompt if incorrect data (i.e. not 1, 2, or 3) is entered. See figure 1 for an example menu.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions