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

1 Ansicht (letzte 30 Tage)
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))

Akzeptierte Antwort

Stephen23
Stephen23 am 27 Sep. 2021
Bearbeitet: Stephen23 am 30 Sep. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Card games finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by