Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create an _ _ _ atomic vector _ _ _ ca lled ` deck ` . The _ _ _ object _ _ _ `
Create an atomic vector ca
lled deck The objectdeck should store elements of type integer Each element stored in the objectdeck represents a card of the deck and is represented by its value. For example, the vectorcLLLL represents the cards ace, two, three and four. The order of the cards are not important.
r Question echoTRUE
# Complete the following code
r Questiontest, echoTRUE, evalFALSE
# TEST CODE
# DO NOT EDIT
if lengthdeck stopThe object deck does not contain elements"
if typeofdeck "integer" stopThe object deck does not contain integer values"
if sumdeck stopThe values of the cards contained in the deck are incorrect"
if allsapplydeck iselement, set c:
stopThe values of the cards contained in the deck are incorrect"
allsapplydeck iselement, set : #are all values TRUE?; iselementx y is the same as x in y
Given a deck of cards, we require a method to draw a card from the deck.
Question
Write a function called drawacard with one argumentdeck The functiondrawacard should return the last element of the value passed to the deck argument
r Question echoTRUE
# Complete the following code
r Questiontest, echoTRUE, evalFALSE
# TEST CODE
# DO NOT EDIT
if drawacardc
stopThe function does not return the last element"
if lengthdrawacard stopThe function returns more than one value"
While the function defined in question will allow you to draw or select a card from the objectdeck the function will always return the same card. In a normal game of blackjack, the deck will first be shuffled before a card is drawn. We will simplify the functionality of drawing a card, by simply selecting a random card from the values passed to the deckargument of the functiondrawacard each time the functiondrawacard is called
Question
Modify the functiondrawacard created in question to return one random card from the values passed to the deckargument Use the functionsample inside the functiondrawacard to return a random card from the deck.
r Question echoTRUE
# Complete the following code
r Questiontest, echoTRUE, evalFALSE
# TEST CODE
# DO NOT EDIT
set.seed
if drawacardc drawacardc stopRandom selection is not performed" #two random draws with the same seed should result in the same draw
Blackjack is played between a player and a dealer. When the game starts both the player and dealer is dealt two cards each.
Question
Use the functiondrawacard developed in question to assign two cards to the object playerhand The object playerhand should be an atomic vector that stores values as integers
r Question echoTRUE
# Complete the following code
r Questiontest, echoTRUE, evalFALSE
# TEST CODE
# DO NOT EDIT
if typeofplayerhand "integer"
stopThe object playerhand does not contain integer values"
if lengthplayerhand stopThe object playerhand does not contain elements"
The objectdealerhand can be defined in the same way as the objectplayerhand For now, we will skip defining the objectdealerhand as the logic is similar to the objectplayerhand
# Determining the winner
In blackjack, a player wins the round if the score of the player is greater than the score of the dealer given that the score of the player does not exceed The score of the player and the score of the dealer is computed in the exact same way. The score of a hand can be computed as follows:
If the total value sum of values of cards in a hand exceeds known as a bust, assign a score of to the hand
If a hand has an ace and the total value of the cards in hand is or less with the ace counting count an ace as the value and not a when computing the total value of cards
If a hand contains exactly two cards and the total value of cards in a hand is equal to known as a "blackjack", assign a value of to the hand
Question
Create a function called scorehand with a single argumenthand The functionscorehand should compute the score of a hand based on the logic described above. The function should return the score as a single numeric value
r Question echoTRUE
# Complete the following code
r Questiontest, echoTRUE, evalFALSE
# TEST CODE
# DO NOT EDIT
testcards listc c c
c c
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started