Thursday, December 6, 2007

Blackjack Simulation

I'm working on a simulation of Blackjack to remind myself of how a program with business logic would be constructed. There are a couple of simple classes in package casino, including Dealer, Shoe, Card, Table, Player, Hand, Chips (aka Bank), Door, and optionally Cashier for converting from one type of currency to another.

Players enter the casino through the Door with a certain amount of money in their personal Bank, case the Tables which each have a single Dealer and Shoe, and a finite number of seats. Player joins a Table and places a bet. Each Player Hand is dealt from the Shoe, then a brief exchange between Player and Dealer decides whether any more cards are dealt into that Hand. The process is repeated with the next Player until the value of each Hand is determined.

The Dealer then completes the transaction by dealing out his own Hand, comparing the value of each other Hand on the Table to his own Hand, and making any necessary adjustments to each player's Bank. Players decide whether to play another Hand, either placing a new bet or leaving the Table, and for as long as this pattern continues another Hand is dealt for every bet. When a Player has had enough, he can proceed to the Cashier and/or leave out the Door with his money.

With the assumption that not every Player is smart, we can fairly assume that the casino will not run out of money and it is almost pointless to maintain a central bank; you can only watch as the balance increases, and as it rises, so does the number of Players who have been bankrupted by the house. This is not the goal of a good casino, and such a statistic would only serve to make the owner feel guilty! Adjust the scenario to allow smart players who can count cards, adjusting their bets based on the probability of winning each hand, and your casino owner may begin to feel compelled to introduce door guards and pit bosses.

The simulation results will tell us if the reasonable casino owner has real cause to be concerned.

2 comments:

yebyen said...

Why oh why would I make a post about a codebase and neglect to include a link to the mentioned codebase? Oh yeah, because you actually need a username and password on my Subversion server to access this code.

svn.tuesdaystudios.com/tuesday/West/

It's OK if you want to see what I'm building, I give these credentials out like toilet paper. Actually, if you're not interested in making a contribution, you don't even have to contact me! Use the WebSVN interface to check out my published work from The West Group!

JJ said...

I’ve always been sceptical about gambling. At University friends did a lot in the casinos in the city and lost a load of cash to some dodgy people and places. But eventually a friend said “Play online casino”, and I agreed to give it a go (after about four hours and debating the risks). So I signed up and played my first game of online casino blackjack, I lost but it was fun! Kept playing and was lucky enough to break even until I got the hang of it!
Has anybody got any tips or any success stories?