Problem

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 it's 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. It's now the next players turn.

Problem Features

Make a simple AI with a random number. If you wish you can use this algorithm: For each decision the computer rolls, 1-3 hold, 4-6 roll again. You can also come up with whatever you want to accomplish this task, but beware, there are programming competi- tions to do exactly this with Pig.

Requirements

  • Do not optimize for computer performance.
  • Global variables in any form are forbidden. This includes #define statement's, too. You can, and should, put classes and structs right under your include statements and using namespace std; statement.
  • Put a Source File Header at the top of your source file.
  • Include a Program Greeting in your program. This is different from a menu because it runs only once at the start of your pro- gram. When you start including unit tests, this is a great place to call that code.
  • Do not use c (.h) style libraries. Use c++ libraries instead.
  • You cannot use any data structures from the standard template library. No < vectors> or < arrays> or anything like that. You can use C-Style arrays, however. You can also build your own dynamic memory structures.

Specifications

// Specification C1 - Fixed Seed
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.

// Specification C2 - Student Name
Allow name to accept first plus last name (ie 2 words). 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 - Bulletproof Menu
Detect and re-prompt if incorrect data (i.e. not 1, 2, or 3) is en- tered.

// 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 - Display Due Date
Display the date this assignment is due in your program greeting section.

// Specification B3 - Hi Score on Heap
Store the game's high score in a variable in the heap. Dont forget to clean up after yourself before the program quits.

// Specification B4 - Display High Score
Display the value you stored in B3 on the console at the end of the game.

// Specification A1 - D6() function
This method returns a randomly generated int between 1 and 6 every time it's called. Unlike Specification A2, this may or may not occupy its own function. I suggest you use this code somewhere to just confirm it works - but notice between A1 and A2 all your random number needs will be met.

// Specification A2 - RandomNumber() function
Create a function called RandomNumber() which generates a ran- dom number between arguments lo and hi. This function is not a replacement for specification A1. I know you will have two func- tions which do essentially the same thing - but you will only need to use one of them.

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

  • Hi must be greater than lo.
  • Lo cannot be less than 1.
  • Hi cannot be greater than 100.

// Specification A4 - Protect RandomNumber() output
Make sure your RandomNumer() function doesn’t send bad output. Use an if statement before your return to make sure the random number isn't greater than 100. Return a -2 error code if you gener- ate bad output.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.