ddr
ddr
  • Threads: 2
  • Posts: 6
Joined: Nov 27, 2019
November 27th, 2019 at 5:57:24 PM permalink
I've been studying blackjack and card counting for a while and wrote my own program to simulate different playing and betting strategies. This was originally for fun and to debunk the bogus claims of a book I read (that claimed you could gain an edge playing basic strategy simply by raising your bet after certain win/loss patterns).

Now that I have this complete game simulator I am able to run 1,000,000 hands or more easily and calculate the observed edge from the win/loss results. But for an 8-deck H17 DAS late surrender game, I keep getting a house edge of around 2.75%, which I know is wrong. According to the Wizard and other references it should be around 0.55%.

My question is: what is the formula to compute house edge from observed results? Currently I am using:

player_edge = (units_won - units_lost) / units_wagered

where 'units_wagered' counts the original wager on each hand, not doubles or splits, per the Wizard's guidance found on /gambling/house-edge/.

'units_won' is the total of all wins including 3/2 for Blackjack
'units_lost' counts all losses including original wagers, surrender (1/2), doubles, and splits

If this formula looks right then I must have a bug in my game logic somewhere. Thanks for reading!

-DDR
ThatDonGuy
ThatDonGuy
  • Threads: 122
  • Posts: 6678
Joined: Jun 22, 2011
November 27th, 2019 at 6:07:54 PM permalink
What do you get if you use (units won - units lost) / hands, assuming your initial bets are always 1 unit?
gordonm888
Administrator
gordonm888
  • Threads: 61
  • Posts: 5357
Joined: Feb 18, 2015
November 27th, 2019 at 8:35:10 PM permalink
Give us more detailed info on your results, if you have it

- Win % or units won/hands
- Lose % or units lost/hands

Any other info you have on frequency of doubles, frequency of splits or whatever.
So many better men, a few of them friends, are dead. And a thousand thousand slimy things live on, and so do I.
ddr
ddr
  • Threads: 2
  • Posts: 6
Joined: Nov 27, 2019
November 28th, 2019 at 4:04:31 AM permalink
I did find a couple of bugs that improved the results but still well above a 1.0% house edge. Here is my output:

H17 DAS LAS Basic Strategy + Base Bet Selector (flat betting 10 units), 8-Decks, Penetration before shuffle .80
total hands: 1,000,000
hands won: 42.61%, units_won 5,026,820.00 (51.55%)
hands lost: 45.19%, units_lost 5,212,710.00
pushes: 7.26% (72,552)
surrenders: 4.94% (49,430)
blackjacks: 4.63% (46,347, won 44042)
units wagered: 9,752,250
edge: -1.91% (negative indicates house edge)
(5,026,820 - 5,212,710) / 9,752,250

"hands" is counting splits as multiple hands. That's why units wagered < total hands * 10. That equates to 24,775 additional hands from splits. I have gone back and forth whether to count "deals" (not counting splits separately) or "hands" in the hands won %. I couldn't resolve how to count multiple splits (e.g. a 3-hand split) where one hand wins and others lose against the win %.

My goal is to have a simulation that I can use to experiment with strategy and betting variations to see the impact as well as tailor it to the games I have access to locally (around Boston and southern New Hampshire).
CrystalMath
CrystalMath
  • Threads: 8
  • Posts: 1911
Joined: May 10, 2011
November 28th, 2019 at 4:34:53 AM permalink
To simplify the debugging, I recommend looking at a bet of 1 and don’t add splits into the hand total. Do track them in the total wager, wins, and losses, though. Also, add info about doubles.
I heart Crystal Math.
charliepatrick
charliepatrick
  • Threads: 39
  • Posts: 3011
Joined: Jun 17, 2011
November 28th, 2019 at 2:31:43 PM permalink
My recommendation is to add lots of trace inside your program and gradually test each bit. For instance have a routine that
(i) Prints the deck after shuffling up
(ii) Prints how each hand is played (including splits and doubles) and the calculated result. Where possible find as many decisions as reasonable (e.g. A7 vs 9, 88 vs Ten).
You can then check that the cards used by each hand match up with the deck and that splits/doubles/strategy is correct.

Another idea is to use the program to test a simple game (Casino War, Baccarat, 3-card poker) and see if the cards are being random and the House Edge is as expected.
ddr
ddr
  • Threads: 2
  • Posts: 6
Joined: Nov 27, 2019
November 30th, 2019 at 5:23:19 PM permalink
I appreciate the guidance. So it seems from the replies I’m on the right track computing the edge value.

I’ve done most of the debugging tips here and will keep at it. I need to instrument more intermediate outputs and look for misplays or bad math somewhere.
ddr
ddr
  • Threads: 2
  • Posts: 6
Joined: Nov 27, 2019
December 14th, 2019 at 10:08:55 PM permalink
For those interested, I found an important bug in my code and think I have solved it! My edge calculation was correct : (units won - units lost) / initial_wagers. The last bug was in computing the value of hands that include an Ace. The logic here turned out to be trickier than I would have thought! Essentially I was always counting the first Ace in a hand as 11, so hands would count as "busted" that should not have been. (e.g. 6-6-A was adding up to 23!) Since player bust is a big contributor to the house edge, that made all the difference.

With this fixed, my 1M deal simulation now gives:

total deals: 1,000,000
total hands: 1,025,475 (includes counting splits)
stake: -6,093.00 (min -6,117.50, max 16.00)
hands won: 42.32%, units_won 515,917.50 (51.59%)
hands lost: 44.27%, units_lost 522,010.50
pushes: 8.11% (83,201)
surrenders: 5.30% (54,321)
blackjacks: 4.74% (47,357, won 45091)
total wagered: 1,000,000
average loss: 0.006093
edge: -0.61%

This is statistically close to the expected value for this rule set. I can now start iterating variations in strategy and bet sizing to optimize for my purposes.

Happy Wagering!

-ddr
  • Jump to: