Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use Matlab to make a classic \"Card Sharks\" game. Carefully follow every instru

ID: 2082602 • Letter: U

Question

Use Matlab to make a classic "Card Sharks" game. Carefully follow every instruction and clearl address each item below and show all work including Matlab code with comments The card Sharks game consists of 20 rounds. The player begins with 0 points. Each round goes like this 1. the dealer (your Matlab program) picks a card at random from a full deck and displays it to the player 2. the dealer asks "will the next card be higher or lower?" 3. the player selects higher or lower 4. the dealer picks a second card from another full deck 5. if the player guessed correctly, 10 points are added to the play munning total If incomect 10 points are subtracted. Your assignment is to write a matlab program that implements this game, and then to play the game yourself end of your code. What to do when the second card is THE SAME as the first? Two different groups will deal with this differently: If your student number ends with an EVEN digit, then you ADD 10 points if the cards are the same. If your student number ends with an ODD digit, then you SUBTRACT 10 points if the cards are the same. Note that only the rank of the cards matters not the suit (diamonds, spades,

Explanation / Answer

close all %Close all figures and plots of MATLAb
clear all %Clears all variables
clc %Clears the command terminal

N=[1,2,3,4,5,6,7,8,9,10,11,12,13
1,2,3,4,5,6,7,8,9,10,11,12,13
1,2,3,4,5,6,7,8,9,10,11,12,13
1,2,3,4,5,6,7,8,9,10,11,12,13]; %Input number for 52 cards

S=[1,2,3,4]; %For the four type of suits

student=input('Enter your student number ','s'); %Input student number in case successive cards are similar in number
ch=rem(student,2); % To check whether student number is even or odd. If result ch=0, number is even. Else number is odd
if (ch)
fprintf('Your student number is ODD. You will lose 10 points for two simlar cards.') % If number is odd, 10 points are deducted if same card is acheived
a=10;
else
fprintf('Your student number is EVEN. You will be awarded 10 points for two simlar cards.') % If number is even, 10 points are added if same card is acheived
a=-10;
end
score=0; % initially the score is cosidered to be 0

for i=1:20 % loop for 20 rounds
  
num=N(randi(52)); % To select a random number from the card
s=S(randi(4)); % To select a random suit. This is just for display purpose. This variable is insignificant to our calculation
  
  
switch s
case 1
suit='Diamond';
case 2
suit='Club';
case 3
suit='Heart';
case 4
suit='Spade';
end
% Assigning a particulat suit out of the 4 numbers
fprintf(' Round number %d Your Card on display is %d %s',i,num,suit) % displays the round number and card picked randomly
  
  
if(i>1) % For the first case, we cannot compare with previous draw. So comparision between two succesive cards takes place only if i>1 or from second draw
if(((num>prev) && (inp==1))|| ((num<prev) && (inp==0))) % the condition for winning. The variable inp is calcualted at the end of the program and the variable prev is the value of the previos draw which is assigned later
score=score+10; % Add 10 after winning
fprintf(' Congratulations!!! You have won. Your current score is %d. You have %d attempts to go',score,20-i) % Progress of the game
elseif (((num>prev) && (inp==0))|| ((num<prev) && (inp==1))) % The condition for losing
score=score-10; % Deducting 10 points
fprintf(' You lose. Better luck next time. Your current score is %d. You have %d attempts to go',score,20-i)
else % The condition when the cards are repeated
score=score+a; % Either adding or dividing based on your student number
fprintf('You recived the same card. Your score now is %d. You have %d attempts to go',score,20-i)
end
end
prev=num; % Assigning the current card value to prev so that it will be usefull to compare with the next draw
if(i<20) % Game is played only for the first 19 attempts. At 20th attempt no game is played.
fprintf(' Will the next card be higher or lower')
  
while(1)
c=input(' Enter ''h'' for higher and ''l'' for lower ','s'); % Input to choose whether card is higher or lower
if ((c=='h')||(c=='H')||(c=='l')||(c=='L')) % The condition to check for any other wrong entries
break
else
fprintf(' Choice is Invalid. Please re-enter ')
end
end
  
if (c=='h'||c=='H') % assiging variable inp to 1 if input was for higher and 0 for lower. Used to update the score, whether to add or subtract.
inp=1;
else inp=0;
end
end
end

fprintf(' Game over. Your final score is %d',score) % The final score is displayed after 20 attempts


%Play one score was 90 and Play 2 score was 60

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote