I’ve been a little bit interested in blackjack of late and in card counting. It turns out that this is a topic about which it is easy to get information. I suppose there is a huge market for advice for would be card counters.
Blackjack is interesting in that it is the only casino card game in which it is possible to beat the house edge through clever play, though to do so requires a lot of work. Essentially, the reason is that a standard game of blackjack already has a very thin edge for the house, only about 0.28% if you play an optimal strategy, 1 so if you can get a further edge you can beat it. Card counting lets you do this, but only be a very thin margin.
I was considering attempting to fully model a blackjack game mathematically, but this would have been very labor intensive. Also, it’s been done a lot of times before. So, I thought it would be fun to instead simulate a game of blackjack and compare various strategies to see how much they lose or gain over time.
If all you know about blackjack is that you want to get as close to twenty one as possible without going over, then the game is actually much more complicated than you think, especially when you attempting to compute the odds. The first thing to know about blackjack is that you are playing against the dealer. The second is that your goal is to get a higher hand than the dealers without going bust (getting a hand higher than twenty one.) Importantly, you don’t know what the dealer’s hand is going to be until you’ve played yours.
Essentially, every game of blackjack begins with players making bets and the dealer dealing two cards to every player at the table and two cards for himself, with one of the dealer cards facing down and the other facing up. Each blackjack player then plays his hand until each is finished. The dealer plays his hand last, turning over all his cards, and then paying out any bets. The game then starts again.
The value of a hand is the sum of all the cards in the hand. Each number cards is worth it’s number. Face cards are each worth ten and an ace is either one or eleven depending on which makes the better hand. (Essentially, an ace is an eleven only if that doesn’t make the hand bust. Only one ace can be worth eleven in any given hand.)
On each player’s turn, if he starts out with twenty one, that is, he has an ace plus a face or ten card, then he wins automatically and receives a three to two payout on his bet. This is called ‘Blackjack.’ (Getting twenty one later is not called ‘blackjack,’ just ‘twenty one.’) If the player doesn’t get blackjack, he has a number of options, the most important being ‘hitting,’ or ‘standing.’ If the player ‘hits,’ then the dealer deals him another card and he may go again. If instead he ‘stands,’ the player is done and the dealer moves on the next player. There are several other moves, such as ‘splitting’ on doubles, ‘doubling down,’ and ‘surrender.’ But the rules behind these vary from casino to casino. If at any point the player’s hand goes over twenty one, he is said to ‘bust,’ and he loses his bet.
It’s this busting that gives the house the edge in blackjack. The dealer can bust too, but he can only do so after all players have played their hands. So, if a player busts he loses his bet even if the dealer later busts. Since busts are common, this means the player will lose relatively frequently.
When it’s the dealer’s turn, he must follow a strict strategy which is set by the house. Typically, what happens is the dealer stands on any hand seventeen or over and hits on and hand less. When the dealer plays, his final hand will always be between seventeen and twenty one, or a bust.
I wrote a blackjack simulator which runs games fully functionally so that I can run games repeatedly easily to try different strategies. I’ve made it so that I can set the number of players, the amount of money each player starts with, as well as the number of decks the game will be played with. In addition, I’ve allowed for the ability to create arbitrary strategies for each player having separate handlers that can be passed in to represent the player’s “AI.” Unfortunately, the simulator doesn’t properly model card counting scenarios. I could fix this but I feel like I’m done for now.
I’ve configured to the blackjack simulator to compute the average winnings per hand for any given game. Running a few hundred or a few thousand games I can generate a histogram which gives a good picture of a given strategy. For example, if the player decides to follow the dealers strategy and stand on seventeen, betting ten every turn yields this return distribution:2
You’ll see that the player loses an average of about one dollar every hand with this strategy, which is about ten percent of his bet. It’s not very good but it’s much better than just playing randomly:
… where you can see that the player loses an average of almost half his hand (of ten) every turn. You can find basic strategies to bet according to and I implemented one I found online, hard coding it, so that it doubles down and splits at opportune times. You’ll see that this strategy halves the loses I have from the stand on seventeen strategy:
This one is about twice as good as the stand of seventeen strategy, but it is still a losing strategy over time. One final thing I tried was a simple hi-low counting scheme. I implemented this as trivially as possible so it just changes the bets on high and low counts rather than changing the actual play strategy. It turns out that this is actually not an improvement over basic play:
If I run the basic strategy and the basic strategy plus card-counting back to back each with the same seeded deck and I count average the loses and wins for both of them, I find that card counting like this actually causes me to lose slightly more:
basic-strategy: -0.541545
basic-strategy+card-counting: -0.66769165
Of course, I’m doing two things wrong here with regard to card counting. The first is that I’m not counting enough cards. It’s tricky to count only the cards the player can see and I didn’t model that correctly when I wrote this simulator. That can be fixed but I haven’t bothered yet. The other thing is that I’m not adjusting the play strategy according to card counts. The reason is I believe that I need a better understanding of blackjack than I have to do that correctly. I may sometime do that, but I’m a little tired of this project for now.