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