Lab 01: Roulette
Introduction
We will simulate the casino game of American roulette! On an American roulette wheel, there are 38 equally-sized spaces that differ in color and number value:
Two spaces are green, and are labelled 0 and 00
The remaining spaces alternate red and black and take on the values 1-36
- There is no particular order to the numbers
The game is simple: a ball is dropped and spins along the roulette until it settles in one of the 38 spaces. Each space has an equal chance of being landed on.
Differing wagers or bets can be made on where the ball will end up landing. For example, it is common to bet on a color. If you “bet on black”, you think the ball will land in a black-colored space. Or you might “bet on events”, which means you think the ball will land in a space with an even number greater than 0.
You wager some money when you make a bet. For example, if I bet $5 and I win, I will get my original $5 back and also gain $5 from the house. So I net $5. If I lose, then the house takes my $5 and I net -$5. In summary:
If I win, I net the amount that I bet
If I lose, I net the negative amount that I bet
In either case, your net gain will be either positive or negative.
Because this is a casino game, we know that the house always wins. So, the purpose of this assignment is to simulate/demonstrate that the player will always lose money in the long run.
Assignment
Imagine that you have unlimited funds and will play roulette n
number of times. You can choose any integer value of n
greater than 200, but be sure to store it as a variable for reproducibility. You will always bet on red and wager $5. For each one of the n
rounds, keep track of the net gain.
At the end of your gambling, obtain and report the sum and average of your net earnings.
Optional: make a plot of a running total of your net gains (i.e. the x-axis represents the iteration/round of betting, and the y-axis represents the total gains up to and including that round).
Please clone the Lab 01 GitHub repository and work in the lab-01-roulette.Rmd
file provided for you.
Details
For simplicity, you can assume that the red spaces take on the values (1, 2, …, 18) and the black spaces take on the values (19, 20, …, 36). You can decide how you would like to represent the two green spaces.
Here is some structure that might help you design your code: you will need to create a for
loop where on every iteration you should:
“Spin” the roulette
Evaluate how the outcome of your spin compares to your bet
Make note of the net gain on that iteration
Concepts used
for
loopsConditional statements
Comparing
R
objectsCreating and modifying vectors
Working with GitHub: try to regularly commit your changes and push them back to GitHub!
Submission details
Knit, commit, and push your project back to github.com using the GitHub Desktop client.
Submit your knitted PDF onto Canvas. You may need to install the tinytex
package to knit to PDF.