What if we choose another number for n

Assignment Help Computer Engineering
Reference no: EM131272174

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"

Reference no: EM131272174

Questions Cloud

Create a static variable called numemployees : Create a static variable called numEmployees that holds an int and initialize it to zero. This will allow us to count all the Employee objects created in the main class.
Ethical challenges in the global business environment : Many business leaders believe that engaging in global business provides opportunities to expand and stay competitive. Go to "SEC Enforcement Actions: FCPA Cases" found at http://www.sec.gov/spotlight/fcpa/fcpa-cases.shtml.
Affect the pakistan balance of trade : Assignment: Do you think we should buy goods and services that are produced in Pakistan -or foreign/ imported products? Does either practice affect the Pakistan's balance of trade? Discuss in detail.
Why was t. hall singled out for scrutiny : What authority did men claim? What does the struggle to mark T. Hall's gender identity suggest about the structure of community life and the roles of men and women in colonial America?
What if we choose another number for n : 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?
Employee motivation across all employees in these regions : Assume you are a consultant working on a company that is planning to sent its expatriates to its offices in three countries, Brazil, China and India. The executives have been tasked with increasing (i) Employee motivation across all employees in thes..
What does just cause for discipline mean to you : What does just cause for discipline mean to you? In your opinion, are the Seven Tests of Just Cause a valid method of analysis? Why or why not?
Collective programming of the mind : In regards to Hofstede's "Collective programming of the mind" - what do you think/what are your thoughts: he had in mind when he defines culture as such?
Support the operations of the three major geographic regions : A large multinational company has three regional data centers to support the operations of the three major geographic regions where the company operates.

Reviews

Write a Review

 

Computer Engineering Questions & Answers

  In order to provide a convenient self-service solution for

in order to provide a convenient self-service solution for students to access personal and course-related material

  Brightidea is in the file storage business they give file

brightidea is in the file storage business. they provide file storage to free and paid clients all over the world. at

  Explain executives based on their needs

assume that you acting as an IT consultant for them. What software solutions would you recommend to your executives based on their needs? Explain your answer.

  Use a one-dimensional array to solve

make Use of a one-dimensional array to solve the following problem: Write an application that inputs five numbers, each of which is between 10 and 100, inclusive.

  You are working on a new web site for cruzes inc the web

you are working on a new web site for cruzes inc. the web site is aimed at providing travel information to consumers

  Questionwrite down an application that solicits and inputs

questionwrite down an application that solicits and inputs three integers from the user and then displays the sum

  How to write a class template sortablevector

how to Write a class template SortableVector. The class should have a member function that sorts the vector elements in ascending order (your choice of the sorting method).

  Elements of the it project plan and the critical duties of

create a word document of it projectbe sure to cite the textbook and any outside sources used. the title page should

  Computer instruction format

In the computer instruction format, the instruction length is 11 bits and size of an address field is 4 bits? Is it possible to have the 5 2-address instructions 45 1-address instructions 32 0-address instructions utilizing the format.

  Appropriate text or on-line resource

Just this Qs By consulting an appropriate text or on-line resource, obtain relevant data and hence estimate the vascular resistance of the following organs: 1) the heart (i.e. the coronary circulation) 2) the brain 3) one kidney 4) both kidneys 5)..

  Algorithm for carrying out concatenation operation

Develop an algorithm that concatenates T1 and T2 into the single binary search tree. The worst case running time must be O(h), where h is the maximum of h1 and h2, the heights of T1 and T2.

  How can you limit breadth and scope of a vulnerability scan

What is a CVE listing? Who hosts and sponsors the CVE database listing Web site? What is Zenmap typically used for? How is it related to Nmap?  How can you limit the breadth and scope of a vulnerability scan?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd