Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need the code in Matlab. A dealer initially draws two cards. Each number card

ID: 3864602 • Letter: I

Question

I need the code in Matlab. A dealer initially draws two cards. Each number card is given a value of its number, each face card is given a value of ten, and each Ace is given a value of 11. If the total of his cards if 16 or less, he must draw another card from the deck. Else if the total of his cards is 22 or greater and he has an Ace, he must convert the value of that Ace from 11 to 1 and update the total of his cards. If the total of his cards is 17 or greater, he stops. Define a matrix A (first_card, final_total). For each hand, increment the cell that corresponds to the first card and final total of the dealer's hand. Use the totals in matrix A to find probabilities and conditional probabilities. Write a program that simulates a blackjack dealer. The program will simulate 20,000 hands and track the results in a matrix. This simulation will draw cards "with replacement". A. Make a "mesh()" plot of matrix A B. Find the probability for every possible total of dealer's cards C. Find the probability that the dealer busts, i.e. that dealer's total is 22 or greater D. Given that the dealer does not bust, find the expected value of the dealer's cards E. For each possible first card that the dealer draws, find the conditional probability that the dealer busts

Explanation / Answer

The given scenario lies in the favor of very famous game in the world i.e, Blackjack.The card consists of two data properties which is classified as suit and rank.In more contrast, A Player and dealer acts in a quite different way and each of them specifically have different rules and regulations.

I have attached the entire code which explains how it simulates 20,000 hands and tracks in a given matrix.


function simulatesBlackjack(N)

A = get(gcf,'playerInfo');
q = length(A);
chance = 10;
schedule = N ==1;

if schedule
delete(get(gca,'players'))
delete(findobj(gcf,'type','axes'))
axes('pos',[0 0 1 1])
axis([-5 5 -5 5])
axis off
bjbuttons('schedule');
stake = sum(A);
if stake >= 0, sig = '+'; else, sig = '-'; end
str = sprintf('%6.0f hands, $ %c%d',q,sig,abs(stake));
titl = text(-2.5,4.5,str,'fontsize',20);
n0 = q+1;
n1 = n0;
else
bjbuttons('off');
payoffs = [-4:1 1.5 2:4]*chance;
counts = hist(A,payoffs);
n0 = q+1;
n1 = ceil((n0)/N)*N;
subplot(2,1,2)
h = plot(0,0);
end
A = [A zeros(1,n1-n0+1)];

for q = n0:n1
bet1 = chance;
P = deal;
D = deal;
P = [P deal];
D = [D -deal];
  

split = mod(P(1),13)==mod(P(2),13);
if split
if schedule
show('Player',P)
show('Dealer',D)
split = pair(value(P(1)),value(D(1)));
  
  
split = bjbuttonclick('split',split+1);
else
split = pair(value(P(1)),value(D(1)));
end
end
if split
P2 = P(2);
if schedule, show('Split',P2); end
P = [P(1) deal];
bet2 = bet1;
end
  
  
if schedule
[P,bet1] = playhand('Player',P,D,bet1);
show('Player',P)
if split
P2 = [P2 deal];
show('Split',P2)
[P2,bet2] = playhand('Split',P2,D,bet2);
end
else
[P,bet1] = playhand('',P,D,bet1);
if split
P2 = [P2 deal];
[P2,bet2] = playhand('',P2,D,bet2);
end
end
  

D(2) = -D(2);
while value(D) <= 16
D = [D deal];
end
  
  
if schedule
show('Dealer',D)
show('Player',P)
s = payoff('Player',P,D,split,bet1);
if split
show('Split',P2)
s = s + payoff('Split',P2,D,split,bet2);
end
else
s = payoff('',P,D,split,bet1);
if split
s = s + payoff('',P2,D,split,bet2);
end
end
S(q) = s;

if schedule
stake = stake + s;
if stake >= 0, sig = '+'; else, sig = '-'; end
str = sprintf('%6.0f hands, $ %c%d',q,sig,abs(stake));
set(titl,'string',str)
end

chunk = min(2000,N);
if ~schedule & mod(q,chunk) == 0
Schunk = S(q-chunk+1:q);

subplot(2,1,2)
ydata = get(h,'ydata');
ydata = ydata(end) + cumsum(Schunk);
ylim = get(gca,'ylim');
if max(ydata) > ylim(1) | min(ydata) < ylim(2)
ydata = cumsum(S(1:q));
h = plot(1:q,ydata);
line([1 n1],[0 0],'color','black')
ylim = 1000*[floor(min(min(ydata)/1000,-1)) ...
ceil(max(max(ydata)/1000,1))];
axis([1 n1 ylim])
else
set(h,'xdata',q-chunk+1:q,'ydata',ydata);
end

subplot(2,1,1)
[kounts,x] = hist(S(q-chunk+1:q),payoffs);
counts = counts + kounts;
p = counts/q;
bar(x,p)
axis([-4.5*chance 4.5*chance 0 .45])
stake = ydata(end);
if stake >= 0, sig = '+'; else, sig = '-'; end
str = sprintf('%c%d',sig,abs(stake));
if abs(stake) < 1000, str = [' ' str]; end
if abs(stake) < 100, str = [' ' str]; end
if abs(stake) < 10, str = [' ' str]; end
title(sprintf('%6.0f hands, $ %s',q,str))
set(gca,'xtick',payoffs);
for k = 1:length(payoffs)
if payoffs(k)==15, y = -.12; else, y = -.08; end
text(payoffs(k)-6.5,y,sprintf('%9.4f',p(k)));
end

r = payoffs/chance;
mu = p*r';
crit = 1.96;
rho = crit*sqrt((p*(r.^2)'-mu^2)/q);
pm = char(177);
text(20,.3,sprintf('%6.4f %c %6.4f',mu,pm,rho));
drawnow
end
end
set(gcf,'playerInfo',S);