--%>

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 : Explain Throws clause Throws clause :

    Throws clause: It is a clause in a method header pointing that one or additional exceptions will be propagated from this technique. For example:    public int find(String s) throws NotFoundExc

  • Q : What are collections and generics What

    What are collections and generics?

  • Q : Differences between primary storage and

    What are the differences between primary storage and secondary storage?

  • Q : Define Data type Data type : There are

    Data type: There are 8 primitive data types in Java; five of such symbolize numerical types of changeable range and precision - float, double, int, long and short. The remaining three are employed to symbolizing single-bit values (that is, Boolean), s

  • Q : What is an Exception Exception : An

    Exception: An object symbolizing the occurrence of an exceptional circumstance - usually, something which has gone wrong in the smooth running of a program. Exception objects are made from classes which expand the Throwable class.

  • Q : Define Delegation Delegation : The

    Delegation: The procedure by which an object passes on a message has received to a sub-ordinate object. When inheritance is not accessible in a programming language, then delegation is the most viable option for ignoring code duplication and promoting

  • Q : Storing the CSS Definitions in external

    Describe the code in order to store CSS Definitions within the external Files.

  • Q : Problem on linear equations using Matlab

    Use Matlab to solve the following system of linear equations:2x + y + 3z = 12x + 6y + 8z = 36x + 8y + 18z = 5Capture Matlab code and the result in a text file.

  • Q : What is Timeslice Timeslice : It is the

    Timeslice: It is the amount of running time assigned to a process or thread prior to the scheduler considers the other to be run. The process or thread will not be capable to employ its full allocation of time when it becomes blocked or preempted thro

  • Q : Explain Untyped Allocations Untyped

    Untyped Allocations: In C/C++ untyped allocations such as malloc, calloc, and realloc can easily be used to create overlays, which again require translation overhead to keep the corresponding non-overlaid objects consistent.

    Discover Q & A

    Leading Solution Library
    Avail More Than 1445828 Solved problems, classrooms assignments, textbook's solutions, for quick Downloads
    No hassle, Instant Access
    Start Discovering

    18,76,764

    1937998
    Asked

    3,689

    Active Tutors

    1445828

    Questions
    Answered

    Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!

    Submit Assignment

    ©TutorsGlobe All rights reserved 2022-2023.