Question
Write R code to simulate 10,000 trials of a craps game. This simulator should tally the results of wins and losses and estimate P(win) as
Write R code to simulate 10,000 trials of a craps game. This simulator should tally the results of wins and losses and estimate P(win) as it's output.
This is where im at so far, can anyone add to this to make it work properly.
So we'll start by creating a counter, call it wins and initialize it to 0:
wins<-0
If they win on the first roll, add one to the win counter:
if(roll== 7|| roll ==11) {
wins<-wins+1
}
else if (roll == 2 ||roll ==3 || roll=12){
#do nothing they lost
}
else {
#otherwise, they scored a point
#inside here, they need to roll again (get a second roll value, but don't replace the first)
# compare it to the first, if it matches, they win, if it's a 7 they lose, if it's anything else, keep rolling until it's a 7 or a win
}
Can anyone help finish this code with me?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started