I am implementing a little Black Jack game in C# and I have the following problem calculating the player's hand value. Aces may have a value of 1 or 11 based on the player's hand. If the player has three cards and one ace, then if the sum of the cards is <= 10 the ace will have value of 11, otherwise it will have a value of 1.
Now lets assume I do not know how many aces the player has got and the game is implemented giving the possibility to the dealer to use more than one deck of cards. The user may have in one hand even 5, 6, 7, 8... aces.
What is the best way (possibly using Linq) to evaluate all the aces the player has got to get the closest combination to 21 (in addition to the other cards)?
I know the players' cards and I want to calculate their values, using the aces to reach the closest value to 21.
Blackjack hands are scored by their point total. The hand with the highest total wins as long as it doesn't exceed 21; a hand with a higher total than 21 is said to bust. Cards 2 through 10 are worth their face value, and face cards (jack, queen, king) are also worth 10.
Face cards each count as 10, Aces count as 1 or 11, all others count at face value. An Ace with any 10, Jack, Queen, or King is a “Blackjack.” If you have a Blackjack, the dealer pays you one-and-a-half times your bet — unless the dealer also has a Blackjack, in which case it's a “push” and neither wins.
The value of a Blackjack hand is the sum of the values of the cards. The goal of the game is to achieve a hand with a value as close to 21 as possible without exceeding 21. It's pretty simple, unless there is an Ace involved.
Add up the value of all the non-aces and add the number of aces: 2, Q, A, A = 2 + 10 + (2) = 14
Then subtract that from 21: 21 - 14 = 7
Is this number less than 10 (if only 1 ace == 11)? Less than 20 (if both aces == 11)?
Since this feels like homework, this is intentionally not the complete answer but should guide you along.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With