Hi all, I am trying to write a basic matlab blackjack program for a class. So fa
ID: 653548 • Letter: H
Question
Hi all,
I am trying to write a basic matlab blackjack program for a class. So far i have not gotten very far i just dont know what to do. The game i am trying to make is playing blackjack, but all you can do in the game is hit 21 or bust. I want the program to automatically try and hit 21. There is no dealer, or money to bet. If anybody could help me out it would be great. This is what i have so far,
function card = dealcard;
%This program will allow someone to draw a card at random from a full deck
%and see what that card would be. you can go through the whole deck
persistent dec; %persistent makes it so matlab stores this variable
if length(dec)<53
dec=[1:52]; %one deck of cards
dec=dec(randperm(length(dec))); %this shuffles the cards
end;
card=dec(end);
Thanks Ryan.
Explanation / Answer
Automatically generate 21.
function card = dealcard;
%This program will allow someone to draw a card at random from a full deck
%and see what that card would be. you can go through the whole deck
persistent dec; %persistent makes it so matlab stores this variable
if length(dec)<53
dec=[21:21]; %one deck of cards
dec=dec(randperm(length(dec))); %this shuffles the cards
end;
card=dec(end);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.