D
D
DALVROT2021-01-18 14:24:58
Mathematics
DALVROT, 2021-01-18 14:24:58

Blackjack, combination probability, how to calculate?

Wrote a code for calculating the probability of a card falling out in blackjack, based on the cards that came out in the game. I want to calculate the probability of the dealer's amount. I created all possible combinations (1800) pieces, the dealer is given one card, and after all the participants in the game have stopped in the selection of cards, the dealer selects cards until the amount is >= 17. I do this: I select all combinations that contain the dealer's card, and multiply all the chances of the cards in this combination. But in sum, all the chances of 17,18,19,20,21 and busting do not give 100%. Tell me if I'm doing it right, or how to do it right. Can it be calculated at all? Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2021-01-18
@DALVROT

You have a problem, it seems that different combinations can be obtained with different probabilities.
Let's say 19 = 2+2+5+5+5. But you can also rearrange the cards in places. After all, the dealer could get 5, then the second 5, then 2, then 2, then 5. And the fives themselves could come 3! ways. However, you can't bet 2 last because the sum of the first four cards is already 17. The dealer wouldn't draw this last 2.
But 19=3+3+4+4+5 can already be chosen by all 5! different ways. Therefore, these 2 combinations, although they give the same amount and contain the same number of cards, can be obtained with different probabilities.
Correct solution using dynamic programming:
First, iterate over which card will be drawn last. Find the probabilities of all sums given this card (so that it exceeds the sum of 17, but not the previous one). Then sum over all such cards.
Eliminate this last card from the deck. Now we need to find how many sets of cards of a given length give each sum < 17. In this case, when calculating the probability, you can rearrange all these cards as you like. Therefore, it matters how many cards we used for the amount.
Now consider dynamic programming - in how many ways can you choose n cards from the first k, getting the sum s (the order is not important).
When counting, you have 2 options - the last of k cards is either included or not in the sum (let's say the array a[] stores the weights of the cards).
Those. F(n,k,s) = F(n,k-1,s)+F(n-1,k-1,sa[k]).
Base:
F(0, k, s) = 1 if s==0; 0 otherwise
F(n,0,s) = 1 if n==0 and s==0; 0 otherwise.
F(n, k, s<0) = 0
You can save on memory and count in a two-dimensional array from the end to the beginning, throwing out k (the second parameter).
Then the desired probability to score the sum xc with the last card l, if there are max_k cards left in the deck (if x<17+l, x>=17, otherwise the probability is 0):
P(x) = sum_{n=1..max_k} f (n, max_k, xl) * n! * (max_k-n)! / (max_k+1)!
There is a search for all possible numbers of cards from the dealer. Next, we take the number of ways to collect the required amount from the DP. Then we multiply by n!, because these cards in the dealer's hand could come in any order. Then we multiply by the probability of drawing specific n+1 cards (counting the last one) from a deck with max_k+1 cards. It's 1/(max_k+1)/max_k/,,,/(max_k-n+1) = (max_k-n)!/(max_k+1)!
This factor after f() can be recalculated in one multiplication and division
as n increases.
I remind you that this must be summed over all possible cards taken for l, again driving the DP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question