• Black Friday Sale: Use coupon code THANKSGIVING to get 50% OFF on all our courses.
    If you already have a subscription and still interested in taking advantage of this offer, you can buy now and apply in your future subscriptions. This offer is also valid on GIFTS. Click here to get this offer.

  • Our one of a kind Low Level Design course is now released for General Availability. Go check it out.





Playing cards:

In playing cards, pips are small symbols on the front side of the cards that determine the suit of the card and its rank. For example, a standard 52-card deck consists of four suits of thirteen cards each: Spades, Hearts, Clubs, and Diamonds.

In a deck of playing cards, the term face card or court card is generally used to describe a card that depicts a person as opposed to the pip cards. They are also known as picture cards. Each suit contains three face cards – the Jack, Queen, and King. The remaining ten cards are called pip cards and are numbered from one to ten. (The "one" is almost always changed to "ace" and often is the highest card in many games, followed by the face cards.) Pip cards are also known as numerals or numeral cards.

So to summarize: Cards with value 1 to 10 are called pip cards, with the card with 1 being an Ace. Face cards are Jack, Queen and King and have value 10, 11 and 12 respectively.

Deck

The pack of 52 cards is called a deck.

Deal

The process of handing the cards to the players is called Card Dealing. The person who deals cards is called Dealer.

Hand

All the card belonging to a player after cards are dealt, form a hand for that player.

Each card also has a certain value which differs from game to game, for example, the values of the cards would be diferent in Poker than in BlackJack. These values are different from the face value of the cards. Face value for a card is always the same:
  • 1 for Ace, or
  • a number 2 through 10, or
  • 11 for Jack, or
  • 12 for Queen, or
  • 13 for King




Design the data structures to represent a deck of cards.

Solution:



This is a Premium Content.
Please subscribe to Low Level Design course to access the content.




BlackJack:

BlackJack is also known as Twenty-One. The standard 52-card pack is used in BlackJack.

Today, Blackjack is the one card game that can be found in every American casino. As a popular home game, it is played with slightly different rules. In the casino version, the house is the dealer (a "permanent bank"). In casino play, the dealer remains standing, and the players are seated. The dealer is in charge of running all aspects of the game, from shuffling and dealing the cards to handling all bets. In the home game, all of the players have the opportunity to be the dealer.

OBJECTIVE OF THE GAME:

Each participant attempts to beat the dealer by getting a count as close to 21 as possible, without going over 21.

CARD VALUES:

It is up to each individual player if an ace is worth 1 or 11. Face cards are 10 and any other card is its pip value.

BETTING:

Before the deal begins, each player places a bet, in chips, in front of them in the designated area. Minimum and maximum limits are established on the betting, and the general limits are from $2 to $500.

SHUFFLE:

The dealer thoroughly shuffles the pack of cards.

THE DEAL:

When all the players have placed their bets, the dealer gives one card face up to each player in rotation clockwise, and then one card face up to themselves. Another round of cards is then dealt face up to each player, but the dealer takes the second card face down. Thus, each player except the dealer receives two cards face up, and the dealer receives one card face up and one card face down.

NATURALS or BLACKJACK:

If a player's first two cards are an ace and a "ten-card" (a picture card or 10), giving a count of 21 in two cards, this is a natural or "blackjack." If any player has a natural and the dealer does not, the dealer immediately pays that player one and a half times the amount of their bet. If the dealer has a natural, they immediately collect the bets of all players who do not have naturals, (but no additional amount). If the dealer and another player both have naturals, the bet of that player is a stand-off (a tie), and the player takes back his chips. If the dealer's face-up card is a ten-card or an ace, they look at their face-down card to see if the two cards make a natural. If the face-up card is not a ten-card or an ace, they do not look at the face-down card until it is the dealer's turn to play.

THE PLAY:

The player to the left goes first and must decide whether to "stand" (not ask for another card) or "hit" (ask for another card in an attempt to get closer to a count of 21, or even hit 21 exactly). Thus, a player may stand on the two cards originally dealt to them, or they may ask the dealer for additional cards, one at a time, until deciding to stand on the total (if it is 21 or under), or goes "bust" (if it is over 21). In the latter case, the player loses and the dealer collects the bet wagered. The dealer then turns to the next player to their left and serves them in the same manner. The combination of an ace with a card other than a ten-card is known as a "soft hand," because the player can count the ace as a 1 or 11, and either draw cards or not. For example with a "soft 17" (an ace and a 6), the total is 7 or 17. While a count of 17 is a good hand, the player may wish to draw for a higher total. If the draw creates a bust hand by counting the ace as an 11, the player simply counts the ace as a 1 and continues playing by standing or "hitting" (asking the dealer for additional cards, one at a time).

THE DEALER'S PLAY:

When the dealer has served every player, the dealers face-down card is turned up. If the total is 17 or more, it must stand. If the total is 16 or under, they must take a card. The dealer must continue to take cards until the total is 17 or more, at which point the dealer must stand. If the dealer has an ace, and counting it as 11 would bring the total to 17 or more (but not over 21), the dealer must count the ace as 11 and stand. The dealer's decisions, then, are automatic on all plays, whereas the player always has the option of taking one or more cards.

Summarization of Basic BlackJack Rules:

  • The goal of blackjack is to beat the dealer's hand without going over 21.
  • Face cards are worth 10. Aces are worth 1 or 11, whichever makes a better hand.
  • Each player starts with two cards, one of the dealer's cards is hidden until the end.
  • To 'Hit' is to ask for another card. To 'Stand' is to hold your total and end your turn.
  • If you go over 21 you bust, and the dealer wins regardless of the dealer's hand.
  • If you are dealt 21 from the start (Ace & 10), you got a blackjack.
  • Blackjack usually means you win 1.5 the amount of your bet. Depends on the casino.
  • Dealer will hit until his/her cards total 17 or higher.
Design the data structures for BlackJack.

Solution:



This is a Premium Content.
Please subscribe to Low Level Design course to access the content.




The above content is written by:

Abhishek Dey

Abhishek Dey

A Visionary Software Engineer With A Mission To Empower Every Person & Every Organization On The Planet To Achieve More

Microsoft | University of Florida

View LinkedIn profile


If you have any feedback, please use this form: https://thealgorists.com/Feedback.




Subscribe to Our Youtube Channel

Follow Us On LinkedIn
wave