Exercises 8 β
In this exercise series, youβll revisit Blackjack and declare three enumerated types you can use to improve its implementation.
Before you begin, familiarize yourself with the solution project for Blackjack. Youβll use this project as your starting point.
Exercise 8.1 β
Declare the enumerations Rank
and Suit
introduced in the previous chapter. Give both a raw type of String
and assign each case its corresponding String
value.
Exercise 8.2 β
Add a computed property value
to Rank
. This property replaces the values
dictionary that the solution currently uses.
Exercise 8.3 β
Declare an enumeration Action
to represent the actions a player can take. These are:
- hit
- stand
- double down
- split
- answer yes
- answer no
Exercise 8.4 β
Add a description
property to Action
that describes the input expected for each action. For example, you can return "(h)it"
to indicate that the player should type either "h"
or "hit"
to select action hit
.
Exercise 8.5 β
Add an initializer to Action
that converts the playerβs input to one of the actions. Return nil
if the input doesnβt match any of the actions.
Exercise 8.6 β
Improve the solution project for Blackjack using structures and enumerations, similar to what you did for Tic-Tac-Toe in Programming with Structures and Enumerations.
Use the enumerations you declared in the previous exercises, identify and declare any other types you need, and give the implementation a complete overhaul.
Also, audit your types for encapsulation. Think about which members a type should expose and mark all others as private.