Dealer Probabilities
In this post I derive the probabilities of each dealer outcome. Our ultimate goal is to be able to mathematically derive Basic Strategy. The first step is to fully describe the outcomes of the dealer.
Rules of the Dealer
The actions of the dealer are pre-determined, meaning the dealer is just a robot following an algorithm. They do not get to make a choice.
def get_dealer_action(hand, hit_on_soft_17):
if hand.total() <= 16:
return "HIT"
elif hit_on_soft_17 and hand.total() == 17 and hand.is_soft():
return "HIT"
else:
return "STAND"
Recall that Aces in BlackJack can be used as either a value of $1$ or $11$. A soft hand refers to a hand that uses an Ace as a value of $11$. For example, the hand $A$, $6$ is a soft 17. There are two standard variants of the BlackJack rules
- H17: dealer will HIT on a soft $17$
- S17: dealer will STAND on a soft $17$
S17 is known to be slightly more advantageous for the player. The parameter hit_on_soft_17 is a boolean variable that represents a standard variant of BlackJack.
Computing the Dealer’s Probabilities
Random Variable Definitions
Define the following discrete random variables.
- Let \(F \in \{ 17, 18, 19, 20, 21, \text{BUST} \}\) be the random variable denoting the final total of the dealer.
- Let \(I \in \{ 0, 1, 2, \ldots, 20, 21, \text{BUST} \}\) be the random variable denoting some intermediary total of the dealer.
- Let \(H \in \{ \text{HARD}, \text{SOFT} \}\) be the random variable denoting the type of the dealer’s hand.
- Let \(C \in \{ A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K \}\) be the random variable denoting drawing a card from the deck.
Let me further clarify the above definitions with an example. Suppose the dealer has $A$, $5$. This gives an intermediate total of $I = 16$ since the Ace is used as an $11$. This also means that this is a soft hand ($H = \text{SOFT}$). As per the dealer’s procedure, they must take another card. Suppose they draw a $C = J$. The dealer’s intermediate total is now still $I = 16$ (since a $J$ is worth $10$), but it is a hard hand ($H = \text{HARD}$). As per the dealer’s procedure, they again must take another card. Suppose they draw a $C = 4$. Then the dealer’s total is now $I = F = 20$. As per the rules, this is the dealer’s final total.
Probability Mass Function Definitions
Consider the following probability definitions. \(\quad\bullet\quad P[C = c] \equiv \text{the probability of drawing card } c \text{ from the deck} \\[10pt] \begin{align} \quad\bullet\quad P[F = f \mid I = i, H = h] \equiv &\text{ the probability that the dealer obtains a final total of } f \\[1pt] &\text{ given they have an intermediary total of } i \text{ of hand type } h \end{align} \\[15pt]\) \(\begin{align} \quad\bullet\quad P[F = f \mid I = i, H = h, C = c] \equiv &\text{ the probability that the dealer obtains a final total of } f \\[1pt] &\text{ given they have an intermediary total of } i \text{ of hand type } h \\[1pt] &\text{ and have drawn the card } c \text{ from the deck} \end{align}\)
However, the more common notation is to express these are probability mass functions (PMFs). \(\begin{align} &\quad\bullet\quad p(c) \equiv p_{C}(c) \equiv P[C = c] \\[10pt] &\quad\bullet\quad p(f \mid i, h) \equiv p_{F \mid I, H}(f \mid i, h) \equiv P[F = f \mid I = i, H = h] \\[10pt] &\quad\bullet\quad p(f \mid i, h, c) \equiv p_{F \mid I, H, C}(f \mid i, h, c) \equiv P[F = f \mid I = i, H = h, C = c] \end{align}\)
Notice that we are overloading the function $p(\cdot)$ with three completely different functions, which are only differentiated via their arguments. This is standard notation in probability. If this bothers you, you can choose to always include the subscripts to the function (e.g. $\ p_{F \mid I, H}(f \mid i, h)$). However, I find this too noisy and the variables quickly become unwieldy. Thus, I will stick to standard notation.
Probability Recurrence
Our goal is to fully compute the PMF $p(f \mid i, h)$. First, consider the boundary conditions which are induced from the BlackJack rules.
- By definition, an intermediary total cannot exceed the final total
- By definition, a hard hand totaling $1$ is not possible (a single ace is considered a soft $11$)
- By definition, a soft hand totaling less than $11$ is not possible
- Dealer always hits on a total of $16$ or less
- Dealer always stands on $18$ or more
- Dealer always stands on a hard $17$
- Whether a dealer hits on a soft $17$ depends on the BlackJack variant
For the generic case, we use the law of total probability \(\displaystyle P[A = a] = \sum_n P[A = a, B = b_n] = \sum_n P[A = a \mid B = b_n] \, P[B = b_n]\) , which models drawing a random card from the deck and adding it to our intermediary total. Putting it all together gives the following definition.
\[p(f \mid i, h) = \begin{cases} 0 &\quad\text{if } i = 1 \text{ and } h = \text{HARD} \\[10pt] 0 &\quad\text{if } i < 11 \text{ and } h = \text{SOFT} \\[10pt] 0 &\quad\text{if } f < i \\[10pt] 1 &\quad\text{if } 18 \leq i \leq 21 \text{ and } i = f \\[10pt] 1 &\quad\text{if } i = f = \text{BUST} \\[10pt] 1 &\quad\text{if } i = 17 \text{ and } i = f \text{ and } h = \text{HARD} \\[10pt] 1 &\quad\text{if } i = 17 \text{ and } i = f \text{ and } h = \text{SOFT} \text{ and } (\text{dealer stays on soft } 17) \\[10pt] \displaystyle \sum_{c \in C} p(f \mid i, h, c) \, p(c) &\quad\text{otherwise } \end{cases}\]The above is simpler than it looks. The top seven lines are just the mathematical representation of the boundary conditions listed above. The last line is just the mathematical representation of drawing a random card from the deck.
Continuing, we can recursively relate $p(f \mid i, h, c)$ to $p(f \mid i, h)$ using the rules of BlackJack. First, we need to define the value of each BlackJack card.
\[v(c) = \begin{cases} 1 &\quad\text{if } c = A \\[5pt] c &\quad\text{if } c \in \{ 2, 3, 4, 5, 6, 7, 8, 9 \} \\[5pt] 10 &\quad\text{if } c \in \{ T, J, Q, K \} \end{cases}\]It’s easiest to deal with the cases of hard and soft hands separately.
\[p(f \mid i, \text{HARD}, c) = \begin{cases} p(f \mid \text{BUST}, \text{HARD}) &\quad\text{if } i + v(c) > 21 \\[10pt] p(f \mid i + 11, \text{SOFT}) &\quad\text{if } i \leq 10 \text{ and } c = A \\[10pt] p(f \mid i + v(c), \text{HARD}) &\quad\text{otherwise} \end{cases}\]Similarly for soft hands.
\[p(f \mid i, \text{SOFT}, c) = \begin{cases} p(f \mid i + v(c), \text{SOFT}) &\quad\text{if } i+v(c) \leq 21 \\[10pt] p(f \mid i + v(c) - 10, \text{HARD}) &\quad\text{if } i+v(c) > 21 \end{cases}\]Dynamic Programming
Since we have a very recursive definition of $p(f \mid i, h)$, it can be efficiently computed using dynamic programming. I am using a bottom-up approach where I first compute smaller subproblems and combine them to compute the larger subproblems. The order we compute is the following
- Hard hands $\geq 11$: since these will remain hard hands $\geq 11$ no matter what card is drawn.
- All soft hands: since if a small card is drawn it may remain soft, but if a larger card is drawn it will become a hard hand $\geq 11$.
- Hard hands $< 11$: since depending on what card is drawn they fall into any of these categories.
The Python code is given below.
import numpy as np
def dealer_probabilities(hit_on_soft_17):
# Initialization
H = np.zeros((23, 23)) # H[i, f] = p(f | i, hard)
S = np.zeros((22, 23)) # S[i, f] = p(f | i, soft)
C = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 4]) / 13 # C[c-1] = p(c)
# As simplification we don't distinguish between {T, J, Q, K}
# we treat them as the same card that can occur 4 times
# now the card value is the index of its PMF value
# Base Cases
for f in range(17, 23):
H[f, f] = 1
for f in range(18, 22):
S[f, f] = 1
if not hit_on_soft_17:
S[17, 17] = 1
# Hard hands >= 11
for i in reversed(range(11, 17)):
for f in range(17, 23):
for c in range(1, 11):
H[i, f] += H[min(i+c, 22), f] * C[c-1]
# Soft hands
# Note: a soft hand of 11 means the dealer is showing just an Ace
soft_hand_stand = 18 if hit_on_soft_17 else 17
for i in reversed(range(11, soft_hand_stand)):
for f in range(17, 23):
for c in range(1, 11):
if i+c <= 21:
S[i, f] += S[i+c, f] * C[c-1]
else:
S[i, f] += H[i+c-10, f] * C[c-1]
# Hard hands < 11 (dealer showing a single card that is not an Ace)
# Note: a hard hard of 0 represents p(f | 0) = p(f), i.e. the prior probabilities of the dealer's final hand
for i in reversed(range(0, 11)):
if i == 1:
continue # Hand hand = 1 is impossible
for f in range(17, 23):
H[i, f] += S[i+11, f] * C[0] # different case for an Ace
for c in range(2, 11):
H[i, f] += H[i+c, f] * C[c-1]
return H, S
Dealer Probability Tables
Below I show the table dealer probabilities for both rule-sets. In each table, the rows represent the dealer’s current hand ($I$), and the columns represent the possible dealer final hand ($F$). The cell values give the probability of the dealer obtaining the future hand, given its current hand ($p(f \mid i, h)$). Cells which are empty have probability $0$.
A particularly interesting row is the bottom row of the hard hands, representing $p(f \mid 0, \text{HARD})$. This is the apriori probability of each dealer outcome. Another interesting column is the bust column representing $p(\text{BUST} \mid i, h)$. For hard-hands between 2 and 6, this represents the probability that the dealer busts given their up-card. We now see why the dealer showing $5$ and $6$ are so advantageous to the player.
Dealer Hits on Soft 17 (H17)
Hard Hands:
| 17 | 18 | 19 | 20 | 21 | bust | |
|---|---|---|---|---|---|---|
| bust | 1.0000 | |||||
| 21 | 1.0000 | |||||
| 20 | 1.0000 | |||||
| 19 | 1.0000 | |||||
| 18 | 1.0000 | |||||
| 17 | 1.0000 | |||||
| 16 | 0.0769 | 0.0769 | 0.0769 | 0.0769 | 0.0769 | 0.6154 |
| 15 | 0.0828 | 0.0828 | 0.0828 | 0.0828 | 0.0828 | 0.5858 |
| 14 | 0.0892 | 0.0892 | 0.0892 | 0.0892 | 0.0892 | 0.5539 |
| 13 | 0.0961 | 0.0961 | 0.0961 | 0.0961 | 0.0961 | 0.5196 |
| 12 | 0.1035 | 0.1035 | 0.1035 | 0.1035 | 0.1035 | 0.4827 |
| 11 | 0.1114 | 0.1114 | 0.1114 | 0.1114 | 0.3422 | 0.2121 |
| 10 | 0.1114 | 0.1114 | 0.1114 | 0.3422 | 0.1114 | 0.2121 |
| 9 | 0.1200 | 0.1200 | 0.3508 | 0.1200 | 0.0608 | 0.2284 |
| 8 | 0.1286 | 0.3593 | 0.1286 | 0.0694 | 0.0694 | 0.2447 |
| 7 | 0.3686 | 0.1378 | 0.0786 | 0.0786 | 0.0741 | 0.2623 |
| 6 | 0.1148 | 0.1148 | 0.1148 | 0.1103 | 0.1057 | 0.4395 |
| 5 | 0.1184 | 0.1229 | 0.1184 | 0.1138 | 0.1089 | 0.4177 |
| 4 | 0.1224 | 0.1273 | 0.1228 | 0.1179 | 0.1126 | 0.3971 |
| 3 | 0.1263 | 0.1320 | 0.1271 | 0.1218 | 0.1162 | 0.3767 |
| 2 | 0.1301 | 0.1365 | 0.1313 | 0.1257 | 0.1196 | 0.3567 |
| 1 | ||||||
| 0 | 0.1333 | 0.1415 | 0.1355 | 0.1823 | 0.1221 | 0.2854 |
Soft Hands:
| 17 | 18 | 19 | 20 | 21 | bust | |
|---|---|---|---|---|---|---|
| 21 | 1.0000 | |||||
| 20 | 1.0000 | |||||
| 19 | 1.0000 | |||||
| 18 | 1.0000 | |||||
| 17 | 0.3422 | 0.1114 | 0.1114 | 0.1114 | 0.1114 | 0.2121 |
| 16 | 0.0786 | 0.1377 | 0.1377 | 0.1377 | 0.1377 | 0.3704 |
| 15 | 0.0801 | 0.1438 | 0.1438 | 0.1438 | 0.1438 | 0.3448 |
| 14 | 0.0813 | 0.1500 | 0.1500 | 0.1500 | 0.1500 | 0.3189 |
| 13 | 0.0823 | 0.1562 | 0.1562 | 0.1562 | 0.1562 | 0.2929 |
| 12 | 0.0829 | 0.1625 | 0.1625 | 0.1625 | 0.1625 | 0.2669 |
| 11 | 0.0575 | 0.1432 | 0.1432 | 0.1432 | 0.3740 | 0.1389 |
Dealer Stands on Soft 17 (S17)
Hard Hands:
| 17 | 18 | 19 | 20 | 21 | bust | |
|---|---|---|---|---|---|---|
| bust | 1.0000 | |||||
| 21 | 1.0000 | |||||
| 20 | 1.0000 | |||||
| 19 | 1.0000 | |||||
| 18 | 1.0000 | |||||
| 17 | 1.0000 | |||||
| 16 | 0.0769 | 0.0769 | 0.0769 | 0.0769 | 0.0769 | 0.6154 |
| 15 | 0.0828 | 0.0828 | 0.0828 | 0.0828 | 0.0828 | 0.5858 |
| 14 | 0.0892 | 0.0892 | 0.0892 | 0.0892 | 0.0892 | 0.5539 |
| 13 | 0.0961 | 0.0961 | 0.0961 | 0.0961 | 0.0961 | 0.5196 |
| 12 | 0.1035 | 0.1035 | 0.1035 | 0.1035 | 0.1035 | 0.4827 |
| 11 | 0.1114 | 0.1114 | 0.1114 | 0.1114 | 0.3422 | 0.2121 |
| 10 | 0.1114 | 0.1114 | 0.1114 | 0.3422 | 0.1114 | 0.2121 |
| 9 | 0.1200 | 0.1200 | 0.3508 | 0.1200 | 0.0608 | 0.2284 |
| 8 | 0.1286 | 0.3593 | 0.1286 | 0.0694 | 0.0694 | 0.2447 |
| 7 | 0.3686 | 0.1378 | 0.0786 | 0.0786 | 0.0741 | 0.2623 |
| 6 | 0.1654 | 0.1063 | 0.1063 | 0.1017 | 0.0972 | 0.4232 |
| 5 | 0.1223 | 0.1223 | 0.1177 | 0.1131 | 0.1082 | 0.4164 |
| 4 | 0.1305 | 0.1259 | 0.1214 | 0.1165 | 0.1112 | 0.3945 |
| 3 | 0.1350 | 0.1305 | 0.1256 | 0.1203 | 0.1147 | 0.3739 |
| 2 | 0.1398 | 0.1349 | 0.1297 | 0.1240 | 0.1180 | 0.3536 |
| 1 | ||||||
| 0 | 0.1451 | 0.1395 | 0.1335 | 0.1803 | 0.1201 | 0.2816 |
Soft Hands:
| 17 | 18 | 19 | 20 | 21 | bust | |
|---|---|---|---|---|---|---|
| 21 | 1.0000 | |||||
| 20 | 1.0000 | |||||
| 19 | 1.0000 | |||||
| 18 | 1.0000 | |||||
| 17 | 1.0000 | |||||
| 16 | 0.1292 | 0.1292 | 0.1292 | 0.1292 | 0.1292 | 0.3541 |
| 15 | 0.1346 | 0.1346 | 0.1346 | 0.1346 | 0.1346 | 0.3272 |
| 14 | 0.1400 | 0.1400 | 0.1400 | 0.1400 | 0.1400 | 0.3000 |
| 13 | 0.1455 | 0.1455 | 0.1455 | 0.1455 | 0.1455 | 0.2725 |
| 12 | 0.1510 | 0.1510 | 0.1510 | 0.1510 | 0.1510 | 0.2450 |
| 11 | 0.1308 | 0.1308 | 0.1308 | 0.1308 | 0.3616 | 0.1153 |