运行一轮的函数
现在,请使用上一题的函数,编写一个总控函数 evaluate_first_roll,完成 Craps 的一整轮。正如下方示例代码所示,该函数以射手(shooter)的首次掷骰为输入,并据此继续执行。roll_dice 和 roll_after_point 函数已为您预加载。
本练习是课程的一部分
R 中的概率谜题
练习说明
- 使用
%in%运算符检查掷骰结果是否为 7 或 11,若是则立即获胜。 - 使用
%in%运算符检查掷骰结果是否为 2、3 或 12,若是则立即失败。 - 如果确立了点数(point),则继续掷骰,直到再次掷出该点数(获胜)或掷出 7(失败)。
交互式实操练习
通过完成这段示例代码来试试这个练习。
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)
}