I am trying to write a function that draws a card from the deck, adds it to a hand, then deletes that card from the deck.

4 vues (au cours des 30 derniers jours)
Is there a way to completely erase the top card or first element from the cell array which is the deck of cards with a function? I can do it outside of the function but when I input the deck and the hand into the function the output comes back like this:
{0×0 double} {'h2'} {'c2'} {'s2'}
I need the function to return a 1X3 cell array instead of a 1X4 with an empty slot, is this possible in matlab?
this is what I am trying:
hand = {['c',num2str(3)]};
%disp(hand);
[drawpile, hand] = drawfromdrawpile(drawpile,hand);
%drawpile(1) = [];
%hand{end+1} = draw;
disp(hand);
disp(drawpile);
function [n,h] = drawfromdrawpile(n,h)
draw = n(1);
h(end+1) = draw;
n{1} =[];
end
when I do drawpile(1) = [] outside the function it changes it to a 1X3 cell array just fine but I need to be able to do it with a function so I can call that function in the course of a turn of the game cadillac.

Réponses (1)

Image Analyst
Image Analyst le 20 Oct 2021
I'm pretty sure you don't need cell arrays. A regular numerical (double) array of length 52 should work.
For what it's worth, I'm attaching my Monte Carlo card dealing program, and another demo. Maybe you'll find something useful in there. My demo code is usually very well commented.

Catégories

En savoir plus sur Card games dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by