I have a small interest in blackjack and the statistics involved with it. I worked in a casino long enough that
I know better than to try and beat the house.
On the other hand, if the dealer has to play to 17, you can win about 1/3 of your hands without drawing a card.
I know that it's been done before, and probably at length, but I want to investigate different strategies for blackjack.
I'm working on the early stages of a blackjack program. It's still in pseudocode, but it's starting to look a lot more
like a blackjack program
and less like a Rube Goldberg blackjack machine.
| A | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | T | J | Q | K |
C | | | | | | | | | | | | | |
D | | | | | | | | | | | | | |
S | | | | | | | | | | | | | |
H | | | | | | | | | | | | | |
When I started with it November 11, 2005, I had plans of making a 2 dimensional array [4x13] and randomly choosing from
it for each draw. After a card was chosen, it's value in the array would change to tell the program not to choose it again. This created
two problems.
- Broken odds
- Inefficient card selection
Broken odds
The first problem with this method is that the only draw with correct odds would be the first with 1/52.
Using the array method, lets pretend we're choosing suit then rank. Each draw, you get a 25% chance of getting a heart.
Still pretending, lets say you get 7 hearts out of the first 12 cards. Your odds of getting a heart in the next draw
should be 6/40 (15%), but
using the array method, you'll always get a chance at a heart 1/4 of the time. This happens on a smaller scale
when you draw rank first.
With my plans of running this hundreds of times to check the odds on different strategies, even a small variance will
kill it.
Inefficient card selection
Also related to my wish to run this at length unattended, I needed to clean up the card selection. Your first card
is always valid, but each card(x)after that, has an x/52 chance of being invalid.
Invalid cards must be redrawn. Simply choosing the next higher card doesn't seem like a problem at first, but it
greatly adds to the problem with skewed odds.
When you're halfway through the deck, you average 2 cards per 3 draws. When you're down to the last few cards, you
could easily draw 20 invalid cards before getting one you can count.
I don't know how many attempted draws it would average to get through a deck, but it would easily be 500, I think.
As of November 20 or so, I "shuffle" the deck with a kind of random bubble sort. I made a system that uses a
natural model to shuffle.
I start with a single dimension array 52 elements long (I might skip this step in the future) and filter the
values into 2 smaller arrays.
Then, (and I'm still working on cleaning up the end of this) I sort the 2 smaller arrays back into the longer one,
starting at the top and randomly
deciding which of the smaller arrays contribute a card to the large one. I've heard that with a real deck, after the
seventh shuffle the cards achieve optimal randomness. Any shuffling after the seventh is unneeded. I may adjust this
after I get a working model coded and can see where the cards end up.
This next part isn't pretty, but it's my current note file.
Reading it now, I don't understand what I meant by some of it.
arr deck(1-52) 0-51 really (don't forget to adjust card,suit
card = deck[x] %13 1=A, 11=J, 12=Q, 13=K
suit = deck[x] %4 1=C, 2=D, 3=H, 4=S
shuffle deck: rnd_bubbly_sort(deck[])*a bunch of times;
draw = read deck[x]; x++ draw from the top of the deck
How many decks?
Starting bet? (0 -> How many hands?)
Increase ?X
if bet
(record ending cash / number of turns)
else
(number of wins / number of turns)
Store card names seperate from values? so J=Q=K=10
Maybe figure card for display then mangle value for score
|
Updates on
Blackjack (page 2). Turns out that the finished product will have almost nothing from the first version :)