Question

Function Name: jackSparrow Inputs: 1. (double) A 1x2 vector describing your hand 2. (double) A 1x2 vector describing Jack SpaContinued... Example: myHand [2 6] sparrowHand= [4 8] deck [6 4 4 8 7 2] winner jackSparrow(myHand, sparrowHand, deck) At the

MATLAB code help!

Function Name: jackSparrow Inputs: 1. (double) A 1x2 vector describing your hand 2. (double) A 1x2 vector describing Jack Sparrow's hand 3. (double) A vector with the next cards to be drawn from the deck Outputs: 1. (char) A description of the game outcome Background: You're out at sea with the infamous Jack Sparrow, and it's a pretty calm day. Without anything better to do, Jack Sparrow challenges you to his favorite card game: BlackJack (Sparrow edition) Function Description: In BlackJack (Sparrow edition), each player wants their cards to add up to the higher number without going over 21 (Hornswoggling). You will start with two cards, and can heave ho (take another card) or scuttle (keep your hand) until you are satisfied or you reach a score of over 21. Since Jack Sparrow likes to go big or go home, aces always count as 11. 2-10 count as their respective values, and there will be no face cards. You are given a vector describing your hand of two cards. You can see your hand, and Jack Sparrow is letting you see his first card too. Here's how to decide whether to heave ho or scuttle: 1. Always heave ho if you have 11 or fewer points in your hand. 2. Always scuttle if you have 17 or more points in your hand. 3. If you have 12-16 points, scuttle if Jack Sparrow's first card is 2-6. Otherwise, heave ho. Every time you take a card, you should add that card to your hand by concatenating it to the end of your vector. Then, delete the card from the deck, recalculate your score, and decide whether you should heave ho again. After your turn, Jack Sparrow will draw cards until he has a score of 17 or higher. Finally, output one of three possible game outcomes: 'Blimey! I win! You win: Sparrow Wins: 'Jack Sparrow wins.' Both hands go over 21: 'Oh no! We both hornswoggled.'
Continued... Example: myHand [2 6] sparrowHand= [4 8] deck [6 4 4 8 7 2] winner jackSparrow(myHand, sparrowHand, deck) At the beginning, you have 8 points, so you heave ho. You pick up the first card from the deck so your hand becomes [2 6 2]. You now have 14 points and Jack Sparrow's first card is a 4. That means you have to scuttle. The deck becomes [4 4 8 7 2]. Jack Sparrow has a score of 12 at the beginning. He decides to heave ho, making his score 16 and the deck [4 8 7 2]. He heave hos again so his score becomes 20 and the deck becomes [8 7 2]. winner 'Jack Sparrow wins. Notes: Jack Sparrow is greedy, so he wins all ties. All cards will be represented as doubles (2-11) There will always be enough cards in the deck
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

function winner = jackSparrow(myHand,sparrowHand,deck)
while true
if sum(myHand)<=11
myHand=[myHand deck(1)];
deck(1)=[];
elseif sum(myHand)>16
break
else
if sum(myHand)<17
if sparrowHand(1)<7 && sparrowHand(1)>1
break
else
myHand=[myHand deck(1)];
deck(1)=[];
end
end
end
end
while sum(sparrowHand)<17
sparrowHand=[sparrowHand deck(1)];
deck(1)=[];
end
if sum(myHand)>21 && sum(sparrowHand)>21
winner='Oh no! We both hornswoggled.';
elseif (sum(myHand)>sum(sparrowHand) && sum(myHand)<22)||sum(sparrowHand)>21
winner='Blimey! I win';
elseif (sum(myHand)<=sum(sparrowHand) && sum(sparrowHand)<22)||sum(myHand)>21
winner='Jack Sparrow wins.';
end
end

Command Window myHand [2 61 >sparrowHand=[4 81; >deck=[6 4 4 8 7 2]; winner jackSparrow (myHand, sparrowHand, deck) winner Ja

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
MATLAB code help! Function Name: jackSparrow Inputs: 1. (double) A 1x2 vector describing your hand 2....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a simplified Blackjack game using the Deck and Card classes (download the attached files to...

    Create a simplified Blackjack game using the Deck and Card classes (download the attached files to start).  There is also a "TestCard" class that creates a Deck and runs some simple code. You may choose to use this file to help you get started with your game program. 1) Deal 2 cards to the "player" and 2 cards to the "dealer".  Print both the player's cards, print one of the dealer's cards. Print the total value of the player's hand. 2) Ask...

  • How do I start this c++ code homework? Write a code in C++ for a BlackJack...

    How do I start this c++ code homework? Write a code in C++ for a BlackJack card game using the following simplified rules: Each card has a numerical value. Numbered cards are counted at their face value (two counts as 2 points, three, 3 points, and so on) An Ace count as either 1 point or 11 points (whichever suits the player best) Jack, queen and king count 10 points each The player will compete against the computer which represents...

  • programming language c++ its a project if anyone can help me it's will be appreciated thnk...

    programming language c++ its a project if anyone can help me it's will be appreciated thnk u. u have to create a code based on the information im giving u you can do it in 1 or 2 day i can wait 1:26 #WW 2.53% Example: A user starts with 1000 points. Game #1 - user chooses to risk 200 points. User wins game (beats the dealer). User now has 1200 points. Game #2 - user chooses to risk 500...

  • For this assignment you will create a one-player variation of the game BlackJack. The game will...

    For this assignment you will create a one-player variation of the game BlackJack. The game will be divided into five rounds. The goal of each round is to accumulate a hand of cards that gets as close to 21 without going over. At the beginng of the game you will start with a score of 100 points. After each round, the difference between your hand and 21 will be subtracted from your total score. The object of the entire game...

  • programming language c++ programming language c++ 1:25 #WW # 53% You may, if you wish, work...

    programming language c++ programming language c++ 1:25 #WW # 53% You may, if you wish, work in pairs; this means that a submission may have 2 names attached but those 2 people must have worked on the project. No free rides! The way to submit the program to me is as follows: put the entire program (main and any other functions) into a single compile. Compile it to be sure that you have the correct set of #include statements and...

  • Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriat...

    Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriate accessors, constructors, and mutators. Next, create a Deck class that stores a vector of Card objects. The default constructor should create objects that represent the standard 52 cards and store them in the vector. The Deck class should have functions to: • Print every card in the...

  • Please write the program in python: 3. Design and implement a simulation of the game of...

    Please write the program in python: 3. Design and implement a simulation of the game of volleyball. Normal volleyball is played like racquetball, in that a team can only score points when it is serving. Games are played to 15, but must be won by at least two points. 7. Craps is a dice game played at many casinos. A player rolls a pair of normal six-sided dice. If the initial roll is 2, 3, or 12, the player loses....

  • Please help me write these in R script / Code 1, Suppose you're on a game...

    Please help me write these in R script / Code 1, Suppose you're on a game show, and you're given the choice of three doors. Behind one door is a car; behind the others, goats. You pick a door, say #1, and the host, who knows what's behind the doors, opens another door, say #3, which has a goat. He then says to you, "Do you want to pick door #2?" What is the probability of winning the car if...

  • "Blackjack 40" my teacher created this assignment and I need help. He is using c++ and...

    "Blackjack 40" my teacher created this assignment and I need help. He is using c++ and has provided this template: Further instructions are below the template! #include <iostream> #include <cmath> #include <cstdlib> using namespace std; //Will return a number from 1 to 13, representing the face of a card int draw_card() { return rand() % 13 + 1; } int main() { const int BET = 10; //This will allow you to control chance, to make testing easier cout <<...

  • 2 A Game of UNO You are to develop an interactive game of UNO between a...

    2 A Game of UNO You are to develop an interactive game of UNO between a number of players. The gameplay for UNO is described at https://www.unorules.com/. Your program should operate as follows. 2.1 Setup 1. UNO cards are represented as variables of the following type: typedef struct card_s { char suit[7]; int value; char action[15]; struct card_s *pt; } card; You are allowed to add attributes to this definition, but not to remove any. You can represent colors by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT