In this exercise we will simulate the first turn of a Blackjack game.
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:
| card | value | card | value |
|---|---|---|---|
| ace | 11 | eight | 8 |
| two | 2 | nine | 9 |
| three | 3 | ten | 10 |
| four | 4 | jack | 10 |
| five | 5 | queen | 10 |
| six | 6 | king | 10 |
| seven | 7 | other | 0 |
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.
Implement the method Blackjack.parse_card which takes a card as a string as an argument.
The method should return the value of the card as an integer.
Blackjack.parse_card("ace")
# => 11The player score has to be categorized into ranges of values. Player scores are computed by adding up the values of the two player cards. The ranges that are used are:
| range | value |
|---|---|
| low | [4, 11] |
| mid | [12, 16] |
| high | [17, 20] |
| blackjack | [21] |
Implement the method Blackjack.card_range which takes two cards as strings as arguments.
The method should return the name of the range of values the two cards fall into.
Blackjack.card_range("ten", "king")
# => "high"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:
Although not optimal yet, you will follow the strategy your friend Alex has been developing, which is as follows:
Implement the method Blackjack.first_turn which takes three cards as strings as arguments.
The method should return the decision you should take as a string.
Blackjack.first_turn("ace", "ace", "two")
# => "P"In this exercise we will simulate the first turn of a Blackjack game.
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:
| card | value | card | value |
|---|---|---|---|
| ace | 11 | eight | 8 |
| two | 2 | nine | 9 |
| three | 3 | ten | 10 |
| four | 4 | jack | 10 |
| five | 5 | queen | 10 |
| six | 6 | king | 10 |
| seven | 7 | other | 0 |
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.
Implement the method Blackjack.parse_card which takes a card as a string as an argument.
The method should return the value of the card as an integer.
Blackjack.parse_card("ace")
# => 11The player score has to be categorized into ranges of values. Player scores are computed by adding up the values of the two player cards. The ranges that are used are:
| range | value |
|---|---|
| low | [4, 11] |
| mid | [12, 16] |
| high | [17, 20] |
| blackjack | [21] |
Implement the method Blackjack.card_range which takes two cards as strings as arguments.
The method should return the name of the range of values the two cards fall into.
Blackjack.card_range("ten", "king")
# => "high"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:
Although not optimal yet, you will follow the strategy your friend Alex has been developing, which is as follows:
Implement the method Blackjack.first_turn which takes three cards as strings as arguments.
The method should return the decision you should take as a string.
Blackjack.first_turn("ace", "ace", "two")
# => "P"