Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Function Name: goFish Inputs: ( double ) A 1xN vector of the cards in player one's hand 2. ( double ) A 1xN vector of the cards in player two's hand...

Function Name: goFish

Inputs:

1. ( double ) A 1xN vector of the cards in player one's hand

2. ( double ) A 1xN vector of the cards in player two's hand

3. ( double ) A 1xM vector of the cards in the deck

Outputs:

1. (char ) A string stating which player won

2. (double) A 1x2 vector of the final score

Function Description:

You and your friend are super bored playing Go Fish at a normal speed so you decide to

spice your game life up with some Go Fish, MATLAB style! You will be given a vector of the

cards in each player's hand -don't worry, jacks will be given to you as an 11, queens a 12 , and

kings a 13- . As in normal Go Fish, the game will end once one player runs out of cards. Player

one will always go first.

Each player will "ask" the other for the first card in their hand, the first element in the

hand vector. If the other player has one of the same type of card in their hand, remove the

number from both hands and add a point to the proper player's score. If the other player doesn't

have the same type of card, first take the first card from the deck and append it to the end of the

hand, then take the card at the front of that player's hand and move it to the end of the hand

(this makes sure they don't ask for the same card twice in a row). Repeat this process until one

player doesn't have any cards left.

Before you play the game, ensure that the players' hands have no repeat cards. If they

do have repeats, remove each pair of cards (if you have three of the same card in one hand,

remove the first two instances of the card). Make sure that every time you draw from the deck,

you check to see if it pairs with any other card in the hand. Anytime a player makes a pair, add a

point to their score. The winner is the player with the most points at the end of the game, not the

one who clears their hand first.

If player one wins, output the string: 'Player 1 won!'

If player two wins, output the string: 'Player 2 won!'

If it is a tie, output the string: 'It's a tie!'

Example:

>> [winner,score] = goFish([1,2],[2,3],[1,4,4,3])

score = [1,1]

winner = 'It's a tie!'

%Player one asks player two for a 1. Player one draws a card from the deck

%and gains a point because it matched a card in player one's hand. player two

%asks player one for a 2 and gains a point. The game then ends

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question