PeterMorris
PeterMorris
  • Threads: 9
  • Posts: 17
Joined: Apr 13, 2010
April 19th, 2010 at 4:54:15 PM permalink
I'm trying to write a computer program to calculate the best strategy and EV for any hand in Blackjack under any combination of rules.

In the first thread, the Wizard helped me to refine my program by changing my formula when the dealer is showing an ace or a ten.

I'm now hoping that he, or someone else, will be able to do the same when it comes to splits.

At the moment I'm using a rule of thumb, which gives close to the correct results. Sometimes they are almost exactly the same, -0.10747 vs -0.10749. But other times its greater -0.258171 vs -0.22159 is the largest difference I've seen. On average the difference is about plus or minus 0.02, which is close but no cigar.

The rule of thumb I'm using right now is this: I calculate the EV for one of the cards, then double it.

I can see what's wrong with that. The EV's for the two hands aren't going to be the same. The EV for hand 2 is affected by cards that come up in hand 1. If I draw an 8 in hand 1, I'm less likely to draw an 8 in hand 2, and so on.

Can anyone suggest a way to improve this? Any way in hand 2 to better approximate the odds of drawing an 8, given that there may, or may not, be one or more 8's in hand 1?

I know how to calculate it exactly. Calculate all possible combinations for hand 1, and for each of them calculate all possible draws for hand 2. But even using the rule of thumb it takes several seconds, doing it accurately would increase that time several thousandfold.
Wizard
Administrator
Wizard
  • Threads: 1494
  • Posts: 26520
Joined: Oct 14, 2009
April 19th, 2010 at 5:19:07 PM permalink
Here is how I do it. This would be mathematically equivalent to the player re-splitting to as many hands as he can, and then playing just one of them, and multiplying the result by the number of hands he re-split to. Here is the computer logic.

1. I calculate the probability that the player will re-split to 2, 3, and 4 hands. This will depend on the player's pair, the dealer's up card, and number of decks. This is done with a recursive function, that was tricky to get right, especially against a dealer 10 or ace (for reasons you're already familiar with).

2. For the case where the player re-split to 2 hands, play out just one hand, eliminating the possibility of getting the original card as the first card after the split. Then multiply by 2.

3. Repeat step 2 for re-splitting to 3 hands. Remove an extra card from the deck, the same rank as the player's pair. Multiply results by 3.

4. Repeat step 3 for re-splitting to 4 hands (take out two cards and multiply results by 4).

5. The expected value is pr(2 hands)*2*EV(one hand) + pr(3 hands)*3*EV(one hand) +
pr(4 hands)*4*EV(one hand).

Hopefully that is right. I haven't touched the program in several years. I recall I had trouble agreeing with Cindy Liu's (webmaster of the former GamblingTools.net site) figures for splitting. She was very generous with her time helping to explain how she did it. I think this is what she said, so credit should go to her.

If this is too much, I would not hesitate to add a rule where the player splits only once.
"For with much wisdom comes much sorrow." -- Ecclesiastes 1:18 (NIV)
scotty81
scotty81
  • Threads: 8
  • Posts: 185
Joined: Feb 4, 2010
April 19th, 2010 at 5:23:58 PM permalink
One approach you might try is to just simulate the play instead of trying to calculate it mathematically. Typically, the majority of the time spent in simulations is with the shuffle, but one way around this is to construct a deck once, and then use a random number generator to select a card. You only need to maintain an array of selected cards, and if the RNG selects the same card again, just keep going until you get a card that hasn't been selected. All the shuffle has to do is set the count of dealt cards to zero.

I have written such a simulator on my PC (2.2 GHZ laptop), and this technique can process about 1 million hands per second. If you can afford to wait a few minutes, the simulation can play close to a billion hands and derive a number very close to the true theoretical number.

Once you solve the shuffle problem, setting up the deck for any combination of counts, etc. is pretty trivial.

The EV is simply the calculation of:

(return/action)

Every time you place a bet, the action number is increased by the amount bet.

Every time you win, the return number is increased by the amount won (including the original bet)

Every time you push, the return is increased by the amount bet.

You will get slightly different numbers depending upon if you chose to discard pushed hands. I've seen some simulators that do this, and some of the popular published EV numbers appear to discard the pushes (i.e. don't count them in the return/action equation). What you will find is that if you don't include the pushes in the EV calcualtion that your EV will be skewed (both positively and negatively) as you get further away from 0.
Prediction is very difficult, especially about the future. - Niels Bohr
pacomartin
pacomartin
  • Threads: 649
  • Posts: 7895
Joined: Jan 14, 2010
April 20th, 2010 at 12:34:30 AM permalink
The bjmath site here does not distinguish between DAS or not DAS. It is an important distinction since it affects several decisions. Since Cindy Liu's site is no longer functional, I think that the Wizard of Odds is the only website that posts an accurate list of expected values which are not calculated via simulation.The best accomplishment you are going to do is simply to reproduce the Wizard's numbers.

You've already shown your programming prowess. As the Wizard suggested I would do the case of being permitted to split one time. If I am correct, then being permitted to split 2,3,4 or as many as possible is so small of a probability that it does not affect any decisions. I have never seen a caveat on number of splits allowed on a cheat sheet.

Maybe you are going to use your program to experiment with new bizarre sets of rules that no one has thought about.
PeterMorris
PeterMorris
  • Threads: 9
  • Posts: 17
Joined: Apr 13, 2010
April 21st, 2010 at 4:38:49 PM permalink
Thank you again, Wizard. I see how that formula works. I do have a question, however.

Quote:

I calculate the probability that the player will re-split to 2, 3, and 4 hands ... This is done with a recursive function, that was tricky to get right, especially against a dealer 10 or ace (for reasons you're already familiar with).



Is it really that complicated? It seems to me that there's only a small probability tree, and it's fairly simple to calculate the possibility of each leaf. For example, given a pair of 8's there are four possibilities for the next cards:

1 - 88 + 88
2 - 8x + 8y
3 - 88 + 8x
4 - 8x + 88

In case 1, resplit both pairs. That takes us to the maximum 4 hands, whatever the cards
In case 2 there are no pairs to split, so we stop on two hands.
In case 3 or 4, split to 8 + 8 + 8x. There are now four possibilities for the cards you get.

3.1 - 8y + 8z + 8x
3.2 - 88 + 8y + 8x
3.3 - 8y + 88 + 8x
3.4 - 88 + 88 + 8x


3.1 gives 3 hands, the rest give four hands.

So there are only 10 possibilities to consider, of which seven give 4 hands, 2 give 3 hands and 1 gives 2 hands.

This seems a lot simpler than a tricky recursive algorithm. But maybe there's something I've overlooked that means the above method won't work. Can you see anything wrong with my logic?
  • Jump to: