Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve the above MATLAB problem, below are some test cases that you can input and should get the corresponding outputs. Test Cases: [win1, scorevec1]

image text in transcribed

Please solve the above MATLAB problem, below are some test cases that you can input and should get the corresponding outputs.

Test Cases:

[win1, scorevec1] = goFish([1 2 2 3], [1 4 3 5], [4 5 6 6])

win1 => Player 1 won!

scorevec1 => 3 1

[win2, scorevec2] = goFish([4 5 1 6], [7 2 2 5], [3 7 7 3 6 1 7 4 2 3 6 5 5 1 1 2 4 3 4 5])

win2 => Player 2 won!

scorevec2 => 1 2

[win3, scorevec3] = goFish([11 10 13 13 1 12 3], [9 5 6 10 4 7 2], [9 5 3 8 13 8 5 12 4 1 8 12 12 3 9 2 4 11 6 11 10 9 7 6 7 8 6 1 13 2 5 1 3 10 4 7 11 2])

win3 => Player 2 won!

scorevec3 => 12 13

Homework 7 Iteration 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 (double) A 1x2 vector of the final score 2. 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 If player two wins, output the string If it is a tie, output the string Player 1 won! Player 2 won!' 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

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