# The Mathematics in BlackJack Basic Strategy

#### qcom

I am doing a school project about the mathematics involved in card games, and I thought the basic strategy of BlackJack would be a great subject to touch on.

For things like the basic strategy charts, what kind of math was used to generate the best possible moves. Now, I know that these are the best possible moves, not counting deviations, because it's just a static "in the moment" comparison, versus taking into account what cards have been dynamically changing the game.

So, is it also possible, that I could do some of the math myself to prove in a sense those "basic strategy" charts?

A link to these charts can be found here: Blackjack - Wikipedia, the free encyclopedia

Thanks!

#### ebaines

There are two aways to go about deriving your own version of the strategy chart. The hard way is to calculate the odds of each possible outcome starting from yor initial conditions (such as you are dealt 17 and the dealer is showing a ten), and develop an expected return for each. Since there are thousands of possible games, you can see that it takes a lot of work to get the final answers. For example, from these starting conditions if the dealer's second card turns out to be an A, 8, 9, 10, J, Q or K, you lose. If it's a 7 you push. If it's a 2, 3, 4, 5 or 6 he has to take another card. Depending on what card he draw snext he may win, push, bust, or be required to draw again. Throw in teh rules for hitting a "soft 17" and it really gets hairy. Once you have an answer, then repeat for all other initial starting conditions.

An easier way is to run a series of Monte Carlo simulations. This technique involves running thousands of games on a computer using a randomized card dealing simulation and seeing which strategies improve your odds of winning. You can do this with some modest programing skills, or even on a spreadsheet. You write the rules for whether the dealer stands or hits, and run the simulation a few thousand times to see how you do. It's pretty straight forward if you assume that the odds of any card being drawn never changes, which basically models the dealer's shoe as infinitely deep. In other words, if he deals an ace of spades the next card he deals is as likely to be another ace of spades as any other card. If you want to get into understanding stategies as the shoe gets worked down (i.e,, takimng into account what cards have already been dealt), it gets too complicated for a spreadsheet, and you would need to write a computer program to simulate it. But in general I think Monte Carlo is the best way to attack this.

qcom

#### qcom

An easier way is to run a series of Monte Carlo simulations. This technique involves running thousands of games on a computer using a randomized card dealing simulation and seeing which strategies improve your odds of winning. You can do this with some modest programing skills, or even on a spreadsheet. You write the rules for whether the dealer stands or hits, and run the simulation a few thousand times to see how you do. It's pretty straight forward if you assume that the odds of any card being drawn never changes, which basically models the dealer's shoe as infinitely deep. In other words, if he deals an ace of spades the next card he deals is as likely to be another ace of spades as any other card. If you want to get into understanding stategies as the shoe gets worked down (i.e,, takimng into account what cards have already been dealt), it gets too complicated for a spreadsheet, and you would need to write a computer program to simulate it. But in general I think Monte Carlo is the best way to attack this.
Thanks a lot for the help, that really simplifies what I need to do! Of course, I like the second option you gave better, and I agree that a computer program would be best because I could calculate a lot of different inputs and outputs pretty easily. Now, for the Monte Carlo method, is there a standard computer application that I could download and set up, or does it need to be coded.

#### ebaines

Now, for the Monte Carlo method, is there a standard computer application that I could download and set up, or does it need to be coded.

The end result will be that if you start with 18 and the dealer is showing 10 you're expected return is about 0.38, meaning that you would expect on average to win only 38% of the time. But if you draw on 18 the chances of busting (and losing) is 10/13 = 0.77, so your odds of winning go down. Hence, even though you probably won't win with an 18, it's best to stand.

Good luck with it!

qcom

#### undefined

MHF Hall of Honor
Thanks a lot for the help, that really simplifies what I need to do! Of course, I like the second option you gave better, and I agree that a computer program would be best because I could calculate a lot of different inputs and outputs pretty easily. Now, for the Monte Carlo method, is there a standard computer application that I could download and set up, or does it need to be coded.
If you google search "blackjack monte carlo simulation" you will get some relevant hits. But my recommendation would be to code it from scratch, then you don't have to read someone else's documentation, and you'll have total control over everything. Also you can gain confidence from learning a new skill. You'll just need to know how to handle loops, random numbers, and a few other basic operations. The language isn't particularly important; you could try Python or Java, for example. Among those two, Java will be a bit faster, and of course there are many other options.

I could give you some sample code if you'd like. I wouldn't be able to work on it for a day or so due to time constraints. Let me know. (And so that I don't defeat the purpose of what I wrote above, I would try to make it an instructive experience, not just giving you code with instructions.)

qcom

#### qcom

If you google search "blackjack monte carlo simulation" you will get some relevant hits. But my recommendation would be to code it from scratch, then you don't have to read someone else's documentation, and you'll have total control over everything. Also you can gain confidence from learning a new skill. You'll just need to know how to handle loops, random numbers, and a few other basic operations. The language isn't particularly important; you could try Python or Java, for example. Among those two, Java will be a bit faster, and of course there are many other options.

I could give you some sample code if you'd like. I wouldn't be able to work on it for a day or so due to time constraints. Let me know. (And so that I don't defeat the purpose of what I wrote above, I would try to make it an instructive experience, not just giving you code with instructions.)
Only problems include the fact that my project is due Wednesday ( a week from today), and this would only be part of it, because I would have to present it into a PowerPoint based on my findings / conclusions.

Also, on top of it all, I barely have any experience in coding of any languages so... Would it be possible for me to code my own based on yours in an easy language in about 3-5 days?

Sorry, it's kind of a lot to ask! (Doh)

The end result will be that if you start with 18 and the dealer is showing 10 you're expected return is about 0.38, meaning that you would expect on average to win only 38% of the time. But if you draw on 18 the chances of busting (and losing) is 10/13 = 0.77, so your odds of winning go down. Hence, even though you probably won't win with an 18, it's best to stand.

Good luck with it!
Thanks a lot too, if I cannot code my own generator of sorts, then I will totally go with an excel spreadsheet for the project.

Last edited:

#### undefined

MHF Hall of Honor
Only problems include the fact that my project is due Wednesday ( a week from today), and this would only be part of it, because I would have to present it into a PowerPoint based on my findings / conclusions.

Also, on top of it all, I barely have any experience in coding of any languages so... Would it be possible for me to code my own based on yours in an easy language in about 3-5 days?

Sorry, it's kind of a lot to ask! (Doh)
Hmm, well I stand by my statement that the programming only requires basic understanding of loops, random numbers, etc., but after reading more about the game blackjack I see that modeling requires some thought (at least for me, not having analysed this game before).

I have found an excellent resource, the blackjack page at Wizard of Odds. Especially of interest for your project is appendix 1, which gives expected returns and the modified basic strategy table for an infinite deck. (There are a few differences between that chart and the chart for 4-8 decks.)

I think that in order to accurately reproduce the basic strategy chart via simulation, we will need to express expected return in terms of not-necessarily-positive numbers as on the site I just referenced. In other words, I think that the scheme: (win = 1, lose = 0, push = 0.5) is a useful tool but is not sufficient for our purposes. I think we should use: a win without doubling (or splitting) is 1, a lose without doubling (or splitting) is -1, and a push is 0. Doubling and splitting are handled accordingly (e.g., a bet that is doubled and lost yields -2).

The charts on expected return are very valuable to us, for testing that we have not made mistakes. After we can reproduce the expected return charts, we will automatically have the basic strategy chart (we choose the lowest expected return available to us given our situation).

So, now that that aspect is addressed, there are some logistical issues regarding programming. Are you using a Windows operating system? If so, maybe the easiest way for me (not necessarily for you (Itwasntme)) is to use Java. That's because I've installed the Java software on Windows machines like 10 times and I'm very familiar with the process (it's only a few steps, but not necessarily obvious to a beginner); and I'm set up to code Java quickly. If you use Linux then Java should be even easier to set up; if you have a Mac, I'm guessing the procedure is comparable, but I'd have to do some internet searches to know how to do certain stuff. If for some reason you have a preference for a language other than Java, please mention it.

Also, regarding logistics, it may be easier if we conversed using an IM program; we could work something out through PM if you want, otherwise here is fine; but probably instructions on how to install the Java software should be through PM at least so as not to bore everyone here.

So, let me know what operating system you're using and we'll go from there.

qcom

#### qcom

OK, from here on, we'll PM the rest, and then see if we can use IMing.

Thanks for the help everone!

#### ebaines

Just a couple of more thoughts...

The idea of scoring -1, 0 and +1 is good (a bit more intuitive than what I first proposed). But there is really no need to worry about keeping track of winnings due to splitting or doubling down with +2's or -2's. Remember that the purpose of the exercise is to determine your strategy for what to do next, not on keeping count of winnings. For example, you always double down (if you're allowed to) based on whether your odds of winning is > 50%. No need to keep traclk of the winnings itself, because after all you're only simulating one hand at a time, not a full game. As for splitting - you do that if the expected winnings for the two split cards are better for you than the winnings if left unsplit (note that you want to split even for cases where you are expected to lose, if the expected losses are less by splitting split than not).

One other thing - don't forget to consider the strategy of buying insurance if the dealer is showing a 10 or ace. Actually this one aspect of the game may be conducive to a nice short (and not too difficult) analysis.

undefined

#### qcom

OK, thanks for the additional info, in the mean time, when I wait for undefined to help me out with the program, I have been experimenting with the Excel spreadsheat idea that you proposed, and it is pretty intuitive (I have hardly used excel before).

I did this however, because, for some reason, when I put your CEILING formula into a cell, I didn't get correct results, instead I entered: =RANDBETWEEN(1,13)

Does that work?

Then I set up 4 columns (2 for the dealers cards and 2 for player 1's cards.

What do I do from there?