By using listi.net you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

listi.net

 


Blackjack

  • Rules for dealer
  • Automating the dealer play

    https://cherper.com/showlist2.asp?parent=52042



    Examine blackjack



    Simulate the play

    Play and learn the best strategies.

    Rules of Blackjack
  • It's you vs. the dealer
  • You place a bet and then you're dealt 2 cards face up
  • and the dealer get 2 cards one face up and one face down
  • Your goal is to get as close to 21 points without going over
  • If you exceed 21 you lose
  • Cards 2 - 10 are worth that point value
  • Ace can be treated as 1 or 11
  • Jack, Queen, and King are treated as 10 pts.
  • The dealer must hit if the hand is less than 17 and stick if greater than 16
  • There is an exception if the dealer has a soft 17 (includes an Ace) then must hit??(not sure)
  • There are other rules of splitting a hand if you have a pair and playing 2 separate hands, you must double your bet
  • There is also doubling down where you double your bet and get one more card only
  • Rules vary amongst casino so check them out
  • there are alternative rules like insurance and sometimes other side bets
  • If there is a tie, called a push, no money changes hands

    Blackjack doesn't use a fair deck except for when the first card is dealt. The odds of receiving a card, shifts as the cards are dealt. We will do most of the analysis assuming that each card is randomly selected (shuffled before each deal) from a limitless deck. Then we will look at one, two, four, six, and eight-deck games.

    For our simulation, we can just generate a random number between 1 and 13, and allow a 1 to mean 1 or 11 and a 11, 12, or 13 to be valued as 10.

    For blackjack, we will first program the dealer's rules to see how often various scenarios play out, then we'll look at the basic rules, advanced rules, and then possibly card counting.

    Below is the results of my analysis





    In 32,051 trials the dealer busts around 30% of the time and doesn't bust 70%.

    Dealer getting 20 is the highest percent which makes sense because there are 4 ten-value cards out of 13, which makes the odds of 4/13 or about a 31% chance of being dealt a 10 value (ie 10, Jack, Queen, or King)

    Download the spreadsheet from Blackjack.xlsm

    Press the Run once button to deal one hand

    Press the Run Many to run it over and over until you press Esc to stop the code.

    Run Once button

    Sub Button1_Click()
    gameover = False
    Range("D:E") = ""
    'a = Array(1, 3, 1, 2, 1)

    Do Until gameover
        i = i + 1
        c = [randbetween(1,13)]
        'c = a(i - 1)
        
        If c > 10 Then c = 10
        Cells(i + 1, 4) = c
        Total = Total + c
        If c = 1 Then
           alttotal = alttotal + c + 10
           If alttotal > 21 Then
              alttotal = alttotal - 10
           End If
          
        Else
            alttotal = alttotal + c
        End If
        Range("E1") = alttotal
        Range("D1") = Total
        If (alttotal > 17 And alttotal < 22) Or Total > 16 Then
          
            If alttotal > Total Then Total = alttotal
            gameover = True
            If Total = 21 Then
                Range("dealer21") = Range("dealer21") + 1
            End If
            If Total = 20 Then
                Range("dealer20") = Range("dealer20") + 1
            End If
            If Total = 19 Then
                Range("dealer" & Total) = Range("dealer" & Total) + 1
            End If
        
            If Total = 18 Then
                Range("dealer" & Total) = Range("dealer" & Total) + 1
            End If
            
            If Total = 17 Then
                Range("dealer" & Total) = Range("dealer" & Total) + 1
            End If
            If Total > 21 Then
                Range("dbusts") = Range("dbusts") + 1
            End If
        
        Else
           If Total < 17 And alttotal < 18 Then
           Else
            alttotal = Total
            Range("E1") = alttotal
           End If
          
        End If
        
    Loop

    End Sub



    Run Many Button

    Sub Button2_Click()
    Do Until Range("I1") <> ""

      Button1_Click
    Loop
    End Sub




    Excersize
  • Make the code more efficient by using variables instead of spreadsheet fields

    Exercise

    Calculate the odds of the dealer busting with various up cards A - K

    The next thing we will do is determine the odds of doubling down.

    Add a chart and some more features



    Let's develop and run a number of simulations of doubling down.
  • With an Ace
  • Hard hand (no Ace)
  • Dealer's up card
  • With card counting
  • How many times in a row should the dealer bust based on the number of hands played



  • blog comments powered by Disqus