以下是我认为您可以在 R 中对游戏进行建模的方法。第一个版本与您所拥有的类似:有 50% 的机会猜对,如果猜对了,玩家就会推进一个牌。否则他们不这样做,并且玩家人数减1。如果玩家人数达到0,或者他们前进到最后,则游戏结束。这显示在 中squid_bridge1()
。
squid_bridge1 <- function(players, n, prob) {
if (players == 0 | n == 18) {
# All players have died or we have reached the end
return(players)
}
jump <- rbinom(1, 1, prob)
if (jump == 0) {
# Player died
return(squid_bridge1(players - 1, n, prob))
}
if (jump == 1 & n < 18) {
# Player lives and advances 1 space
return(squid_bridge1(players, n + 1, prob))
}
}
然而,这并不能准确地描述游戏,因为错误的猜测会给剩余的玩家额外的信息。如果玩家选择错误,那么下一次猜测正确的概率不是 50%,而是 100%。但是,在那之后,正确猜测的概率会降低到 50%。这可以用另一个参数来解释,以跟踪先前猜测的正确性。
squid_bridge2 <- function(players, n, prob, previous) {
if (players == 0 | n == 18) {
# The game ends if there are no players or they have reached the end
return(players)
}
if (previous == 0) {
# The previous guess was wrong, but now the players know where to go next
return(squid_bridge2(players, n + 1, prob, previous = 1))
}
jump <- rbinom(1, 1, prob)
if (jump == 0) {
# Player died
return(squid_bridge2(players - 1, n, prob, previous = 0))
}
if (jump == 1 & n < 18) {
# Move is correct. Advance 1 space
return(squid_bridge2(players, n + 1, prob, previous = 1))
}
}
但是,有一个问题。在节目中并不是那么简单,玩家摔倒的原因不是错误的猜测(被推,故意跳跃等)。我不知道做这样的事情的合理概率是多少,但它可能很低,比如说 10%。
not_stupid <- function() {
x <- runif(1, 0, 1)
if (x <= 0.1) {
return(FALSE)
} else {
return(TRUE)
}
}
由于情绪在每次移动之前都会飙升,因此我们将在每次移动之前进行测试。
squid_bridge3 <- function(players, n, prob, previous) {
if (players == 0 | n == 18) {
# The game is over because there are no players left or they reached the end
return(players)
}
if (previous == 0) {
# The previous guess was wrong, but now the players know where to go next
return(squid_bridge3(players, n + 1, prob, previous = 1))
}
if (!not_stupid()) {
return(squid_bridge3(players - 1, n, prob, previous = 1))
}
jump <- rbinom(1, 1, prob)
if (jump == 0) {
# Player died because of either choosing wrong or a self-inflicted loss
return(squid_bridge3(players - 1, n, prob, previous = 0))
}
if (jump == 1 & n < 18) {
# Move is correct. Advance 1 space
return(squid_bridge3(players, n + 1, prob, previous = 1))
}
}
然后运行一些模拟:
set.seed(123)
trials <- 10000
players <- 16
squid1 <- replicate(trials, squid_bridge1(players, 0, 0.5))
squid2 <- replicate(trials, squid_bridge2(players, 0, 0.5, 1))
squid3 <- replicate(trials, squid_bridge3(16, 0, 0.5, 1))
df <- tibble(squid1 = squid1,
squid2 = squid2,
squid3 = squid3) %>%
pivot_longer(cols = c(squid1, squid2, squid3))
ggplot(data = df,
aes(x = value)) +
geom_histogram(bins = 10,
binwidth = 1,
fill = "cornflowerblue",
color = "black") +
facet_wrap(~name,
nrow = 3) +
xlab("# of players to make it to the end") +
scale_x_continuous(breaks = seq(0, 16, by = 1),
labels = seq(0, 16, by = 1))
正如您在下面看到的,第一种情况严重偏左。由于玩家基本上是在“盲目地猜测”每一块牌,因此任何人都不太可能走到最后。然而,在考虑了从错误猜测中获得的信息后,平均大约有 7 名玩家成功。通过添加由于另一个原因而随机下降的机会,分布会向左倾斜一些。
- 第一种情况的平均值:1.45
- 第二种情况的平均值:7.01
- 第三种情况平均值:4.99
要回答只有3 名玩家成功的概率问题,我在最后一种情况下得到 ~ 10.8%
编辑:根据要求,这是生成图的代码。我还修复了存在一些命名问题的各种函数(在我创建它们时使用了几个不同的名称)。看起来它导致了第三个函数的一个小错误,但我已经修复了它。