-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.m
65 lines (63 loc) · 1.8 KB
/
Player.m
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
% PUT ALMOST ALL OF THIS UNDER THE HAND CLASS, bet, softhand and doubledown
% can stay under player as those aren't dealer related.
classdef Player < Hand
%% PROPERTIES
properties
playerName
MoneyPool
canSplit
bankrupt
isBust
end
%% CONSTRUCTORS
methods
function obj = Player(playerName, playerBank, playerInitalDraw)
arguments
playerName {mustBeText}
playerBank {mustBePositive, mustBeNonzero}
playerInitalDraw
end
% Initialize from the super class
obj@Hand(playerInitalDraw);
obj.MoneyPool = playerBank;
obj.playerName = playerName;
obj.checkSplitHand;
obj.isBust = false;
end
end
% methods
% function update(obj)
% obj.checkBankruptcy;
% obj.calcHandValue;
% end
% end
%% GAME METHODS
methods
function value = betToPot(obj, bet)
obj.checkBankruptcy();
if bet >= obj.MoneyPool && ~obj.bankrupt
bet = obj.MoneyPool;
warning(obj.playerName + ' is now all in. Bet value: ' + bet);
end
obj.MoneyPool = obj.MoneyPool - bet;
value = bet;
end
end
methods(Access = private)
function checkBankruptcy(obj)
if obj.MoneyPool <= 0
obj.bankrupt = true;
disp(obj.playerName + ' is bankrupt.')
else
obj.bankrupt = false;
end
end
function checkSplitHand(obj)
if isequal(obj.currentHand(1),obj.currentHand(2))
obj.canSplit = true;
else
obj.canSplit = false;
end
end
end
end