Calculate probability to decide whether to hit/double/split/stand

#1
Hi,

I'm currently trying to build a Blackjack game and would like to be able to calculate what the best option to take in a given situation is.

I have used information at http://probability.infarom.ro/blackjack.html in order to calculate a probability of bettering your hand if you take another card but cannot find any equations explaining how to calculate the probability after taking actions such as split.

Something like (Dead link: http://www.tqsports.com/blackjack/calculator.htm) is what i would like to make, but I cannot get my head around the calculations needed.

Thanks
:)
 

Sonny

Well-Known Member
#2
Basically you want to calculate the EV (Archive copy) for every possible hand. It can be pretty tricky because the number of hands is large and the calculation of dealer probabilities is usually different for most hands. The Theory of Blackjack by Peter Griffin will explain how to derive BS for BJ, as well as give you the formulas and even some source code to calculate the numbers yourself. You might also like to read these old threads.

http://www.blackjackinfo.com/bb/showthread.php?t=7197
http://www.blackjackinfo.com/bb/showthread.php?p=37503

-Sonny-
 
#3
Thanks for your reply Sonny.

Thats looks like exactly what I want to do.

If The Theory of Blackjack by Peter Griffin explains how to calculate these numbers then I will buy it and proceed from there.
 
#4
Hi,

I've bought the book The Theory of Blackjack by Peter Griffin and have managed to work out and code a solution to calculate the probabilities for:
- Dealer outcome
- Stand EV
- Double EV

I'm having trouble working out how to go about the hit and split probabilites as i can't work out where the calculations should stop. Stand and double were ok as its either the current position, or one further card - but with hit and split there are many paths to go down of varying lengths.

When calculating the EV for hit presumably i am correct in thinking it should take more than just the next card into account? Otherwise it would surely be the same calculation as the double and wouldn't therefore take into account the option of taking further cards.

Any help or advice on how to programmatically (even at a pseudo-code level) do the hit and split calculations would be much appreciated.

Many thanks.
 

Canceler

Well-Known Member
#5
ItsMe1989 said:
i can't work out where the calculations should stop.
To do it right, you should stop after you’ve taken into account EVERYTHING THAT COULD POSSIBLY HAPPEN, and weighted those outcomes by their probability of occurrence.

No one said it would be easy. :)

This is why I’m in awe of anyone who develops a combinatorial analyzer. :1st:
 
#6
Thanks Canceler. I wasn't expecting it to be easy!

Is there any way to get sufficient results quickly for the purposes of giving real time advice alongside a game, rather than completly accurate for all possibly actions.

Something i'm thinking is:
Take the hand, work out the EV of standing, work out ev of standing after hitting (for each card ace through tens), if hit is greater than stand then continue down the hit path (and do the same again) otherwise take the stand value. Weight them accordingly and add them up.

This seems to be giving realistic figures when compared to those of doubling and standing (ie. the advice seems to be correct) in all situations but those which you would clearly expect double to be favoured - in this case the hit figure is still higher.

Any comments on this way of calculating a basic figure for simple advice in a "just-for-fun" game? or ways which it could be improved?

Your comments are much appreciated. Thanks.
 

KenSmith

Administrator
Staff member
#7
ItsMe1989 said:
Is there any way to get sufficient results quickly for the purposes of giving real time advice alongside a game, rather than completly accurate for all possibly actions.
Except for splits, the complete calculation should be quick enough for realtime use.

Something i'm thinking is:
Take the hand, work out the EV of standing, work out ev of standing after hitting (for each card ace through tens), if hit is greater than stand then continue down the hit path (and do the same again) otherwise take the stand value. Weight them accordingly and add them up.
On the right track, but you can't know the hit EV unless you go all the way to the end of the chain. Otherwise, you're essentially comparing "stand" to "hit just once", which is going to yield inaccurate results. For example, with a hard total of 5, the EV is identical for hitting once or standing. Hitting is obviously superior once you allow more than one hit card.

The code you write for this process should be recursive. The innermost routine should call itself many times to arrive at a result.
 
#8
Thanks for your reply KenSmith.

The code i have written is recursive, it keeps hitting until the current stand EV (after any number of hits) is greater than the EV after hitting the next card.

Can you explain to me what you mean by "the end of the chain"? As it is where the calculation should stop that I am unsure on.

:)
 

Canceler

Well-Known Member
#9
ItsMe1989 said:
Any comments on this way of calculating a basic figure for simple advice in a "just-for-fun" game? or ways which it could be improved?
No, not from me. I'm not qualified to advise you on this; I just know it's complicated. People like KenSmith, Sonny, and k_c can give you much better advice than I can.
 

KenSmith

Administrator
Staff member
#10
ItsMe1989 said:
Can you explain to me what you mean by "the end of the chain"? As it is where the calculation should stop that I am unsure on.
The end of the chain is when you have a total of 21 or more. For every possible hand combination, you'll examine all possible hits until the hand reaches 21 or busts.

Here's a bit of pseudo-code:

Code:
function GetOptimalValue(CurrHand);
{
Calculate StandEV;

if (CurrHand.total >= 21) {
  return StandEV;
} else {
  HitEV = 0;

  for HitCard = (ace,2,3,...,Ten) {
    ProbabilityThisCard = NumLeft(HitCard) / TotalCardsLeft;
    NewHand = CurrHand.addCard(HitCard);
    HitEV += ProbabilityThisCard * GetOptimalValue(NewHand);
  } 

  if HitEV > StandEV {
    return HitEV;
  } else {
    return StandEV;
  }
}
I'm glossing over lots of details here, such as the fact that you need to send the current Deck status into the recursive routine. Hopefully this helps though.
 
#11
KenSmith thank you very much - that was very helpful. I had almost that but some of my logic was slightly wrong!

I've implemented it along the lines you suggest now, however it still appears to be resulting it hitting always being more favourable than doubling. I'm wondering if there might be a slight mistake in how i'm calculating one of the figures used in the calculation (such as the stand EV or dealer probability).
If I outline the process i'm using could you tell me if you see any problems?

Dealer Prob:
Take upcard, loop through each of cards (2..ace) and continue to call function until a total over 17 is achieved. Work out the probability of that route and add that to an array storing each outcome (17 through 21, bj and bust) in the correct element. Continue until all routes have been processed.
This seems to be working and giving me figures that seem roughly correct (and add up to 1 so i know all options are being evaluated) but it differs from the tables linked to by Sonny earlier in the thread.

Stand EV: (as outlined in The Theory of Blackjack, if i've understood it correctly)
Get current dealer prob and value of current hand, for each of the possible outcomes decide if you'd win or loose (currently ignoring ties) and adding to win/loose variables. Then ev = win-loose.

Double EV:
Loop through each of cards (2..ace) adding one to the current two card hand, calculate the probability of getting that card, calculate the stand EV after taking that card, multiply probability and stand EV then add to double EV. Do once for each of the available cards (2..ace).

I believe I'm fairly close with these and really do appreciate the feedback.
Thanks!
 

Canceler

Well-Known Member
#12
ItsMe1989 said:
it still appears to be resulting it hitting always being more favourable than doubling.
I hate to ask a silly question, but...

Are you handling your payouts properly? Because a proper double-down (as opposed to hitting) should result in winning fewer hands, but more money.
 
#13
Canceler said:
Are you handling your payouts properly? Because a proper double-down (as opposed to hitting) should result in winning fewer hands, but more money.
Canceler: I get what you're saying and i think i may have overlooked this (rather silly of me:eek:) in my calculation of double down EV.
Am i correct in thinking that as you will win twice as much, the wins should be weighted twice as much as the lose in the calculation?

I'm still thinking my process for calculating the dealer probabilites is slighly wrong as they differ from the tables on the site.

Thanks.
 

Canceler

Well-Known Member
#14
ItsMe1989 said:
Am i correct in thinking that as you will win twice as much, the wins should be weighted twice as much as the lose in the calculation?
Something like that, I'm sure. In this thread, I'm only doing concepts. I'll leave it to you to work out the details. :grin:
 
#15
Sonny said:
The Theory of Blackjack by Peter Griffin will explain how to derive BS for BJ, as well as give you the formulas and even some source code to calculate the numbers yourself.
Can you tell on which pages in the book to find this? :)
 

MGP

Well-Known Member
#16
Ken,

I'm surprised at you ;) !! There's no reason to exclude splitting. It's possible to calculate CD strategy real-time if playing online. It takes longer to type in the cards that are being dealt...

KenSmith said:
Except for splits, the complete calculation should be quick enough for realtime use.


On the right track, but you can't know the hit EV unless you go all the way to the end of the chain. Otherwise, you're essentially comparing "stand" to "hit just once", which is going to yield inaccurate results. For example, with a hard total of 5, the EV is identical for hitting once or standing. Hitting is obviously superior once you allow more than one hit card.

The code you write for this process should be recursive. The innermost routine should call itself many times to arrive at a result.
 
Top