Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Assignment: Game of Pig - Monte Carlo Method

Collaboration Policy

We encourage collaboration on various activities such as lab, codelab, and textbook exercises. However, no collaboration between students is allowed on the programming assignments. Please be sure to read and understand our full policy at:

Student will demo their assignment to me for feedback and grading.

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 Task

For this assignment you will simulate a given number of hold-at-N turns of a game called Pig, and report the estimated probabilities of the possible scoring outcomes. You are NOT implementing the game of Pig, only a single turn of this game. The value of N will be acquired via user input, as will the number of repetitions.

What is Pig?

Pig is a folk dice game with simple rules: Two players race to reach 100 points. In each turn, a player repeatedly rolls a die until either the player holds and is credited with the sum of the rolls so far (i.e. the current turn score) or rolls a 1 ("pig"), in which case the turn score is 0.

So at every point during a turn, the player is faced with a choice between two moves:

roll (again) - a roll of the die occurs

2 - 6: the number is added to the current turn score; the turn continues

1: the player loses all points accumulated in the turn (i.e. scores a 0); turn ends hold - The turn ends as the the hold option is invoked for one reason or another.

You can play the game yourself a few times before you start to think about the assignment. It can be useful to visualize and understand how a turn works. Play the game here.

Hold-at-N Turn Strategy

A good strategy to help decide when to hold and when to roll is the "hold-at-N strategy":

The player chooses a number, N, that will hopefully both maximize their turn score while minimizing their chances of losing that score by rolling a 1; as soon as their current turn score reaches (or passes) N, the player holds.

We are going to test this strategy for different values of N, which will be supplied by user input, by simulating a number of turns (which will also be supplied by user input). Obviously, the larger the number of simulations, the better the estimate of probabilities.

For instance, suppose the user asks the program to test the strategy for N = 20.

We throw the die for a turn ("simulate a turn"), and get the following rolls:

Roll 1: 2 - current turn score = 2

Roll 2: 5 - current turn score = 7

Roll 3: 6 - current turn score = 13

Roll 4: 2 - current turn score = 15

Roll 5: 4 - current turn score = 19

Roll 6: 3 - current turn score = 22

At this point we end the turn by holding, since we have a score of 22 (which is at least our N).

Of course, if we simulate the same turn again, we might get:

Roll 1: 6 - current turn score = 6

Roll 2: 5 - current turn score = 11

Roll 3: 5 - current turn score = 16

Roll 4: 3 - current turn score = 19

Roll 5: 1 - current turn score = 0

We rolled a 1 which according to the rules ends the turn and grants a turn score of 0.

Question: for N = 20, what range of scores are possible? How many variables will you need to hold the probability estimates for those scores? What if we choose another number for N?

Again, remember that 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.

Random Seed Requirement

You will of course, be using the C++ cstdlib library function rand(), which you will "prime" with a seed value using the function srand(int).

As you know, if you want to get different random values every time you run a program using the rand function, you should seed it with srand(time(0));

When you are testing your program, however, you will want to directly compare your program's output with the sample runs below, so you will want to work with the exact same random values that are used in our solution. To do this you have to seed rand with 333: srand(333);

If you are not working on Cloud 9 then your values may differ from the sample results, even using the seed 333, due to differing implementations of rand() on different operating systems.

Input Requirements

Enter a single positive integer indicating the number at which to hold.
Enter a single positive integer indicating the number of turns to be simulated.
Larger numbers will tend to yield better estimations but take longer to execute.
We test with both small and large numbers, so testing may take some time.

Output Requirements

Prompt the user with: "What value should we hold at? "
Prompt for number of simulations: "Hold-at-N turn simulations? "
Output a blank line between the input prompt and table output.
On the next line, print "Score" and "Estimated Probability" separated by a tab (‘\t').

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.

Print the table to a file named "output.txt"

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92026899
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Computer Engineering

We have a scheme program belowdefine lst i think you like

We have a Scheme program below: (define lst '(I (think you) like me)) (set! lst (cdr lst)) (set-car! lst '(thinks you)) (set! lst (cons 'he (cons 'also lst))) (a) For each execution step of the above program, draw the me ...

Start your c development tool and view the swatthebugs16cpp

Start your C++ development tool and view the SwatTheBugs16.cpp file. The file is contained in either the Cpp7\Chap05\Swat TheBugs16 Project folder or the Cpp7\Chap05 folder. (Depending on your C++ development tool, you m ...

Prove the sieve of eratosthenes algorithm has runtime

Prove the Sieve of Eratosthenes algorithm has runtime complexity ≤ O(n log log n). Sieve Input: an integer n > 1. Let A be an array of Boolean values, indexed by integers 2 to n, initially all set to true. for i = 2,3,4, ...

Here are specific instructions about the two programs that

Here are specific instructions about the two programs that you will write: Copying the Data Block using Arrays The first program that you will write will use arrays for the data transfer. You may directly use SRCBLK and ...

Say you have some pictures each 500 kb in size say you also

Say you have some pictures each 500 KB in size. Say you also go to a store and buy a new desktop computer. Approximately how many pictures could you put on the hard disk, assuming you could use all the space on the disk ...

Run sqlplus systemoracle11 and spool to ccis421bs6spooltxt

Run sqlplus system/Oracle11 and SPOOL to c:\cis421b\S6spool.txt User SCOTT, who had the password TIGER, changed it to something more secure, but has since forgotten it. If possible, demonstrate what you as a DBA can do t ...

Question you are required to sort a file containing

Question : You are required to sort a file containing integers between 0 and 999999. You cannot afford to use one million pigeon-holes, so you decide instead to use one thousand pigeon-holes numbered from 0 to 999. You b ...

What is vsftpd name two other server packages that may be

What is vsftpd? Name two other server packages that may be used for the same purpose

Question sunshine health corporation is seeking to improve

Question : Sunshine Health Corporation is seeking to improve overall connectivity across their corporate campus near the Hawaii Kai Marina, Honolulu, Hawaii. The campus buildings have recently been updated, thus the LANs ...

Two contract offers are made to you the first contract

Two contract offers are made to you. The first contract offers $10,000 at the end of each year for the next five years and then $20,000 per year for the following 10 years. The second offer pays 10 payments, starting wit ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As