Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
December 18th, 2021 at 8:50:29 AM permalink
General Question:
When writing a program to calculate EV of a given decision in Blackjack, is it possible to do it algebraically or is brute force the only way to ensure accuracy?


Context:
I wrote a program in Python to calculate decision EV for any hand total/true count to find index plays for any given rule set. I know my results are slightly inaccurate because I took some short cuts in my approach to keep the program running quickly. I know this information is widely available and solved for, this was mostly an exercise for myself to get better at Python.

My approach is for any given player hand total (not combination) I look at the probability of them drawing a certain card and the subsequent EV. Example for hitting a 20 vs a dealer's 21:




To generate various true counts, I randomly remove high or low cards from the shoe, recalculate the probability of the outcomes for each hand, then generate the player decision EVs as normal. Repeat this ~100 times for non-zero TCs (to account for variance of removed cards), then take the average EV of each decision. This works pretty well for 6/8 deck games but starts to break down for DD/SD games.

The benefits to this algebraic approach are the speed at which the program runs since there's almost no looping. The problems are pretty obvious intuitively and in my output (below).
E.g. my 12v2 DD index is showing as +6 when it should be +3 since I'm not accounting for the fact that a 12v2 hand will often be comprised 2-3 low cards for the player and the single 2 for the dealer which would raise the TC 1-2 points in a DD game.

So back to my original question - is there an algebraic way to solve for SD/DD indices or is brute forcing through all hand possibilities the only truly accurate method?

ThatDonGuy
ThatDonGuy
  • Threads: 122
  • Posts: 6584
Joined: Jun 22, 2011
December 18th, 2021 at 10:11:47 AM permalink
I am a little confused as to what you mean by "algebraically."

Your main problem may be that you are only doing each one 100 times, so the variance between the expected and actual results is larger than what you want. Try 10,000 results (and even then, that's a little low) and see what happens.

If your strategy does not change (other than how much you bet) based on the EV, then what I would do is this:
1. Start with a full deck/shoe, and a running count and TC of zero
2. Play hands through the shoe, keeping track of the player total, dealer up card, and TC at the start of the hand, and recalculating the TC after the hand is played
3. Remember to take into account when the deck/shoe will be reshuffled
4. Repeat 1 and 2 as many times as you can - anything short of 100,000 is not going to be accurate, and I would prefer millions of runs.
Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
December 18th, 2021 at 10:27:29 AM permalink
Algebraically meaning I don't simulate each hand I just look at the probability of each outcome and the EV of that outcome for a specific hand. For clarity, each hand's EV is calculated once per decision and each TC is what's being simulated 100 times. Since I'm only removing a handful of cards from the shoe I'm not sure I need more than that to get pretty accurate results.

Also I'm trying to calculate the EV of each decision, not just the optimal decision. In your approach above would the program just randomly pick hit/stand/double/split/surrender for each hand?
ThatDonGuy
ThatDonGuy
  • Threads: 122
  • Posts: 6584
Joined: Jun 22, 2011
December 18th, 2021 at 2:08:21 PM permalink
Quote: Donuts

Algebraically meaning I don't simulate each hand I just look at the probability of each outcome and the EV of that outcome for a specific hand. For clarity, each hand's EV is calculated once per decision and each TC is what's being simulated 100 times. Since I'm only removing a handful of cards from the shoe I'm not sure I need more than that to get pretty accurate results.

Also I'm trying to calculate the EV of each decision, not just the optimal decision. In your approach above would the program just randomly pick hit/stand/double/split/surrender for each hand?
link to original post


I would use basic strategy.

And even if you were simulating something like a coin toss, I would use far more than 100 results.
charliepatrick
charliepatrick
  • Threads: 39
  • Posts: 2997
Joined: Jun 17, 2011
December 19th, 2021 at 1:04:12 AM permalink
Technically you can work out all the dealer hands given a starting deck (i.e. which cards have been removed) and hence the chances of all the outcomes. To save time it might be worth combining (say) dealer 7 89 with 7 98, but in practice it's best just to create a nested loop and work out all the combinations and how often each can happen. (You may need to cater for hands such as 7 22222 being impossible with one deck, i.e. can happen 0 times!)
Looking at (say) 93 vs 2, then you need to work out the EVs of 93 vs 2 (standing) then 93A,932,933...939 (obviously 93X is a loser, so you set that to -1). In theory you need to look at whether you hit 93A using a similar technique.
Once you've coded 93 v 2 you can do any other player hand.
DogHand
DogHand
  • Threads: 2
  • Posts: 1746
Joined: Sep 24, 2011
December 19th, 2021 at 5:25:32 AM permalink
Quote: Donuts

<snip>My approach is for any given player hand total (not combination) I look at the probability of them drawing a certain card and the subsequent EV. Example for hitting a 20 vs a dealer's 21:



<snip>link to original post



Donuts,

I am puzzled by this example of yours: if the dealer already has 21 before the player acts, then the dealer has a BJ. Why isn't the hand over before the player acts?

Dog Hand
gordonm888
Administrator
gordonm888
  • Threads: 61
  • Posts: 5283
Joined: Feb 18, 2015
December 19th, 2021 at 11:04:23 AM permalink
Your algebraic approach is what is usually called "combination mathematics." Most blackjack calculators and many analyses are based on combination math. Most of us do take into account the composition of the dealer's hand. It is sometimes important: say, for 12v4. A T-2 vs 4 is often played differently than a 9-3 vs 4,
Last edited by: gordonm888 on Dec 19, 2021
So many better men, a few of them friends, are dead. And a thousand thousand slimy things live on, and so do I.
Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
December 19th, 2021 at 2:07:07 PM permalink
Quote: gordonm888

Your algebraic approach is what is usually called "combination mathematics." Most blackjack calculators and many analyses are based on combination math. Most of us do take into account the composition of the dealer's hand. It is sometimes important: say, for 12v4. A T-2 vs 4 is often played differently than a 9-3 vs 4,
link to original post



Is the right approach then to do what I did but instead of just using dealer/player totals use explicit two card hand combinations (e.g. 2 + 10 and 3 + 9 instead of just 12) then calculate the weight of each combination to decide what to do on the average 12?
Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
December 19th, 2021 at 2:08:37 PM permalink
Quote: DogHand

Quote: Donuts

<snip>My approach is for any given player hand total (not combination) I look at the probability of them drawing a certain card and the subsequent EV. Example for hitting a 20 vs a dealer's 21:



<snip>link to original post



Donuts,

I am puzzled by this example of yours: if the dealer already has 21 before the player acts, then the dealer has a BJ. Why isn't the hand over before the player acts?

Dog Hand
link to original post



Bad example from me might have been better to do a dealer 20 with a 1,0,-1... etc. chart instead
charliepatrick
charliepatrick
  • Threads: 39
  • Posts: 2997
Joined: Jun 17, 2011
December 19th, 2021 at 2:23:00 PM permalink
Quote: Donuts

...Is the right approach then to do what I did but instead of just using dealer/player totals use explicit two card hand combinations (e.g. 2 + 10 and 3 + 9 instead of just 12) then calculate the weight of each combination to decide what to do on the average 12?...

No - for instance the decision of 10 2 vs 4 single deck is to hit, whereas 9 3 vs 4 is to stand. A more extreme case is 7 7 vs Ten, where you stand.

With infinite decks it doesn't matter how your total is made up, with with finite decks sometimes which cards are in your hand makes a difference.

Of course if you're trying to develop a count method and when you should change from basic strategy, then you possibly need to take shortcuts, otherwise it will be too much to remember.
Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
December 19th, 2021 at 4:17:05 PM permalink
Quote: charliepatrick

Quote: Donuts

...Is the right approach then to do what I did but instead of just using dealer/player totals use explicit two card hand combinations (e.g. 2 + 10 and 3 + 9 instead of just 12) then calculate the weight of each combination to decide what to do on the average 12?...

No - for instance the decision of 10 2 vs 4 single deck is to hit, whereas 9 3 vs 4 is to stand. A more extreme case is 7 7 vs Ten, where you stand.

With infinite decks it doesn't matter how your total is made up, with with finite decks sometimes which cards are in your hand makes a difference.

Of course if you're trying to develop a count method and when you should change from basic strategy, then you possibly need to take shortcuts, otherwise it will be too much to remember.
link to original post



That makes sense - I don't think I'd ever bother learning composition dependent basic strategy since SD games are a bit rarer these days anyway. If I was just going to do this exercise for DD/6D would the weighted average method I mentioned work then?
  • Jump to: