See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 13 of 23

Thread: VBA Code For Blackjack

  1. #1
    Member
    Join Date
    May 2023
    Location
    Las Vegas since 11/2023
    Posts
    58


    Did you find this post helpful? Yes | No

    VBA Code For Blackjack

    This question must have been asked before but - I'm looking for VBA code to deal blackjack.

    I want to test play deviations. I can alter the deal/shuffle code myself.

    Anyone know where this might exist? I don't want to do the heavy lifting of re-inventing the wheel.

  2. #2
    Random number herder Norm's Avatar
    Join Date
    Dec 2011
    Location
    The mote in God's eye
    Posts
    12,798
    Blog Entries
    59


    Did you find this post helpful? Yes | No
    VBA would be far too slow.
    "I don't think outside the box; I think of what I can do with the box." - Henri Matisse

  3. #3
    Member
    Join Date
    May 2023
    Location
    Las Vegas since 11/2023
    Posts
    58


    Did you find this post helpful? Yes | No
    Quote Originally Posted by Norm View Post
    VBA would be far too slow.
    Even if that's true, it's the only language I know that I could modify the dealing code in.

  4. #4


    Did you find this post helpful? Yes | No
    Quote Originally Posted by redtop43 View Post
    This question must have been asked before but - I'm looking for VBA code to deal blackjack.

    I want to test play deviations. I can alter the deal/shuffle code myself.

    Anyone know where this might exist? I don't want to do the heavy lifting of re-inventing the wheel.
    I program in C++ under cygwin OS, so I don't know how easy it is for you to spawn subprocesses under VBA. I just integrate the Eric Farmer C++ code into any new functionality that I require. If I had to write a simulator and I could not integrate Eric's code directly into my project, I would do a simple workaround with a master-slave arrangement.

    Can you generate input to an external executable file from VBA? If you can, you can make strategy.exe a slave to your VBA program.

    If I make a text file called 'redtop' and use this as input to Eric's strategy.exe program, it will perform almost any BJ calculation I could ever want for a simulator.

    This command instructs the program to use the file as input:
    Code:
    ./strategy.exe < redtop
    
    where the contents of the redtop file are:
    6
    y
    y
    y
    n
    y
    y
    n
    n
    n
    1.5
    prob.txt
    7 2 2 6
    0 0
    This is the key for the lines in the input file:
    Code:
    Enter number of decks, or 0 to enter shoe: 6
    Enter 'Y' or 'y' if dealer hits soft 17: y
    Enter 'Y' or 'y' if doubling down is allowed on any total: y
    Enter 'Y' or 'y' if doubling down is allowed on soft hands: y
    Enter 'Y' or 'y' if doubling down is allowed on any number of cards: n
    Enter 'Y' or 'y' if doubling down is allowed after splitting pairs: y
    Enter 'Y' or 'y' if resplitting pairs is allowed: y
    Enter 'Y' or 'y' if resplitting aces is allowed: n
    Enter 'Y' or 'y' if CDZ- (vs. CDP) post-split strategy is used: y
    Enter 'Y' or 'y' if late surrender is allowed: n
    Enter blackjack payoff (normally 1.5): 1.5
    This takes less than a second to run and generates a file named prob.txt. If your VBA can read the output file and capture the console output, you will have a lot of detailed information about this particular hand. It should be simple to parse the prob.txt file to get all the primary and secondary strategy choices for any given hand.

    If this is too slow for what you have in mind, then you might be able to create a large set of files ahead of time to store the information that you need for your simulation. You have not provided much information about the problem you are trying to solve. If you need to be able to simulate deep into the deck, then you might want to keep the slave program attached to the VBA output and use it to do a stream of calculations for your sim. Note that you can set the exact contents of the shoe rather than just start with 6 decks as I have done.

    You should be able to do two-way communication between master and slave processes by using pipes or by spawning a subprocess and redirection the I/O file descriptors.

  5. #5
    Member
    Join Date
    May 2023
    Location
    Las Vegas since 11/2023
    Posts
    58


    Did you find this post helpful? Yes | No
    Thank you, but I haven't the foggiest idea what you just said. I was a computer whiz kid back before most people had seen a computer. My skills have seriously atrophied.

    Here is what I want to do:

    1) Find VBA code that would play a hand of blackjack. Shuffle the cards, deal two to each player, and let the player and then the dealer make all relevant decisions.
    2) Determine my experiment. Let's say I want to know the EV of doubling (6,5) vs. A with a TC of +2.
    3) I will go into the code and hijack some elements of it; for example I may make the first three cards in the deck 6, 5, A. This would result in the player having an 11 and the dealer showing an A. I will need to be able to call a decision array where (11 vs. A) is double. I could hard-code this but then when the decision is hit, I will still need the program to know to hit 12-16 and stand on 17+ vs. dealer A.
    4) I will go into the deck (assume 6 decks) and remove 11 more low cards, giving a RC of +12 and a TC of approximately +2. My plan for the dealing routine is to select a random number from 1-312, but if the card has already been removed, it will pick a new random index. I will only deal one hand before reshuffling.

    So that's what I'm looking for.

  6. #6


    Did you find this post helpful? Yes | No
    Quote Originally Posted by redtop43 View Post
    Thank you, but I haven't the foggiest idea what you just said. I was a computer whiz kid back before most people had seen a computer. My skills have seriously atrophied.

    Here is what I want to do:

    1) Find VBA code that would play a hand of blackjack. Shuffle the cards, deal two to each player, and let the player and then the dealer make all relevant decisions.
    2) Determine my experiment. Let's say I want to know the EV of doubling (6,5) vs. A with a TC of +2.
    3) I will go into the code and hijack some elements of it; for example I may make the first three cards in the deck 6, 5, A. This would result in the player having an 11 and the dealer showing an A. I will need to be able to call a decision array where (11 vs. A) is double. I could hard-code this but then when the decision is hit, I will still need the program to know to hit 12-16 and stand on 17+ vs. dealer A.
    4) I will go into the deck (assume 6 decks) and remove 11 more low cards, giving a RC of +12 and a TC of approximately +2. My plan for the dealing routine is to select a random number from 1-312, but if the card has already been removed, it will pick a new random index. I will only deal one hand before reshuffling.

    So that's what I'm looking for.
    Eric's program will do all of this already.

    I just ran 5,6 vs dealer ace with a full 6-deck deck and again with 11 cards of rank (2, 3, 4) removed.
    Code:
    Stand      E(X) =  -59.507785350%
    Hit        E(X) =   10.866847832%
    Double     E(X) =   12.400674775%
    
    Stand      E(X) =  -58.936586889%
    Hit        E(X) =   12.857923894%
    Double     E(X) =   17.895879083%
    As you can see, it calculates the EV of 'Hit' even though it is not the optimum strategy.

    If you can invoke an external program from VBA, then all your program needs to do is create the text input to control stragtegy.exe. I know little about VBA. Maybe you would be better off invoking the program via perl or python.

    (My first program was written in 1973 on a Univac mainframe in ALGOL60.)
    Last edited by OnlineAP; 02-24-2025 at 05:46 PM.

  7. #7
    Member
    Join Date
    May 2023
    Location
    Las Vegas since 11/2023
    Posts
    58


    Did you find this post helpful? Yes | No
    It seems like you have done exactly what I'm trying to do. How do I get that program?

    I do remember about a zillion years ago writing a QuickBasic program that piped input from a .txt file. When I rewrote it in VBA I put the data in a tab of a spreadsheet and pulled the data from there.

    If I understand what you did above, you found the EV for stand, hit, and double, both for TC= (roughly) 0 and +2? Slightly inaccurate because you pulled all 2/3/4 and no 5/6? But more than adequate here as a proof of concept.

  8. #8


    Did you find this post helpful? Yes | No
    Did I just read QuickBasic? Good times. Staying tuned here!

  9. #9


    Did you find this post helpful? Yes | No
    Quote Originally Posted by redtop43 View Post
    It seems like you have done exactly what I'm trying to do. How do I get that program?

    I do remember about a zillion years ago writing a QuickBasic program that piped input from a .txt file. When I rewrote it in VBA I put the data in a tab of a spreadsheet and pulled the data from there.

    If I understand what you did above, you found the EV for stand, hit, and double, both for TC= (roughly) 0 and +2? Slightly inaccurate because you pulled all 2/3/4 and no 5/6? But more than adequate here as a proof of concept.
    https://github.com/possibly-wrong/blackjack
    You can get the source code here, but I assume that you would just start with the precompiled executable programs that are also in the distribution. These programs have text input and output. If you can figure out how to send the right information to the program, then it is able to do almost any calculation that you would need for your analysis.

    The source code is C++, so you probably won't be able to modify it unless you are fairly strong in C++.

  10. #10


    Did you find this post helpful? Yes | No
    Quote Originally Posted by redtop43 View Post
    Even if that's true, it's the only language I know that I could modify the dealing code in.

    Coding is essentially an obsolete skill at this stage. I would purchase a premium level AI and work on your prompt generation. You should find that easy with a background in programming.

    Much easier and 20x faster. You can work with pre-existing code if necessary. Using Github programs like the one suggested above as a base to work from tend to minimize AI errors.
    Last edited by Archvaldor; 03-04-2025 at 11:48 AM.

  11. #11


    Did you find this post helpful? Yes | No
    Quote Originally Posted by Archvaldor View Post
    Coding is essentially an obsolete skill at this stage. I would purchase a premium level AI and work on your prompt generation. You should find that easy with a background in programming.

    Much easier and 20x faster. You can work with pre-existing code if necessary. Using Github programs like the one suggested above as a base to work from tend to minimize AI errors.
    I strongly disagree that AI could do any serious programming for AP work at this stage. I have dabbled with it, and I found it unhelpful except as a glorified code beautifier and documentation creator. I give it code that I have already written, and it does not understand what it is doing. Do you really think that it could write code for optimizing split strategy?

    Are you coding with AI? Do you have any examples of it doing analysis that is beyond what appears on these pages. This is a serious question. I would love to find out what I am missing here.

    I recently received an e-mail from support at an online casino. Yahoo AI summarized it this way:
    "Your XXXXX Bet account will be permanently closed, and you can withdraw your Loyalty Points balance of $XXX.49, but not the remaining account balance."

    This AI summary scared the crap out of me, since I have a very large balance at that site. Here is what the text actually said:

    "Dear XXXXX,

    Following a recent review by our gaming team, it has been determined that your account will be permanently closed with immediate effect.
    Any remaining account balance can be withdrawn.
    You have a Loyalty Points balance of XX,X49.65 which equates to $XXX.49 which you can also withdraw from the XXXXX Bet App.
    This decision is final, will not be overturned and has been made in full accordance with XXXXXX Bet Terms and Conditions which are available here [link].
    We appreciate your understanding,"

    So AI got it totally wrong.

    I found it amusing that the e-mail included a promotional add promising me $100 is I would refer a friend to sign up.






  12. #12


    Did you find this post helpful? Yes | No
    Quote Originally Posted by OnlineAP View Post
    I strongly disagree that AI could do any serious programming for AP work at this stage. I have dabbled with it, and I found it unhelpful except as a glorified code beautifier and documentation creator. I give it code that I have already written, and it does not understand what it is doing. Do you really think that it could write code for optimizing split strategy?

    Are you coding with AI? Do you have any examples of it doing analysis that is beyond what appears on these pages. This is a serious question. I would love to find out what I am missing here.

    I recently received an e-mail from support at an online casino. Yahoo AI summarized it this way:
    "Your XXXXX Bet account will be permanently closed, and you can withdraw your Loyalty Points balance of $XXX.49, but not the remaining account balance."

    This AI summary scared the crap out of me, since I have a very large balance at that site. Here is what the text actually said:

    "Dear XXXXX,

    Following a recent review by our gaming team, it has been determined that your account will be permanently closed with immediate effect.
    Any remaining account balance can be withdrawn.
    You have a Loyalty Points balance of XX,X49.65 which equates to $XXX.49 which you can also withdraw from the XXXXX Bet App.
    This decision is final, will not be overturned and has been made in full accordance with XXXXXX Bet Terms and Conditions which are available here [link].
    We appreciate your understanding,"

    So AI got it totally wrong.

    I found it amusing that the e-mail included a promotional add promising me $100 is I would refer a friend to sign up.






    Big tech services that incorporate AI elements are, as you correctly point out, worthless and/or actively dangerous.

    Check out Claude 3.7. Comparing that to whatever yahoo is using is like night and day.

  13. #13
    Random number herder Norm's Avatar
    Join Date
    Dec 2011
    Location
    The mote in God's eye
    Posts
    12,798
    Blog Entries
    59


    Did you find this post helpful? Yes | No
    Quote Originally Posted by Archvaldor View Post
    Coding is essentially an obsolete skill at this stage.
    That will not be true for quite some time.
    "I don't think outside the box; I think of what I can do with the box." - Henri Matisse

Page 1 of 2 12 LastLast

Similar Threads

  1. David Kuvelas Breaks The Blackjack Code
    By Zaal in forum The Disadvantage Forum
    Replies: 25
    Last Post: 03-26-2019, 12:56 AM
  2. MGP BJ CA Source Code now available on GitHub
    By MGP in forum General Blackjack Forum
    Replies: 8
    Last Post: 03-14-2017, 04:20 PM
  3. Damon: BlackJack Code
    By Damon in forum Blackjack Main
    Replies: 2
    Last Post: 09-30-2001, 12:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

About Blackjack: The Forum

BJTF is an advantage player site based on the principles of comity. That is, civil and considerate behavior for the mutual benefit of all involved. The goal of advantage play is the legal extraction of funds from gaming establishments by gaining a mathematic advantage and developing the skills required to use that advantage. To maximize our success, it is important to understand that we are all on the same side. Personal conflicts simply get in the way of our goals.