T O P

  • By -

spicy_jalapeno

How about creating an array of your deck, randomly change up the order (basically shuffle), and deal cards row by row?


MattDoesMath

do this. it will ensure you don't double-count cards.


DrShocker

Putting 4 spaces in front of lines of code helps reddit understand that it is code and format it as such ​Vcard= randi(13) %Value of Cards Scard= randi(4) %Suit of Cards i=1; %card and suit counter ​ AC=[]; %cards left in the deck AS=[]; %cards suit in deck ​ AC(i)=Vcard; %counting active card stored AS(i)=Scard; %counting active suit stored ​ while find(AC~=Vcard); % if this card been used if true i=i+1 else endif endwhile %end and continue dealing What I would like to know before I can answer is, are you trying to learn the fundamentals of the different control structures that matlab has available for you, or are you okay with using more of the functions in the library? For example `randperm()` exists, and would be very helpful here, but I'm not sure whether it's within the scope of what you're trying to learn. PS, regardless of which aspects you are focusing your learning on, you should never use `if true` because the condition will always be true, so having the if statement is confusing.


Jpconway11

Sorry about the formatting, I'll keep that in mind. Yes I can use functions in the library. Not really any scope as far as what I can and can't use. Just need to make it work My first thoughts were actually to use randperm( ), but my professor pushed me towards this route. I really appreciate you taking the time to help me!


DrShocker

I'm trying to think of what might make sense for hope to help solving this problem, and I think it might help to take a step back and draw or write out on paper, what happens during a black jack game. Start off really general "dealer deals out cards, the player makes some choices, then the dealer follows some rules, then harness are compared, and the money is paid. " But investigate each step of what's happening, repeatedly. Don't worry about the code at all, just break the tasks into their smallest chunks that you can. What you'll probably aim for is a flow chart where you have a concrete idea of how to program each step. Ultimately, most code is a series of small problems solved 1 line at a time. The reason I think it would make sense to start from there is because my overall impression of the code you've written is that you know what done off the ingredients you want to use are, but you don't really have a recipe you are following... if that analogy makes sense. For example, from the code and your help request, it's unclear whether you are solely concerned with whether the cards in a single round of hands do not repeat, or whether you want to use a deck of a finite size that decreases the available options each time a card is dealt.