I am implementing a blackjack game with minimax tree which calculates the probabilities and play automatically depend on this probabilities.
Assume that, we play with 1 deck and the first game dealer takes : '5' and player takes '5 7' so the total score is 12 for player.
In this case, first I am trying to check all possible probabilities for player's stand decision.
If player stands :
My remain cards in deck like this : Structure of deck(K,V) K : card number, V: count of card
{1: 4, 2: 4, 3: 4, 4: 4, 5: 2, 6: 4, 7: 3, 8: 4, 9: 4, 10: 16}
Now, dealer should pass the number 17. Some examples can be like this :
5(base card) + 1(11) + 1 = 17 (possibility of this hand : 4/49 * 3/48)
5(base card) + 1(11) + 2 = 18 (possibility of this hand : 4/49 * 4/48)
......
5 (base card) + 10 + 1 + 1 = 17 (possibility of this hand : 16/49 * 4/48 * 3/48)
My question is, how can I calculate all this possibilities and calculate the final possibility of if player decision is standing. I cannot figure out how can I coded these combination of numbers.
EDIT :
I found out this code which calculate the possible combinations. It is similar what I look like. I need to change this for my problem, I hope I can do it.
def subset_sum(numbers, target, partial=[]):
s = sum(partial)
# check if the partial sum is equals to target
if s == target:
print "sum(%s)=%s" % (partial, target)
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, partial + [n])
if __name__ == "__main__":
subset_sum([3,9,8,4,5,7,10],15)
#Outputs:
#sum([3, 8, 4])=15
#sum([3, 5, 7])=15
#sum([8, 7])=15
#sum([5, 10])=15