Velocity Reviews > Ruby > [QUIZ] Studying Blackjack (#151)

# [QUIZ] Studying Blackjack (#151)

Ruby Quiz
Guest
Posts: n/a

 01-04-2008
The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.rubyquiz.com/

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
if you can.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

The majority of the strategy in Blackjack hinges around the dealer's hand. The
reasons are likely obvious to most of you: that's the hand you have to beat and
the dealer plays by fixed rules we can predict.

For those unfamiliar with Blackjack, you only need to know a tiny bit about the
game for the purposes of this exercise. The goal for both the player and the
dealer is to draw cards to make a hand with the highest total possible, without
going over 21. Going over 21 is called "busting" and it means you lose the
hand. Face cards count for ten, aces are one or eleven (whichever is better for
the hand), and all other cards count for their face value. You start with two
cards and, if they happen to be a ten valued card and an ace (a count of 21),
the hand is called a "natural." A natural is an automatic win in most cases.

The dealer begins with one of his two cards face up and one face down. We call
the former the "upcard." The dealer will "hit" or take more cards until he
reaches a count of 17 or higher. After that he will "stand" or leave the hand
where it is. That tells us that there are only seven possible outcomes for the
dealer: get dealt a natural, bust, or hit to a total of 17, 18, 19, 20, or 21.

We start every hand knowing half of what the dealer holds thanks to the upcard.
Believe it or not, you can make pretty reliable guesses about how the hand will
go with just that knowledge.

Write a Ruby program that shows the percent chance of a dealer reaching each
possible outcome based on the upcard showing.

I'll give you some hints to verify your results. Basic Blackjack strategy
teaches that we should assume the dealer "has a ten in the hole" (as the face
down card). It's not always true, of course, but 17 is a common outcome for a
dealer with an upcard of seven. Finally, we call five and six "the dealer's
bust cards" for reasons that will become obvious if you are outputting correct
percentages.

In the casinos Blackjack is often played with more than one deck shuffled
together. One, two, six, and eight deck games are common. You may want to
offer the option to adjust the deck size your program uses. Either way, let's
default to two decks as an average of what a player will face.

Sharon Phillips
Guest
Posts: n/a

 01-04-2008
> Write a Ruby program that shows the percent chance of a dealer
> reaching each
> possible outcome based on the upcard showing

Are we able to post partial / full outcomes within the 48 hours?

Cheers,
Dave

James Gray
Guest
Posts: n/a

 01-04-2008
On Jan 4, 2008, at 4:27 PM, Sharon Phillips wrote:

>> Write a Ruby program that shows the percent chance of a dealer
>> reaching each
>> possible outcome based on the upcard showing

>
> Are we able to post partial / full outcomes within the 48 hours?

You bet. Feel free.

James Edward Gray II

Chris
Guest
Posts: n/a

 01-05-2008
> > Are we able to post partial / full outcomes within the 48 hours?
> You bet. *Feel free.

Here's mine so far, my first ruby quiz !

Upcard Bust 17 18 19 20 21 Natural
c1 26.20% 16.80% 13.00% 14.20% 13.90% 15.90% 0.00%
c2 38.80% 14.60% 11.40% 11.00% 12.30% 11.90% 0.00%
c3 40.50% 14.40% 13.40% 11.20% 12.00% 8.50% 0.00%
c4 38.00% 15.20% 14.30% 11.70% 10.70% 10.10% 0.00%
c5 42.30% 12.80% 12.30% 11.80% 9.20% 11.60% 0.00%
c6 39.10% 23.50% 10.30% 10.00% 8.80% 8.30% 0.00%
c7 25.60% 35.40% 14.00% 10.70% 6.50% 7.80% 0.00%
c8 23.70% 13.00% 33.60% 16.20% 6.20% 7.30% 0.00%
c9 21.90% 10.50% 11.90% 35.90% 12.90% 6.90% 0.00%
ct 19.40% 12.50% 10.90% 11.20% 31.70% 5.10% 9.20%
cj 19.70% 14.40% 10.60% 12.30% 29.90% 5.80% 7.30%
cq 18.90% 13.50% 10.90% 10.30% 32.20% 6.60% 7.60%
ck 19.50% 12.30% 12.80% 11.10% 31.90% 6.00% 6.40%
ca 14.00% 13.40% 14.40% 13.10% 12.60% 4.10% 28.40%

Seems to satisfy the hints given in the quiz, but I'm still not sure
if I deal with the case where the dealer gets dealt two or more aces
correctly.

Chris

Eric I.
Guest
Posts: n/a

 01-05-2008
Here are my results. I combined the 10 and the face cards in one row
since they're essentially equivalent. And the data was generated by
doing 10,000 deals per upcard.

upcard bust 17 18 19 20 21
natural
------ ------- ------- ------- ------- ------- -------
-------
2 | 35.95% 13.32% 13.17% 13.34% 12.44% 11.78%
0.00%
3 | 37.85% 13.41% 12.93% 11.69% 12.51% 11.61%
0.00%
4 | 40.14% 13.24% 11.86% 12.03% 11.48% 11.25%
0.00%
5 | 41.80% 12.82% 12.32% 11.41% 11.34% 10.31%
0.00%
6 | 41.76% 17.65% 10.59% 10.36% 10.04% 9.60%
0.00%
7 | 26.77% 36.23% 13.53% 8.29% 7.88% 7.30%
0.00%
8 | 24.96% 12.84% 35.69% 12.73% 7.04% 6.74%
0.00%
9 | 22.98% 12.27% 10.69% 35.47% 12.22% 6.37%
0.00%
10 | 21.61% 11.21% 11.68% 11.23% 32.97% 3.55%
7.75%
ace | 11.60% 12.33% 13.03% 13.06% 13.43% 5.27%
31.28%

I do wonder, though, whether the deck is biased somehow when the
dealer deals him/herself since all the players are dealt beforehand.
For example, it seems a player is more likely to consume a sequence of
low cards through consecutive hits than a sequence of high cards. So
depending on the number of players at the table, the cards the dealer
is likely to get may change somewhat. And perhaps the dealer's odds
change further the deeper into the shoe the table gets. Does anyone
know?

Eric

====

Are you interested in on-site Ruby training that uses well-designed,
real-world, hands-on exercises? http://LearnRuby.com

Joe
Guest
Posts: n/a

 01-05-2008
I didn't think it was supposed to be run a specific number of times,
but go over all possibilities.

I was thinking something like this: (with 2 decks of cards)
2 2 2 2 2 2 2 2 3 - 19
2 2 2 2 2 2 2 2 4 - 20
2 2 2 2 2 2 2 2 5 - 21
2 2 2 2 2 2 2 2 6 - bust
2 2 2 2 2 2 2 2 7 - bust

also would these be considered different hands or the same?
2 2 2 2 2 2 2 2 3
2 2 2 2 2 2 2 3 2

I may be wrong though. If that's the case someone correct me.

Joe

On Jan 4, 2008 8:55 PM, Eric I. <(E-Mail Removed)> wrote:
> Here are my results. I combined the 10 and the face cards in one row
> since they're essentially equivalent. And the data was generated by
> doing 10,000 deals per upcard.
>
> upcard bust 17 18 19 20 21
> natural
> ------ ------- ------- ------- ------- ------- -------
> -------
> 2 | 35.95% 13.32% 13.17% 13.34% 12.44% 11.78%
> 0.00%
> 3 | 37.85% 13.41% 12.93% 11.69% 12.51% 11.61%
> 0.00%
> 4 | 40.14% 13.24% 11.86% 12.03% 11.48% 11.25%
> 0.00%
> 5 | 41.80% 12.82% 12.32% 11.41% 11.34% 10.31%
> 0.00%
> 6 | 41.76% 17.65% 10.59% 10.36% 10.04% 9.60%
> 0.00%
> 7 | 26.77% 36.23% 13.53% 8.29% 7.88% 7.30%
> 0.00%
> 8 | 24.96% 12.84% 35.69% 12.73% 7.04% 6.74%
> 0.00%
> 9 | 22.98% 12.27% 10.69% 35.47% 12.22% 6.37%
> 0.00%
> 10 | 21.61% 11.21% 11.68% 11.23% 32.97% 3.55%
> 7.75%
> ace | 11.60% 12.33% 13.03% 13.06% 13.43% 5.27%
> 31.28%
>
> I do wonder, though, whether the deck is biased somehow when the
> dealer deals him/herself since all the players are dealt beforehand.
> For example, it seems a player is more likely to consume a sequence of
> low cards through consecutive hits than a sequence of high cards. So
> depending on the number of players at the table, the cards the dealer
> is likely to get may change somewhat. And perhaps the dealer's odds
> change further the deeper into the shoe the table gets. Does anyone
> know?
>
> Eric
>
> ====
>
> Are you interested in on-site Ruby training that uses well-designed,
> real-world, hands-on exercises? http://LearnRuby.com
>
>

James Gray
Guest
Posts: n/a

 01-05-2008
On Jan 4, 2008, at 8:22 PM, Joe wrote:

> I didn't think it was supposed to be run a specific number of times,
> but go over all possibilities.
>
> I was thinking something like this: (with 2 decks of cards)
> 2 2 2 2 2 2 2 2 3 - 19
> 2 2 2 2 2 2 2 2 4 - 20
> 2 2 2 2 2 2 2 2 5 - 21
> 2 2 2 2 2 2 2 2 6 - bust
> 2 2 2 2 2 2 2 2 7 - bust
>
> also would these be considered different hands or the same?
> 2 2 2 2 2 2 2 2 3
> 2 2 2 2 2 2 2 3 2
>
> I may be wrong though. If that's the case someone correct me.

I think I've heard about two different, but very interesting
strategies to solve this problem. I can't wait to see the code.

James Edward Gray II

James Gray
Guest
Posts: n/a

 01-05-2008
On Jan 4, 2008, at 6:35 PM, Chris wrote:

>>> Are we able to post partial / full outcomes within the 48 hours?

>> You bet. Feel free.

>
> Here's mine so far, my first ruby quiz !

Welcome to the quiz. Glad to have you.

> =85but I'm still not sure if I deal with the case where the dealer =20
> gets dealt two or more aces correctly.

If a dealer has two aces, the first one would be 11 and the second one =20=

a 1 for a total of twelve. Any aces added into the mix would be =20
another one. The original aces would drop to a one if keeping it at =20
11 takes the dealer over 21.

James Edward Gray II=

James Gray
Guest
Posts: n/a

 01-05-2008
On Jan 4, 2008, at 7:55 PM, Eric I. wrote:

> I do wonder, though, whether the deck is biased somehow when the
> dealer deals him/herself since all the players are dealt beforehand.

I believe what you say is true, though I think it's a detail typically
ignored in this kind of strategic analysis.

Google the "cut card effect blackjack" for some interesting (and I

James Edward Gray II

tho_mica_l
Guest
Posts: n/a

 01-05-2008
> Write a Ruby program that shows the percent chance of a dealer
> reaching each possible outcome based on the upcard showing.

I'm sorry for asking this dummy question (and I hope not to spoil it
for
anyone) but all this jargon makes me feel strange and it's early in
the
morning. Do I understand the game right in that:

1. The dealer gets a card
2. If the sum of his cards is < 17, repeat step #1
3. If the sum is >= 17, the result is registered
4. If the dealer has 6 + Ace, he stops and doesn't try to get a 4
or
something lower?

The set of possible cards is limited to 2 decks, i.e. 2 * 13 (2..10,
B,
D, K, A) cards by default.

A set of two card decks contains two 2s?

The probabilities for 10, B, D, K should be all the same since they
all
count 10 and removing them from the card set results in the same
probability
to get another card with a value of 10 for each of them?