--%>

Program to Calculate Estimate Probability

Collaboration Policy

Collaboration between students on programming assignments is NOT allowed under any circumstances - you may not even discuss your work with others; you may NOT get coding assistance, or copy code, from ANY outside source (books, web sites, current or past students, your own previous sub missions if you are repeating the course, etc.). We test every submission for copying and when we find it we treat it as flagrant academic dishonesty on the part of all parties involved, regardless of their roles as provider or consumer. The penalty is generally instant failure in the course, in addition to the usual sanctions applied by Student Judicial Affairs.

As you can see from the submission header below, we ask you to essentially take an oath that the code you submit is entirely your own work.

At the same time, we certainly understand very well that you will frequently need help completing your programming assignment, so we provide channels where you may get that help in a way which will strengthen your programming skills: instructor and TA office hours, and the discussion forums where you can ask all the questions you want about the assignment, and even help others with the understanding that you have gained (but not, of course, with any actual code).

Assignment Submission Instructions

Your assignment must be submitted as a simple text file named main.cpp

Files in ANY other format (MS Word document, etc.) or with ANY other name (main, main.doc, main.txt, etc.) will not be graded.

Submit your work via the appropriate iLearn assignment link, making sure you use the correct link.

We strongly recommend that:

1. you submit at least 6 hours before the deadline, even if you haven't completed the program - you can re-submit as often as you like, and we will only grade the final submission

2. once you have submitted your final attempt, go back and download it back to your system: then run it just to make absolutely sure that it really is the file you intended to submit!

You are budding professionals, and are expected to take full responsibility for abiding by the requirements of a contract.

The only reason we will ever accept for a missed deadline is if the system administrators inform me that either the iLearn system or the CS department servers were off-line for a significant period around the time of the deadline (In which case we will probably have notified you of alternative procedures).

Remember to include the following header information at the top of your program

(DO NOT REMOVE THE // at the beginning of each line, these tell the compiler to ignore these lines)

// =============== BEGIN ASSIGNMENT HEADER ================

/// @file assn<#>/main.cpp

/// @brief Assignment <#, e.g. 1,2,3..10> for CS 10

///

/// @author []

/// @date

///

/// @par Enrollment Notes

/// Lecture Section:

/// @par

/// Lab Section:

/// @par

/// TA:

///

/// @par Plagiarism Section

/// I hereby certify that the code in this file

/// is ENTIRELY my own original work.

// ================== END ASSIGNMENT HEADER ===============

NOTE: This header MUST appear at the top of EVERY file submitted as part of your assignment

(don't forget to fill in *your* details and remove the <> brackets!!).

Copy & paste this header into your file then update personal details.

(make sure spaces are copied too!)

Completed Example, notice the <> are all removed and spacing exists:

// =============== BEGIN ASSIGNMENT HEADER ================

/// @file assn1/main.cpp

/// @brief Assignment 1 for CS 10 Winter 2013

///

/// @author Adam Koehler []

/// @date January 8, 2013

///

/// @par Enrollment Info

/// Lecture Section: 002

/// @par

/// Lab Section: 22

/// @par

/// TA: Adam Koehler

///

/// @par Plagiarism Section

/// I hereby certify that the code in this file

/// is ENTIRELY my own original work.

// ================== END ASSIGNMENT HEADER ===============

Assignment Specifications

We are going to use the Monte Carlo Method to determine the probability of scoring outcomes of a single turn in a game called Pig.

Your Assignment

For this assignment you will simulate a given number of hold-at-20 turns, and report the estimated probabilities of the possible scoring outcomes. You are NOT implementing the game of Pig, only a single computer turn of this game.

What is Pig?

Pig is a folk jeopardy dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 ("pig") is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn, the player is faced with two decisions:

1. roll - if the player rolls

 1: the player scores nothing and it becomes the opponents turn

 2 - 6: the number is added to the turn total and the turn continues

2. hold - The turn total is added to the player's total score and it becomes the opponent's turn.

Hold-at-20 Turn Strategy

Again, you are only implementing one turn of this game and then simulating it many times to estimate the probability of each scoring outcome of this turn strategy.

When implementing a single turn for the computer, one strategy to use is something called the hold-at-20 strategy. The hold-at-20 strategy has the computer continue to roll the die until it rolls a pig (1) which gives them a turn score of 0 or until it accumulates a turn score of 20 or more. In other words, the computer stops if it reaches a turn score of 0, 20, 21, 22, 23, 24, or 25.

For example, on the computer's turn, it rolls the following:

Roll 1: 2

Roll 2: 5

Roll 3: 6

Roll 4: 2

Roll 5: 4

Roll 6: 3

At this point the computer stops rolling since it has a score of 20 or higher (22 in this case).

It didn't stop after Roll 5 because its turn score was only 19 (2 + 5 + 6 + 2 + 4) at that point.

Random Seed Requirement

For this assignment, you MUST seed the random function with the value 1000 (instead of time(NULL)) so that you get these EXACT values (when compiled and run on CS server).

Input Requirements

Enter a single positive integer indicating the number of turns to be simulated. (Larger numbers will tend to yield better estimations as we saw in lecture.)

Output Requirements

  1. Initially, prompt the user with: "Hold-at-20 turn simulations? "
  2. Output a blank line between the input prompt and table output.
  3. On the next line, print "Score" and "Estimated Probability" separated by a tab.
  4. After the simulations, print a table line for each score outcome that occurred in increasing order of score. For each score outcome, print the score, a tab, and the fraction of turn simulations that yielded that score rounded to six digits after the decimal place.

Notice that the results all have six digits to the right of the decimal. Also note, the 1 count simulation example is not meant to always produce 1.000000 in the score 21 category but it will exist in some category and all 6 others will be 0.000000.

Marking Guidelines

  1. Make sure your code compiles.
  2. Make sure your output score values, results and spacing match what is specified.
  3. We utilize the diff command to grade so make sure your spelling is correct.

Basic Style Guidelines

  1. indentation - follow proper 2-4 space indentation as you go into loops or branches
  2. spacing - blank lines should be used to separate logic blocks
  3. no line wraps - no line of code should have more than 80 characters
  4. "meaningful" variable names
  5. comments - each logical block of code should have a brief explanatory comment

 

   Related Questions in Programming Languages

  • Q : What is no-arg constructor no-arg

    no-arg constructor: It is a constructor which takes no arguments. By default, each and every class without an explicit constructor has a default no-arg constructor with the public access. Its role is entirely to invoke the no-arg constructor of the in

  • Q : What is Automation Testing life cycle

    What is Automation Testing life cycle?

  • Q : What is an Object Object : It is an

    Object: It is an instance of a particular class. In common, any number of objects might be constructed from a class definition. The class to which an object belongs states the common characteristics of all instances of that class. In those characteris

  • Q : State Null character State Null

    State Null character: The \u0000 character. The care must be taken not to confuse this with null reference.

  • Q : Identify Customers in SQL The company

    The company wish to provide an incentive of free shipping to such customers who have not returned for 2 months. Build a procedure named PROMO_SHIP_SP which determines these customers are and then updates the BB_PROMOLIST table accordingly. The procedure employs the be

  • Q : Choice of technology in coding of game

    What are the choice of technologies while coding a game?

  • Q : What is sticky bit Explain the sticky

    Explain the sticky bit?

  • Q : Explain Assignment operator Assignment

    Assignment operator: The operator (=) employed to store the value of an expression into the variable, for example: Variable = expression; The right-hand

  • Q : Describe File system File system : The

    File system: The operating system makes it possible to utilize space on a computer's disk drives by imposing a structured file system on disk storage. Each and every file system contains its own conventions for the manner in which the files are named,

  • Q : Explain Cast Cast : Where Java does not

    Cast: Where Java does not allow the utilization of a source value of one type, it is essential to use a cast to force the compiler to admit the use for the target type. The care must be taken with casting values of primitive types, as this frequently