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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!