Riddler Express
Youβre playing a game of cornhole with your friends, and itβs your turn to toss the four bean bags. For every bean bag you toss onto your opponentsβ board, you get point. For every bag that goes through the hole on their board, you get points. And for any bags that donβt land on the board or through the hole, you get points.
Your opponents had a terrible round, missing the board with all their throws. Meanwhile, your team currently has points β just points away from victory at . Youβre also playing with a special house rule: To win, you must score exactly points, without going over.
Based on your history, you know there are three kinds of throws you can make:
- An aggressive throw, which has a percent chance of going in the hole, a percent chance of landing on the board and a percent chance of missing the board and hole.
- A conservative throw, which has a 10 percent chance of going in the hole, an percent chance of landing on the board and a percent chance of missing the board and hole.
- A wasted throw, which has a percent chance of missing the board and hole.
For each bean bag, you can choose any of these three throws. Your goal is to maximize your chances of scoring exactly points with your four tosses. What is the probability that your team will finish the round with exactly points and declare victory?
Solution
Let us consider the general case of an -throw game, and let the state be the number of points. The optimal probability at the start of the throw as a function of the number of points is given by the dynamic programming recursion
where and are the probabilities of a throw landing in the hole, on the board and missing the board under aggressive and conservative throws.
The maximum above is taken over the three possible decisions:
-
Aggressive throw, which keeps the score at with probability , changes it to with probability and with probability .
-
Conservative throw, which keeps the score at with probability , changes it to with probability and with probability .
-
Wasted throw, which keeps the score at with probability .
The required probability is obtained by calculating given and the following terminal conditions:
From the code below, the probability that the team will finish the round with exactly points and declare victory is .
Computation
N, max_pts = 4, 3
P = zeros(Float32, N, N*max_pts+1)
P[N,1], P[N,3], P[N,4] = 0.4, 0.8, 1
aβ, aᡦ, aβ = 0.4, 0.3, 0.3
cβ, cᡦ, cβ = 0.1, 0.8, 0.1
for k in N-1: -1 :1
for x in 1:k*max_pts+1
P[k,x] = max(aβ*P[k+1,x+3]+aᡦ*P[k+1,x+1]+aβ*P[k+1,x],
cβ*P[k+1,x+3]+cᡦ*P[k+1,x+1]+cβ*P[k+1,x],
P[k+1,x])
end
end
print(P[1,1])