Clear Filters
Clear Filters

How to rank cards

2 views (last 30 days)
Lynn Boudani
Lynn Boudani on 29 Nov 2020
Answered: Manas on 1 Aug 2022
I'm trying to rank the different cards, but I'm struggling with the if statements and on how to assign a value to my different suits. Basically, if the 'tarneeb' is spades that means spades is the highest ranking suit, I'm struggling on how to code that.
  2 Comments
Rik
Rik on 29 Nov 2020
If you ask a specific question related to Matlab you increase your chances of getting an answer. I'm not sure which game you refer to, nor what you have already done.
Lynn Boudani
Lynn Boudani on 29 Nov 2020
I did this excel file. The card game is called Trumps. I'm trying to assign values to these different suits.
if contains(tarneeb_input,'S')
%spades is the highest ranking
%for the hearts: Ace is the strongest(val = 13) but spades always beats it (spades>13)
end

Sign in to comment.

Answers (1)

Manas
Manas on 1 Aug 2022
Having an if condition to check the value and suit is more than enough here.
tarneeb_input = input("Enter Card");
score = 0;
if(contains(tarneeb_input, "Spades"))
score = 39;
elseif(contains(tarneeb_input, "Hearts"))
score = 26;
elseif(contains(tarneeb_input, "Clubs"))
score = 13;
else
score = 0;
end
if(tarneeb_input(1) == '2')
score = score + 1;
elseif(tarneeb_input(1) == '3')
score = score + 2;
elseif(tarneeb_input(1) == '4')
score = score + 3;
elseif(tarneeb_input(1) == '5')
score = score + 4;
elseif(tarneeb_input(1) == '6')
score = score + 5;
elseif(tarneeb_input(1) == '7')
score = score + 6;
elseif(tarneeb_input(1) == '8')
score = score + 7;
elseif(tarneeb_input(1) == '9')
score = score + 8;
elseif(tarneeb_input(1) == '10')
score = score + 9;
elseif(tarneeb_input(1) == 'J')
score = score + 10;
elseif(tarneeb_input(1) == 'Q')
score = score + 11;
elseif(tarneeb_input(1) == 'K')
score = score + 12;
else
score = score + 13;
end
disp(score);

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!