Simulering av äppelspelet för Stockholm Bayes ClubApple Game Simulation for Stockholm Bayes Club

← Tillbaka till resurser← Back to Resources

Spelregler Game rules

I det här spelet tävlar du mot farmor. Farmor går längs en stig från start till mål, medan du försöker samla så många äpplen som möjligt innan hon kommer fram.

I varje omgång kastar man en vanlig sexsidig tärning:

  • Om det blir 1, 2 eller 6 flyttar farmor fram lika många steg.
  • Om det blir 3, 4 eller 5 samlar du i stället lika många äpplen.

Det finns två specialrutor på stigen:

  • Om farmor hamnar på 9 tar hon en genväg och flyttar direkt till 14.
  • Om farmor hamnar på 18 måste hon stå över nästa tur.

Spelet slutar så fort farmor når eller passerar ruta 21. Då avbryts omgången direkt, och antalet äpplen du har samlat är ditt slutresultat.

In this game you compete against grandma. Grandma moves along a path from start to finish, while you try to collect as many apples as possible before she reaches the end.

Each round a six-sided die is rolled:

  • If the result is 1, 2, or 6, grandma moves forward that many spaces.
  • If the result is 3, 4, or 5, you collect that many apples instead.

There are two special squares on the path:

  • If grandma lands on 9, she takes a shortcut and moves directly to 14.
  • If grandma lands on 18, she must skip her next turn.

The game ends as soon as grandma reaches or passes square 21. At that moment the round stops immediately, and the number of apples you have collected is your final score.

Testa en omgång Try one game


Fördelning från 10 000 simulerade spel Distribution from 10,000 simulated games

Visa kod
library(ggplot2)

simulate_game <- function() {
  pos <- 0
  apples <- 0
  skip <- FALSE

  while (pos < 21) {

    if (skip) {
      skip <- FALSE
      next
    }

    roll <- sample(1:6, 1)

    if (roll %in% c(1,2,6)) {
      pos <- pos + roll

      if (pos == 9) pos <- 14
      if (pos >= 21) break
      if (pos == 18) skip <- TRUE

    } else {
      apples <- apples + roll
    }
  }

  apples
}

set.seed(123)

n_sim <- 10000
results <- replicate(n_sim, simulate_game())

df <- data.frame(apples = results)

ggplot(df, aes(x = apples)) +
  geom_histogram(
    binwidth = 1,
    boundary = -0.5,
    fill = "#E1635B",
    color = "white"
  ) +
  scale_x_continuous(breaks = seq(0, max(df$apples), by = 5)) +
  scale_y_continuous(
    breaks = scales::pretty_breaks(n = 6),
    labels = scales::comma
  ) +
  labs(
    title = "Distribution of Apples Collected",
    subtitle = "10,000 simulated games",
    x = "Apples collected",
    y = "Number of games"
  ) +
  theme_bw() +
  theme(panel.grid.minor = element_blank())

Uppskattad sannolikhet att vinna spelet med 10, 20 och 30 äpplen Estimated probability of winning the game for 10, 20, 30 apples

Visa kod
library(scales)

p10 <- percent(mean(results >= 10))
p20 <- percent(mean(results >= 20))
p30 <- percent(mean(results >= 30))

cat(
  " ≥10 apples:", p10,"\n",
  "≥20 apples:", p20,"\n",
  "≥30 apples:", p30
)
 ≥10 apples: 88% 
 ≥20 apples: 65% 
 ≥30 apples: 41%

← Tillbaka till resurser← Back to Resources