ComeçarComece de graça

Function to run one round

Now, let us use the function from the previous exercise, and write one overall function, called evaluate_first_roll, to complete one round of Craps. As seen in the sample code below, this function will take the shooter's first roll as its input, and proceed accordingly from there. The roll_dice and roll_after_point functions have been preloaded for you.

Este exercício faz parte do curso

Probability Puzzles in R

Ver curso

Instruções do exercício

  • Use the %in% operator to check whether the roll is a 7 or 11, resulting in an immediate win.
  • Use the %in% operator to check whether the roll is a 2, 3, or 12, resulting in an immediate loss.
  • If a point is established, continue rolling until either the point is rolled again, resulting in a win, or a 7 is rolled, resulting in a loss.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

evaluate_first_roll <- function(roll){
  # Check whether the first roll gives an immediate win
  if(___){
    won <- TRUE
  }
  # Check whether the first roll gives an immediate loss
  if(___){
    won <- FALSE
  }
  if(roll %in% c(4,5,6,8,9,10) ){
    # Roll until the point or a 7 is rolled and store the win/lose outcome
    won <- ___
  }  
  return(won)
}
Editar e executar o código