-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsofthand.m
More file actions
74 lines (63 loc) · 2.18 KB
/
softhand.m
File metadata and controls
74 lines (63 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function [outcome,deck,count,pcards,dcards] = softhand(pcards,dcards,deck,count)
dd = 1; % Will change to 2 if player decides to double down
while 1
% Check if Dealer has 21
if (dcards(1) == 1 && dcards(2) == 10) || ...
(dcards(1) == 10 && dcards(2) == 1)
dcards(find(dcards==1,1)) = 11; % Set ace to = 11
if sum(pcards) == 11; % Check for player Blackjack
pcards(find(pcards==1,1)) = 11; % Set ace to = 11
outcome = 0; % Blackjack push
break
end % If Player doesn't also have blackjack
outcome = -1; % Push
break
end
% Check if Player has 21
% We know one card is an ace so if the total of the cards equals 11
% then the other cards is a ten: Blackjack
if sum(pcards) == 11
outcome = 1.5; % Player has blackjack 3:2 payout
pcards(find(pcards==1,1)) = 11; % Set ace to = 11
break
end
strat = soft(sum(pcards)-1,dcards(1)); % Determine strategy
% Stand
if strat == 0 % Stand set ace to equal 11
pcards(find(pcards==1,1)) = 11;
% Double Down
elseif strat == 2
dd = 2; % double outcome if player doubled down
[pcards(3),count,deck] = deal(deck,count);
if sum(pcards) < 12
pcards(find(pcards==1,1)) = 11;
end
else % strat == 1 Hit
[pcards,count,deck] = dealto(pcards,count,deck);
end
% Check if Player Busted
if sum(pcards) > 21
outcome = -1*dd;
break
end
% Player now has all cards based on basic strategy
% Deal to Dealer
[dcards,count,deck] = dealto(dcards,count,deck);
% Check if Dealer Busted
if sum(dcards) > 21
outcome = 1*dd;
break
end
% Player has been delt too and Dealer has been delt too
% Compare Hands
if sum(pcards) > sum(dcards)
outcome = 1*dd; % Win
break
elseif sum(pcards) < sum(dcards)
outcome = -1*dd; % Loss
break
else
outcome = 0; % Push
break
end
end