Question: Question 6 _ _ _ ( 4 ) Create a _ _ _ function _ _ _ called ` payout ` with three _ _
Question
Create a function called payout with three arguments: playerscoredealerscore and bet Assign a default value of to the argumentbet The goal of the functionpayout is to return the amount that the player should receive positive number or payin negative number based on the values passed to the playerscoredealerscore and betarguments The final amount should be returned as a single numeric value. For example, if the player wins without blackjack the function should return bet; implying that the player wins 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 hisher actions first. Once the player has performed their actions, it is the dealers turn to perform actions. After the dealer has performed hisher 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.
When a player requests a hit one card is drawn from the deck and added to the hand of the player
When a player chooses to stand the turn of the player ends.
Question
Define a function called hit The functionhit has only one argumenthand When the functionhit is called the function should add a card to the vector passed to the handargument using the functiondrawacard defined in question The functionhit should return the original vector passed to the argumenthand 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
For our game, the dealer performs the action hit when the hand value of the dealer is less than
Question
Create a function called dealerstrategy The functiondealerstrategy has only one argumenthand The functiondealerstrategy should call the functionhit defined in question until the dealer score is more than or the dealer bust Note based on the value passed to the handargument the functionhit 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:
handvalue: The sum of the cards in the player hand ie column handvalue
useableace: Whether the hand of the player contains a useable ace, an ace than can count as without the player going bustcolumn: usableace
dealerace to dealerten: the faceup card of the dealer
Two lookup tables have been created, dfactionlookup and dfactionlookupalt
dfactionlookup is the player's default strategy, while dfactionlookupalt serves as the alternative strategy
Question
Create two functions that the player may use to implement their strategy.
Create a function called lookupaction with two argumentshand and dealercard The functionlookupaction should return whether the player should "Hit" or "Stand" using the data framedfactionlookup
Create another function called lookupactionalt with the same arguments as lookupaction The functionlookupactionalt should return whether the player should "Hit" or "Stand" using the data framedfactionlookupalt
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
