I am attempting to change the value 'K' to a value of 10 so I can add it to other numbers.

1 次查看(过去 30 天)
I am trying to program a card game called cadillac. I am using cell arrays for the deck and hands. i.e. hand = {['h','K'], ['s',num2str(9)],['s',num2str(8)]}; The lower case letters are the suit of the card and the second element is the value of the card. I can't figure out how to change the face cards (i.e J, Q, K, and A) equal their respective number values so I can compute the score of the hand.
A = 11;
K = 10;
Q = 10;
J = 10;
currentScore = 0;
hand = {['h','K'],['c',num2str(9)],['s',num2str(8)]};
card1 = cell2mat(hand(1));
card2 = cell2mat(hand(2));
card3 = cell2mat(hand(3));
if(strcmp('K',card1(2)))
card1(2) = uint8(10);
end
disp(card1(2))

采纳的回答

Stephen23
Stephen23 2021-9-27
编辑:Stephen23 2021-9-30
Putting meta-data (e.g. the suits, card types) into variable names makes this task much harder.
Meta-data is data and should be stored in a variable, not in its name. For example, MATLAB is designed to work very efficiently with vectors (and arrays more generally), so using vectors is much better data design:
S = 'AJKQ';
V = [11,10,10,10];
C = 'J';
X = C==S;
V(X)
ans = 10

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Card games 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by