0
votes

I am trying to write a mathematical function for calculating the probability of winning or loosing the player.

Assume that we play blackjack with only one deck(52 cards) and the first example hand is like that :

The player has `7 and 5`
Dealer has `6`

Here I need the calculate if player stands, what is the probibility of dealers win?

The dealer can win if the total cards value are 17 <= x <= 21

I can calculate this with code like this but this is very inefficient for 6 decks.

def subset_sum(numbers, target, target2, partial=[]):
    s = sum(partial)
    # check if the partial sum is equals to target
    if s >= target and s <= target2: 
         print partial
    if s >= target:
         return  # if we reach the number why bother to continue
    for i in range(len(numbers)):
        n = numbers[i]
        remaining = numbers[i+1:]
        subset_sum(remaining, target, target2, partial + [n])

I am searching for a mathematical function which calculates the probability and return it.

def get_prob(deck, small_number, big_number):

return prob

In our example, dealer has 6 so small number will be 17-6=11 and big number is 21-6=15.

5,6,7 are used in first hand so my deck has now like this :

dec = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]

With these numbers, dealer has 6 so small number is 17-6 = 11 and 21-6 = 15

def get_prob(dec,11,15):

return prob

Problem: what is the probability that the sum of the cards will be between 11 and 15 ?

1
possibility of the combinations (maybe only unique)? - dsgdfg
Sure, only the unique's. [6,5] and [5,6] is same thing. It should not be sum twice @SDilmac - Batuhan B
I'm voting to close this question as off-topic because it asks for a mathematical probability function. This would be better suited for math SE. - DPenner1

1 Answers

0
votes

As I posted in my last answer to one of your Blackjack questions, this is not algorithmically necessary for your specific setup, as I understand it in your previous question.

This is a simple application of permutations. However, since there is no way of predicting the probability of still standing after the next deal, it is not meaningful to calculate that far ahead, since the player will not be able to influence the outcome given any depth. It is computationally simpler to calculate the probability one at a time.

If you have a deck:

deck = [1,1,1,1,2,2,2,3,3...]

it is possible to get the probabilities of ending up with a sum in a range using:

def get_prob(deck, minimum, maximum):
  counts = [deck.count(i) for i in range(14)]
  return sum(counts[minimum:maximum+1])/len(counts)

Simply, this function, given a deck and a range of the acceptable card values, will return a probability of a card being drawn within those thresholds.

Also, if the minimum value is 11, as an example, not counting aces, it is not necessary to use this function, as a draw needs to happen regardless.