Blackjack
I'm working on writing a program to solve for finding the optimal strategy in blackjack. Supposedly this is simply the basic strategy. I can measure my success by how close it is to the basic strategy. If I get the basic strategy exactly, then I can safely assume my methods will work for when I calculate the strategies for when the true count is +1, -1, etc.
The true count is the count divided by the number of decks left. In single deck, with half a deck left, that means multiply the count by two. In six deck, two decks in (usually after about six hands or so at a full table), that means divide by four.
Anyways, the math I need to do is calculate the expected value for every possible action of every possible situation (this is why I'm using a computer). I already have an algorithm for calculating the dealer's odds of ending up with a 17-21 or bust for a given count. Now I need some kind of dynamic solution to solve for the player's expectation based on these odds.
If a dealer's odds of having 17, 18, 19, 20, 21, bust are .11, .12, .13, .14, .15, .35, respectively (based on some face up card), and the count is 0 (each card has an equal probability), then how do we play a 13? (These numbers are totally fictitious, so this does not necessarily apply to real blackjack.) It actually depends already on the strategy defined for playing a 21, 20, 19, 18, 17, 16, 15, and 14. Since, in order to calculate our EV of hitting, we need to know the optimal strategy of all those hands, for when we get an ace, 2, 3, 4, 5, 6, 7, or 8.
So, in order to better understand how to write the dynamic programming version, I guess I should just solve a simple case, as illustrated above. Solve for 21. Put that strategy into the array. Solve for 20. Into the array. But now, do I solve for soft 20, or hard 19? Obviously these strategies are trivial, but lets say soft 17 vs. hard 16. Okay, hard 16 never becomes a soft 17, so solve for hard 10-20, and then soft 20, then hard 9, then soft 19. Since a hard 9 never becomes a soft 19, but a hard 8 sometimes does, this is a possible order. Another order is solve hard 21-12, then soft 20. Since an 11 never becomes a soft 20, and a soft 20 never becomes an 11, this is fine. A soft 20 does become a hard 12 sometimes, so we must solve hard 12 before soft 20. But only hard 9 becomes a soft 20. So we have options to solve for soft 20 between solving for hard 12 and hard 9. So just based on points, hard or soft, we have an array that is ordered something like this:
This is of course not including pairs. Since the only way to have a 4 is with two 2's, I need to add them to this array somewhere, but where? Last I guess. Just tag them on to the end. A soft 15 will never become a pair of 4s, so these strategies can be solved last, and use the previous solutions in the array.
Yay! I've created my dynamic blackjack algorithm. Algorithmics is a very mathematical part of computer science. Since I was working on this, I just thought you might enjoy it.
I'm working on writing a program to solve for finding the optimal strategy in blackjack. Supposedly this is simply the basic strategy. I can measure my success by how close it is to the basic strategy. If I get the basic strategy exactly, then I can safely assume my methods will work for when I calculate the strategies for when the true count is +1, -1, etc.
The true count is the count divided by the number of decks left. In single deck, with half a deck left, that means multiply the count by two. In six deck, two decks in (usually after about six hands or so at a full table), that means divide by four.
Anyways, the math I need to do is calculate the expected value for every possible action of every possible situation (this is why I'm using a computer). I already have an algorithm for calculating the dealer's odds of ending up with a 17-21 or bust for a given count. Now I need some kind of dynamic solution to solve for the player's expectation based on these odds.
If a dealer's odds of having 17, 18, 19, 20, 21, bust are .11, .12, .13, .14, .15, .35, respectively (based on some face up card), and the count is 0 (each card has an equal probability), then how do we play a 13? (These numbers are totally fictitious, so this does not necessarily apply to real blackjack.) It actually depends already on the strategy defined for playing a 21, 20, 19, 18, 17, 16, 15, and 14. Since, in order to calculate our EV of hitting, we need to know the optimal strategy of all those hands, for when we get an ace, 2, 3, 4, 5, 6, 7, or 8.
So, in order to better understand how to write the dynamic programming version, I guess I should just solve a simple case, as illustrated above. Solve for 21. Put that strategy into the array. Solve for 20. Into the array. But now, do I solve for soft 20, or hard 19? Obviously these strategies are trivial, but lets say soft 17 vs. hard 16. Okay, hard 16 never becomes a soft 17, so solve for hard 10-20, and then soft 20, then hard 9, then soft 19. Since a hard 9 never becomes a soft 19, but a hard 8 sometimes does, this is a possible order. Another order is solve hard 21-12, then soft 20. Since an 11 never becomes a soft 20, and a soft 20 never becomes an 11, this is fine. A soft 20 does become a hard 12 sometimes, so we must solve hard 12 before soft 20. But only hard 9 becomes a soft 20. So we have options to solve for soft 20 between solving for hard 12 and hard 9. So just based on points, hard or soft, we have an array that is ordered something like this:
This is of course not including pairs. Since the only way to have a 4 is with two 2's, I need to add them to this array somewhere, but where? Last I guess. Just tag them on to the end. A soft 15 will never become a pair of 4s, so these strategies can be solved last, and use the previous solutions in the array.Yay! I've created my dynamic blackjack algorithm. Algorithmics is a very mathematical part of computer science. Since I was working on this, I just thought you might enjoy it.


0 Comments:
Post a Comment
<< Home