### What is Blackjack?

Blackjack is a popular card game played in many casinos. The player plays against the dealer aiming to reach 21 points, or a score higher than the dealer without exceeding 21. The values of the cards in Blackjack are as follows:

• Aces can be either 1 or 11 points (the player decides);
• Face cards (i.e., Jack, Queen, and King) are 10 points;
• All the remaining cards have their scores equal to their numbers (e.g., 2 is 2, 3 is 3, and so on).

The game can be played with one or several decks of 52 cards. We will use a single deck of 52 cards in our version of Blackjack.

### Our simplified version

At the start of the game, the player and the dealer are dealt two cards each:

• both of the players cards are dealt face up;
• one of the dealers card (called the hole card) is dealt face down, and the other one face up.

Then, its the players turn:

• he can choose to ask the dealer to repeatedly hit his hand by dealing him one card at a time;
• each time the player presses hit, the points corresponding to the dealt card are added to the players hand value;
• if the value of the players hand exceeds 21, he busts and loses immediately;
• if he decides to stop before he busts, we say that he stands and its the dealers turn.

If the player has decided to stand, its the dealers turn:

• the dealer reveals its hole card;
• he proceeds by dealing more cards to himself until the value of his hand is 17 or higher;
• if the value of the dealers hand is higher than 21, then the dealer is busted and loses immediately;
• otherwise, the values of the players and the dealers hands are compared against each other, and the hand with the higher value wins;
• the ties are resolved in favor of the dealer.

The program decides the values of aces. Each time an ace is dealt to a hand:

• if setting its value to 11 doesnt bust the hand, then the value of the ace is 11;
• otherwise the program sets the value of the ace to 1.

### The games GUI

The games GUI consists of the following elements:

• three buttons, Deal, Hit, and Stand;
• a text field with the name of the game;
• a text field for displaying the score;
• text fields demarcating the players and dealers areas of the game table;
• the players cards and the dealers cards;
• a text field to display the messages Hit or stand?, You Bust! New deal? and You win! New deal? (you can modify this messages or add other ones, if it does not change the basic functionality of the game).

This picture represents a possible layout for Blackjack: See image.

To see it in action, you can take a look at an example of Blackjack from Codeskulptor being played on YouTube: https://www.youtube.com/watch?v=eCPXzdrz8i0 Observe how the cards seem to fly from the deck to the hands on the table. You wont have to do that, but your game will look pretty cool if you do.

### Assets

You will need sprites for the program:

• the deck is in http://jfitz.com/cards/windows-playing-cards.png
• the back of the card is in http://jfitz.com/cards/b2fv.png

### Game logic

The following state diagram represents the logic of the game: See image.

### Global constants

In order to simplify the structure of the code, you should declare the following constants at the beginning of your program (you can, of course, declare other constants, like for instance the dimensions of the canvas, the dimensions of the cards, as well as some colours or font sizes):

• a constant SUITS keeps a tuple with all the available suits;
• a constant RANKS keeps a tuple with all the available ranks;
• a constant VALUES keeps a dictionary with the values of the cards.

### The classes

Your implementation of Blackjack should have at least the following classes. For each one you have a list of the minimal required functionalities, feel free to add anything that will help you write clean code.

Card:

• each card is an object of the class Card;
• its initializer sets the suit and the rank of the card;
• the class should have a method to draw the card on the canvas;
• the class should have a method to get the value of a card.

Deck:

• the deck is kept in a list with all the 52 cards;
• when a card is dealt it should be removed from the deck;
• the deck should be shuffled using the shuffle function from the random module.

Hand:

• each player belongs to this class, which means that you will have two objects of the class Hand, player and dealer;
• the class should have a method that adds cards to the hand;
• the class should have a method to draw the card on the canvas;
• the class should have a method to return the value of the hand;
• the class should have a method that returns a Boolean indicating if the hand is busted.

Game:

• this class will be used to wrap all the remaining aspects of the game;
• you should keep all your state variables in this class and query them from the game loop;
• you can also encapsulate the game loop in this class, but you wont have too.

### Scoring

The score counts the players balance of wins and losses:

• he is awarded 1 point for each game he wins (the dealer busts);
• he loses 1 point for each time he busts, or when the total value of his cards is equal to the total value of the cards of the dealer.

For example, the score of -1 may result from the player winning 5 games and losing 6 games.