|
| 1 | +In this exercise we will simulate the first turn of a [Blackjack](https://en.wikipedia.org/wiki/Blackjack) game. |
| 2 | + |
| 3 | +You will receive two cards and will be able to see the face up card of the dealer. All cards are represented using a string such as "ace", "king", "three", "two", etc. The values of each card are: |
| 4 | + |
| 5 | +| card | value | card | value | |
| 6 | +| :---: | :---: | :---: | :---: | |
| 7 | +| ace | 11 | eight | 8 | |
| 8 | +| two | 2 | nine | 9 | |
| 9 | +| three | 3 | ten | 10 | |
| 10 | +| four | 4 | jack | 10 | |
| 11 | +| five | 5 | queen | 10 | |
| 12 | +| six | 6 | king | 10 | |
| 13 | +| seven | 7 | other | 0 | |
| 14 | + |
| 15 | +**Note**: Commonly, aces can take the value of 1 or 11 but for simplicity we will assume that they can only take the value of 11. |
| 16 | + |
| 17 | +Depending on your two cards and the card of the dealer, there is a strategy for the first turn of the game, in which you have the following options: |
| 18 | + |
| 19 | + - Stand (S) |
| 20 | + - Hit (H) |
| 21 | + - Split (P) |
| 22 | + - Automatically win (W) |
| 23 | + |
| 24 | +Although not optimal yet, you will follow the strategy your friend Alex has been developing, which is as follows: |
| 25 | + |
| 26 | +Category: Large Hand |
| 27 | + |
| 28 | +- If you have a pair of aces you must always split them. |
| 29 | +- If you have a Blackjack (two cards that sum up to a value of 21), and the dealer does not have an ace, a figure or a ten then you automatically win. If the dealer does have any of those cards then you'll have to stand and wait for the reveal of the other card. |
| 30 | + |
| 31 | +Category: Small Hand |
| 32 | + |
| 33 | +- If your cards sum up to 17 or higher you should always stand. |
| 34 | +- If your cards sum up to 11 or lower you should always hit. |
| 35 | +- If your cards sum up to a value within the range [12, 16] you should always stand unless the dealer has a 7 or higher, in which case you should always hit. |
| 36 | + |
| 37 | +The overall logic has already been implemented. You have four tasks: |
| 38 | + |
| 39 | +## 1. Calculate the score of any given card. |
| 40 | + |
| 41 | +Implement a function to calculate the numerical value of a card given its name using coditionals. |
| 42 | + |
| 43 | +```java |
| 44 | +parseCard("ace") |
| 45 | +// returns 11 |
| 46 | +``` |
| 47 | + |
| 48 | +## 2. Determine if two cards make up a Blackjack. |
| 49 | + |
| 50 | +Implement a function that returns `true` if two cards form a Blackjack, `false` otherwise. |
| 51 | + |
| 52 | +```java |
| 53 | +isBlackjack("queen", "ace") |
| 54 | +// returns true |
| 55 | +``` |
| 56 | + |
| 57 | +## 3. Implement the decision logic for hand scores larger than 20 points. |
| 58 | + |
| 59 | +Implement a function that returns the string representation of a decision given your cards. This function is only called if the `handScore` is larger than 20. It will receive 2 arguments: `isBlackJack` and `dealerScore`. It should implement the bulletpoints in the category "Large Hand" above. |
| 60 | + |
| 61 | +```java |
| 62 | +isBlackJack = true |
| 63 | +dealerScore = 7 |
| 64 | +largeHand(isBlackJack, dealerScore) |
| 65 | +// returns "W" |
| 66 | +``` |
| 67 | + |
| 68 | +## 4. Implement the decision logic for hand scores with less than 21 points. |
| 69 | + |
| 70 | +Implement a function that returns the string representation of a decision given your cards. This function is only called if the `handScore` is less than 21. It will receive 2 arguments: `handScore` and `dealerScore`. It should implement the bulletpoints in the category "Small Hand" above. |
| 71 | + |
| 72 | +```java |
| 73 | +handScore = 15 |
| 74 | +dealerScore = 12 |
| 75 | +SmallHand(handScore, dealerScore) |
| 76 | +// returns "H" |
| 77 | +``` |
0 commit comments