Question: Question 6 _ _ _ ( 4 ) Create a _ _ _ function _ _ _ called ` payout ` with three _ _

Question 6___(4)
Create a ___function___ called `payout` with three ___arguments___: `player_score`,`dealer_score` and `bet`. Assign a default ___value___ of `1` to the ___argument___`bet`. The goal of the ___function___`payout` is to ___return___ the amount that the player should receive (positive number) or pay-in (negative number) based on the values passed to the `player_score`,`dealer_score` and `bet`___arguments___. The final amount should be returned as a single ___numeric___ value. For example, if the player wins without blackjack the function should return 1\*bet; implying that the player wins 1\*bet in this round.
Game Actions
We now have a way to define a deck of cards, draw a card, determine the score of a hand and determine the final payout. Next, we focus on implementing the actions in a game of blackjack.
In blackjack, the player performs his/her actions first. Once the player has performed their actions, it is the dealers turn to perform actions. After the dealer has performed his/her actions, the game is concluded and the payout is determined.
The action that a player should take is based on their cards and the first card dealt to the dealer where the first card dealt to the dealer is visible to the player.
## Player actions
Depending on the rules used in blackjack, a player can have multiple actions available. We will simplify the problem by only considering the actions hit and stand.
1. When a player requests a hit, one card is drawn from the deck and added to the hand of the player
2. When a player chooses to stand, the turn of the player ends.
___Question 7___(2)
Define a ___function___ called `hit`. The ___function___`hit` has only one ___argument___,`hand`. When the ___function___`hit` is ___called___ the ___function___ should add a card to the vector passed to the `hand`___argument___ using the ___function___`draw_a_card` defined in ___question 3___. The ___function___`hit` should ___return___ the original vector passed to the ___argument___`hand` with a new card added to the last position of the vector.
Dealer actions
Once the player chooses to `stand` or `bust` as a result of `hitting`, it is the dealers turn to play. According to the rules of blackjack, the dealer __must__ perform the action `hit` when the hand value of the dealer is less than 17.
___For our game, the dealer performs the action `hit` when the hand value of the dealer is less than 18.___
___Question 8___(4)
Create a ___function___ called `dealer_strategy`. The ___function___`dealer_strategy` has only one ___argument___,`hand`. The ___function___`dealer_strategy` should ___call___ the ___function___`hit` defined in ___question 7___ until the dealer score is more than 18 or the dealer `bust`. Note based on the value passed to the `hand`___argument___, the ___function___`hit` might be not be called, called once or called more than once.
Game agent
Now that we have implemented the game mechanics we can start by implementing an artificial agent the player. To implement the artificial agent, we will make use of a lookup table to determine when the agent should perform the action `hit` or when the agent should perform the action `stand`.
We can implement a lookup table in R using a ___data frame___. The ___data frame___ will be used to determine if the player should perform the action `hit` or `stand` based on:
1._hand_value_: The sum of the cards in the player hand i.e. column hand_value
2._useable_ace_: Whether the hand of the player contains a useable ace, an ace than can count as 11 without the player going `bust`(column: usable_ace)
3._dealer_ace_ to _dealer_ten_: the face-up card of the dealer
Two lookup tables have been created, `df_action_lookup` and `df_action_lookup_alt`.
`df_action_lookup` is the player's default strategy, while `df_action_lookup_alt` serves as the alternative strategy
___Question 9___(6)
Create two functions that the player may use to implement their strategy.
Create a ___function___ called `lookup_action` with two ___arguments___`hand` and `dealer_card`. The ___function___`lookup_action` should ___return___ whether the player should "Hit" or "Stand" using the ___data frame___`df_action_lookup`.
Create another ___function___ called `lookup_action_alt` with the same arguments as `lookup_action`. The ___function___`lookup_action_alt` should ___return___ whether the player should "Hit" or "Stand" using the ___data frame___`df_action_lookup_alt`

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!