[Tutor] How do you define the value of ACE in black jack

Magnus Lycka magnus@thinkware.se
Tue Feb 18 06:14:24 2003


Someone suggested a Card class, but whether the ace is 1 or 11 in
black jack depends on the context, on the whole hand. So it's
the hand of cards that needs to know the calculation rules, not
the individual cards. It's a long time since I played BJ, but if
I remember correctly, the rules are more advanced than ace having
two possible values. For instance an ace and a 10 (K, Q, J or 10)
is a black jack, which gives a bigger win than three sevens which
is just 21. See for instance
http://www.thefinerlife.com/games_library/blackjack_rules.htm

To perform the calculations, it's enough to get a list of
numerical values, say [11, 11] (for two aces). We might
well have a hand class that contains the hand and performs
the calculation, but it will also work well to keep the
values in a simple list, and use a simple function to do
the calculation. It could look a bit like this:

def calcHandValue(hand):
     value = sum(hand)
     if value >= FAT and ACE_HIGH in hand:
         hand[hand.index(ACE_HIGH)] = ACE_LOW
     return sum(hand)

With the lacking sum function and constants defined, this
will enable something like:

 >>> h = [11, 11]
 >>> print h
[11, 11]
 >>> print calcHandValue(h)
12
 >>> print h
[1, 11]

We could also use list looking like this:
[('Ace of Clubs', 1), ('Ace of Spades', 11)]
or if you wish a Card class that can contain
both the numeric value and the description,
but as I said, the heart of the matter is in
the hand of cards, not in a card itself.

Back to the review...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se