BookmarkSubscribeRSS Feed

Simulating a Blackjack Game

Started ‎08-05-2016 by
Modified ‎04-04-2022 by
Views 2,148

This package simulates a blackjack game using multiple functions and modules.
All code must be ran in a proc iml.

Each function in the package is an instrumental part in running the game, and the play_hand() function is the final module that incorporates all functions to actually simualte the game.

The game is based on one player and the dealer and uses the "optimal strategy" in order to maximize the player's winnings. When the play_hand() function is run, SAS will print the dealer's initial face up card, the player's initial hand, the player's next "action", and finally the results of the game which include the player and dealer's hand values along with the player's amount in winnings based on the bet made. The game is set up so that it uses 2 decks of cards.

The functions include:

shuffle_deck which shuffles n number of decks.
shoe which draws m number of cards from the shuffled decks.
new_hand which creates a new hand of cards by drawing m cards from the deck and placing a bet.
hand_value calculates the value of a player's hand of cards.
dealer_hand creates a new hand of cards for the dealer by drawing m cards from the deck.
dealer_hand_value calculates the value of a dealer's hand of cards.
winnings calculates the amount in winnings of the player based on the player and dealer's cards.
print_hand prints out the contents of a hand of blackjack.
hit draws 1 card from the shoe and adds it to the hand.
stand returns the unaltered hand of cards.
dd doubles the amount of the bet, draws an additional card, and returns the new hand.
splitPair can only be used if the 2 cards are the same value, and it splits the cards into 2 separate hands.
strategy_optimal is the strategy we use to simulate this blackjack game. It returns the optimal move the player should make.
play_hand is the ending function that incorportates all of the above functions and actually plays the game of blackjack.

The deck of cards must be loaded into the script before beginning the game.
Also, the dealer and player's hand of cards msut be created using the appropriate functions.

Comments

Really should provide some reason as to why we should bother to look at this.

It sounds really interesting. I wonder whether you were able to build an app or an online game out of it?

Hey there! This package to simulate a blackjack game sounds pretty cool. I'm not much of a blackjack player myself, but I'm curious - how does this differ from the online blackjack games we see all over the place? By the way, I'm on the lookout for some new games to play. I recently discovered Blackout Bingo, and it's been a blast. If you're interested, here's a link to a review I found: https://joywallet.com/article/blackout-bingo-review/. Maybe it could be a fun addition to your project! Anyway, I'm new here, so it's nice to meet you all.

@Casamaretam 

 

SAS/AF and SAS/FSP for SAS 6.8 or 6.12 (been awhile so I can't remember which version) around 1995 shipped with a SAS implementation of video black jack as an example of the programming tools included. Card faces, betting odds, options like doubling and such.

You can access the SAS/AF version of the game through SAS Display Manager.  Launch display manager and on the main menu bar select Solutions-->Accessories--> Games.  There are 6 games you can select: Black Jack, Tic-Tac-Toe, Slots, Solitaire, Jumble, and Poker.

@JimLoughlin 

Requires the SASHELP.GAMES catalog to be installed which is dependent on your licensed products apparently. With these products I do not have that catalog:

---Base SAS Software
---SAS/STAT
---SAS/GRAPH
---SAS/Secure 168-bit
---SAS/Secure Windows
---SAS Enterprise Guide
---SAS/ACCESS Interface to PC Files
---SAS/ACCESS Interface to ODBC
---SAS Workspace Server for Local Access
---High Performance Suite

You probably need SAS/AF.

Version history
Last update:
‎04-04-2022 03:10 PM
Updated by:

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags