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.
Declare the enumerations
Suit introduced in the previous chapter. Give both a raw type of
String and assign each case its corresponding
Add a computed property
Rank. This property replaces the
values dictionary that the solution currently uses.
Declare an enumeration
Action to represent the actions a player can take. These are:
- double down
- answer yes
- answer no
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
"hit" to select action
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.
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.