Gambler’s Ruin
Consider a gambler who starts with an initial fortune of $1. On each successive gamble, the gambler either wins $1 or loses $1 independently of previous outcomes, with probabilities \(p\) and \(q = 1 - p\), respectively.
Suppose the gambler begins with a kitty of $A and places bets against a “Banker” who has an initial fortune of $B. The game is viewed from the gambler’s perspective. By convention, the Banker is the wealthier of the two.
Key parameters:
- Probability of a successful gamble: \(p\)
- Probability of an unsuccessful gamble: \(q
= 1 - p\)
- Success-to-failure ratio: \(s =
\frac{p}{q}\)
- Typically, the game is biased in favor of the Banker (i.e., \(q > p\), so \(s < 1\))
Let \(R_n\) denote the gambler’s total fortune after the \(n^\text{th}\) gamble.
- If the gambler wins the first game: \(R_1
= A + 1\)
- If the gambler loses the first game: \(R_1 = A - 1\)
The total amount at stake is the Jackpot, \(A + B\). The game ends when the gambler
either: - Wins the entire jackpot: \(R_n = A +
B\)
- Loses everything: \(R_n = 0\)
Simulating a Single Gamble
To simulate one bet, generate a random number between 0 and 1:
## [1] 0.5262137
Assuming the game is biased in favor of the Banker:
If the random number is less than 0.45, the gambler wins; otherwise, the Banker wins.
Example outcomes:
runif(1) # [1] 0.1251274 → Gambler wins
runif(1) # [1] 0.754075 → Banker wins
runif(1) # [1] 0.2132148 → Gambler wins
runif(1) # [1] 0.8306269 → Banker wins
Tracking the Gambler’s Fortune Over Time
Let \(A\) be the initial kitty, and \(B\) be the Banker’s wealth. We’ll keep track of the gambler’s fortune using a vector \(R_n\):
A <- 20
B <- 100
p <- 0.47
Rn <- c(A)
probval <- runif(1)
if (probval < p) {
A <- A + 1
B <- B - 1
} else {
A <- A - 1
B <- B + 1
}
Rn <- c(Rn, A)
Simulating Until the Game Ends
The loop below runs until the gambler either loses all his money or
wins the entire jackpot. A break
statement ends the game if
the gambler wins:
A <- 20
B <- 100
p <- 0.47
Rn <- c(A)
Total <- A + B
while (A > 0) {
UnifVal <- runif(1)
if (UnifVal <= p) {
A <- A + 1
B <- B - 1
} else {
A <- A - 1
B <- B + 1
}
Rn <- c(Rn, A)
if (A == Total) break
}
Simulating Multiple Games to Examine Duration
We can simulate many games and record how long each lasts (i.e. how many rounds until the gambler goes broke or wins the jackpot):
A.ini <- 20
B <- 100
p <- 0.47
M <- 1000
RnDist <- numeric()
Total <- A.ini + B
for (i in 1:M) {
A <- A.ini
Rn <- numeric()
Rn[1] <- A
while (A > 0) {
UnifVal <- runif(1)
if (UnifVal <= p) {
A <- A + 1
B <- B - 1
} else {
A <- A - 1
B <- B + 1
}
Rn <- c(Rn, A)
if (A == Total) break
}
RnDist <- c(RnDist, length(Rn))
}
Distribution of Game Durations
Now you can analyze or plot RnDist
to explore the
distribution of game durations—i.e., how many rounds typical games last
before ending.