C++ Monte Carlo Assignment: Once again, we are going to use the Monte Carlo Meth
ID: 662516 • Letter: C
Question
C++ Monte Carlo Assignment:
Once again, we are going to use the Monte Carlo Method, this time to determine the different
frequencies of landing on each spot of a board in a single circumnavigation of the game board.
The Board
You should now be learning to make your programs as general as possible. For this assignment, you
have to be able to make your calculations work for any board size and configuration: all you know
about it is that all the "cells" (the squares on which a player can land) are evenly distributed around
the edge of an n?sided polygon, k cells per side. For our purposes, we shall number the cells 1
through (n * k), with cell (n * k) also being the original starting position.
The Simulation
A player rolls a pair of 6?sided dice, and moves that many cells from the start spot; this process is
repeated as many times as required until the roll places the "piece" on or past the starting space.
Since we are modeling only a single player, there are no turns: each simulation is of a single player
going around the entire board once. The starting space is also the last possible spot a player can
land in a single rotation, we record landing on this space but then end the simulation (no more rolls and
we do not record anything if we land beyond this last space [beyond n*k]).
Your Task
You will model the board as a vector of size (n * k). Note that although you will be working with
indices 0 through (n * k ? 1), you will report the cells as numbers 1 through (n * k), as this is how a
player would think about the board.
As your player traverses the board, you will record each cell he/she lands on. You will perform
multiple simulations of a single board rotation, accumulating in each vector cell the number of times
the player lands on the corresponding board space.
You will implement several functions for this program. As you have learned, you must understand
how to test each function with a "test harness". We do not submit the harnesses to R'Sub, R'Sub
already has several to test with.
Functions
We list two functions that are required, we provide an idea for third optional function and you can
implement other additional functions that you find useful. You should write function comments for
each of the functions you define, containing an @brief, @param and @return similar to those we
have previously provided for you. R'Sub will test each function individually.
The first function will simulate the dice roll. Once again we want the function to be as general as
possible, so we will parameterize both the number of dice and the number of sides on a dice.
The second function returns the cell with most landings within a closed interval of board spots.
(The closed interval [5,10] means any of the values 5, 6, 7, 8, 9, or 10.)
rollNDice
? simulates rolling N dice, each of which has the specified number of sides
? parameters: two integers by value:
? first integer: the number of dice to roll, by value
? second integer ? the number of sides on the dice, by value
? return type: integer, the summation of all N dice rolls
mostLandings
? returns the cell on the board with the most "landings", within an inclusive interval
? parameters: a vector<int>; two integers
? first parameter: the game board vector, by const reference
? second parameter: the start of the interval to be tested, by value
? third parameter: the end of the interval to be tested, by value
? return type: integer, the index of the first cell in the interval with the most landings
Optionally, you may want (in addition to other functions you think of):
printBoard
? procedure, prints out game board, showing number of landings on each cell
? parameters: a vector<int>
? return type: void
Random Seed Requirement
We want you to submit to R'Sub with srand(time(0)); as the seed. However, to reproduce the
results displayed in the examples you you have to seed rand with 333: srand(333);
A note to those not working within C9. The random numbers generator on different systems
(Windows, Linux, OS X) may produce different results even when using the specified seed value.
? board ? the game board vector, by const reference
When debugging your program using srand(333), the first 24 rolls of a die on c9 (linux) are:
544334523652415533644342
Input Requirements
? Prompt the user for the board configuration: number of sides, number of cells per side
? Prompt the user for the number of simulations to run.
Output Requirements
Use the mostLandings function to help you find and report the cell that has the most landings on
each side of the board. As shown in the examples, each side of the board is reported. You will
need to write a loop to print out this information and the loop should use simple mathematics to
calculate the beginning and ending spots based on the side number.
Explicit Example
For our explicit example we will utilize the board game Monopoly. The board for Monopoly has 4
sides of 10 spaces, so our vector needs 40 cells. The start space in Monopoly is "Go", but "Go" will be
the last spot represented by the last cell in the vector, as the first board space is the spot
immediately after "Go".
Note that we are not incorporating the
Explanation / Answer
#include #include #include #include #include using namespace std; int main () { srand (time(0)); string operation; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.