On 6 Jan 2008, at 22:40, James Gray wrote: > On Jan 6, 2008, at 3:03 PM, Denis Hennessy wrote: > >> The understanding I had was that a dealer could 're-value' their >> hand with each card dealt; that is - if they draw two aces they're >> obviously 11 and 1 and they have to hit again. If they then draw a >> card which would cause them to bust, they can treat both aces as 1. > > You have all of that right, but Eric was saying you don't properly > value hands with multiple aces in them. For example, ace, ace, and > ten should value as 12, not 22. > > One way I've handled this in the pass was to sort the hand such that > aces are at the end, run through building up a total, and count an > ace as 11 when I passed it if doing so would keep the running count > less than or equal to 21 minus the cards left to count. > > Hope that makes sense. > > James Edward Gray II > Actually, I think my code is correct, but I might be snow-blind. Here's the relevant function. It values all the non-ace cards first and then values the aces. def hand_value(hand) value = 0 # First calculate values ignoring aces hand.each do |c| if c=='A' next elsif 'JQK'.include? c value += 10 else value += c.to_i end end # Then add aces as 11 unless they would bust the hand hand.each do |c| if c=='A' if value>10 value += 1 else value += 11 end end end value end /dh