C++ Creating a Function that generates a single turn in Monte Carlo/Pig: I\'m ha
ID: 660991 • Letter: C
Question
C++ Creating a Function that generates a single turn in Monte Carlo/Pig:
I'm having a large amount of confusion trying to figure out how to code a certain function.
My Code so far:
int singleTurn(int N)
{
int roll;
int total;
for (N = 0; N = N; N++)
{
roll = 1 + (rand() % 6);
}
total += roll;
cout << total;
return total;
}
What the function needs to do:
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 and simulating this single turn over and over. The value of
N will be acquired via user input, as will the number of repetitions.
Pig is a folk dice game in which every single turn boils down to two simple rules where a player rolls
or does not roll. Each time a roll of the die occurs, an action is taken based on the die value. For our
simulations, we will implement a specific strategy such that once our minimum turn score is reached
the turn will end (opt to hold).
In summary, a turn looks like:
? roll (or 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. A hold may occur for multiple reasons.
singleTurn
? name: singleTurn
? return type: integer, the score of a single turn
? parameters: one integer representing the hold value for a single turn