Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating hand values in Blackjack

Tags:

c#

blackjack

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.

like image 973
GigaPr Avatar asked Mar 08 '10 15:03

GigaPr


People also ask

How do you score a hand in blackjack?

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.

How do you value cards in blackjack?

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.

What is hand value in blackjack?

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.


1 Answers

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.

like image 141
Dinah Avatar answered Oct 02 '22 07:10

Dinah