Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Function Name: jackSparrow Inputs: 1. ( double ) A 1x2 vector describing your hand 2. ( double ) A 1x2 vector describing Jack Sparrows hand

Function Name: jackSparrow Inputs: 1. ( double ) A 1x2 vector describing your hand 2. ( double ) A 1x2 vector describing Jack Sparrows 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: Youre out at sea with the infamous Jack Sparrow, and its 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. Heres 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 Sparrows 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: You win: 'Blimey! I win!' Sparrow Wins: 'Jack Sparrow wins.' Both hands go over 21: 'Oh no! We both hornswoggled.' 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions