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

1 visualización (últimos 30 días)
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))

Respuesta aceptada

Stephen23
Stephen23 el 27 de Sept. de 2021
Editada: Stephen23 el 30 de Sept. de 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

Más respuestas (0)

Categorías

Más información sobre Card games en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by