Implement several functions for this program

Assignment Help Basic Statistics
Reference no: EM131096095

CS 10 - Assignment 7: Monte Carlo - Board Game

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: Full Collaboration Policy

Submission Instructions

Submit to R?Sub testing, feedback and grading.

Assignment Specifications

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, so 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 onceThe starting space is also the last possible spot a player can land in a single rotation - i.e. roll until at or beyond start but don't record a landing past (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 will return the cell with most landings within a closed interval of board spots.

(A 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; 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

board - the game board vector, by const reference

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.

When debugging your program using srand(333), the first 24 rolls of a die on c9 (linux) are:

5 4 4 3 3 4 5 2 3 6 5 2 4 1 5 5 3 3 6 4 4 3 4 2

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 ?values? of the board in the simulation (so landing on jail does not send you to jail).

So side 1 is spots 1-10, side 2 is spots 11-20, side 3 is spots 21-30, and side 4 is spots 31-40. In the game Monopoly, a player rolls two six sided dice. We will use the 24 rolls of srand(333) within our example simulations.

We show the dice rolls (based on the 24 values), the accumulation of the dice rolls and the vector cell that would be incremented based on those dice rolls. We show two simulations, so if you request 1 simulation then only simulation 1 would run, but if you request 2 simulations both simulation 1 and simulation 2 would run before the program completes. The first two example runs correspond to our specific Monopoly example.

Simulation 1

Dice Rolls:

5+4 -> 9

4+3 -> 7

3+4 -> 7

5+2 -> 7

3+6 -> 9

5+2 -> 7

Accumulation after roll:

9

16

23

30

39

46

Vector cell increased:

8

15

22

29

38

Beyond "Go" (40)
(i.e. not recorded)

Simulation 2

Dice Rolls:

4+1 -> 5

5+5 -> 10

3+3 -> 6

6+4 -> 10

4+3 -> 7

4+2 -> 6

Accumulation after roll:

5

15

21

31

38

44

Vector cell increased:

4

14

20

30

37

Beyond "Go" (40)
(i.e. not recorded)

Example Runs (User input has been bolded and underlined to help differentiate typed input from program output.)

user@cs10: $ g++ boardGame.cpp

user@cs10: $ run a.out

How many sides of the board are there? 4

How many spots are on each side? 10

How many simulations? 1

The following spots on each side have the most landings:

On side 1, spot 9 has the most landings: 1

On side 2, spot 16 has the most landings: 1

On side 3, spot 23 has the most landings: 1

On side 4, spot 39 has the most landings: 1

user@cs10: $ g++ boardGame.cpp

user@cs10: $ run a.out

How many sides of the board are there? 4

How many spots are on each side? 10

How many simulations? 2

The following spots on each side have the most landings:

On side 1, spot 5 has the most landings: 1

On side 2, spot 15 has the most landings: 1

On side 3, spot 21 has the most landings: 1

On side 4, spot 31 has the most landings: 1

user@cs10: $ g++ boardGame.cpp

user@cs10: $ run a.out

How many sides of the board are there? 1

How many spots are on each side? 11

How many simulations? 3

The following spots on each side have the most landings:

On side 1, spot 9 has the most landings: 2

user@cs10: $ g++ boardGame.cpp

user@cs10: $ run a.out

How many sides of the board are there? 6

How many spots are on each side? 12

How many simulations? 10000000

The following spots on each side have the most landings:

On side 1, spot 7 has the most landings: 1821959

On side 2, spot 16 has the most landings: 1482794

On side 3, spot 26 has the most landings: 1437018

On side 4, spot 44 has the most landings: 1430447

On side 5, spot 49 has the most landings: 1430818

On side 6, spot 65 has the most landings: 1430729

Reference no: EM131096095

Questions Cloud

Express the self-inductances with the constant angular : Express the self-inductances with the constant angular displacement in terms of step length.
Home remodeling and repair business : Santiago runs a home remodeling and repair business. List the three key economic questions, and give relative examples as they apply to his company. Explain. How could thinking at the margin help Santiago increase his revenue?
Particular model of digital camera : Suppose you discovered that a particular model of digital camera could be bought much more cheaply in Minneapolis, Minnesota, than in Flagstaff, Arizona.
Express the self-inductances for the single-stack : Express the self-inductances for the single-stack, variable-reluctance stepper motor shown in Fig. 9.5-1 with the constant angular displacement in terms of step length.
Implement several functions for this program : 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: Full Collab..
Rebels from participating in the nation new government : Conservative European states agreed to Belgium's independence in 1831 under the condition that A The Belgians allowed Charles X of France to become their new king B Belgium would remain neutral in all international affairs C The Belgians did not enco..
Profitable for farmers to produce rice : 1) Q: One reason why the quantity demanded of a good increases as its price decreases is that 2) Q: If it is now mo re profitable for farmers to produce rice than corn, we can expect
Calculate the temperature change in celsius degrees : calculate the temperature change in Celsius degrees
Annotated bibliography of article-workplace safety : Prepare an Annotated Bibliography of given articles- Workplace safety" A call for research And Introducing carbon structural adjustment: energy productivity and decarbonization of the global economy

Reviews

Write a Review

Basic Statistics Questions & Answers

  Find the 95 confidence interval for the mean time wired

a sample of 352 subscribers to wired magazine shows the mean time spent using the internet is 13.4 hours per week with

  The mean of sample a is significantly different than the

the mean of sample a is significantly different than the mean of sample b. sample a 59 41 74 62 87 73 sample b 53 67 85

  Collapse the response categories in the following table so

Collapse the response categories in the following table so that it meets the assumption of the chi-square test; then perform the test.

  Can we reject the null hypothesis that the sample is a

a set of sample scores from an experiment has an n 30 and an xobt 19.a. can we reject the null hypothesis that the

  In what class interval must the median lie

What percentage of the checkout times was at least 3 minutes? In what class interval must the median lie? Explain your answer.

  How did irs ap stat scores compare to the national results

Some questions to consider: How did IRS AP Stat scores compare to the national results? How did AP Stat students do compared to the BC Cale students? DO these results indicate that IRS males and females may perform differently on the AP Statistics ex..

  Performs a test of hypothesis

Drug sniffing dogs must be 95% accurate. A new dog is being tested and is right in 46 of 50 trials. Find a 95% confidence interval for the proportion of times the dog will be correct.

  Real engineering situations usually involve measurements

In passing, Ben also cryptically comments: By testing the signs of the endpoints of the intervals, it is possible to break mul-interval into nine cases, only one of which requires more than two multiplications. Rewrite this procedure using Ben'..

  What is the mean of the distribution

What is the probability that the variable will take the value 2? What is the mean of the distribution?

  If a blue marble is drawn it is placed back in the box

consider the following marble game a box contains m red marbles and n blue marbles n m gt 0 and a fixed number - here

  A student is required to take college algebra before taking

a student is required to take college algebra before taking stats. but not all students are required to take stats.

  What are the steps in the construction

what are the steps in the construction

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