-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.m
118 lines (104 loc) · 3.92 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
classdef Player
%PLAYER Summary of this class goes here
% Detailed explanation goes here
properties (Constant)
maxClues = 10;
maxFriends = 30;
clueDurability = 10;
end
properties
ID;
playertype;
rxClues = zeros(1,7);
myClues = zeros(1,7);
friendList = zeros(1,0);
credits = 0;
partyCreditsToday = 0;
partiesThrown = 0;
clueTimers = cell(1,7);
end
methods
function obj = Player(id)
%PLAYER Construct an instance of this class
% Detailed explanation goes here
obj.ID = id;
end
function self = addFriend(self,id)
%ADDFRIEND Adds a friend to this player
if length(self.friendList) >= self.maxFriends
error('Player:addFriend',...
'Player %d already has maxFriends',self.ID);
end
if any(self.friendList==id)
error('Player:addFriend',...
'Player %d is already friends with player %d',self.ID,id);
end
self.friendList = [self.friendList id];
end
function self = addCredits(self,amt)
self.credits = self.credits + amt;
end
function self = receivePartyCredits(self)
if self.partyCreditsToday < 300
self.partyCreditsToday = self.partyCreditsToday + 30;
self.credits = self.credits + 30;
end
end
function self = newDay(self)
self.partyCreditsToday = 0;
for iter = 1:7
clueTimer = self.clueTimers{iter};
clueTimer = clueTimer - ones(size(clueTimer));
for jter = 1:sum(clueTimer==0)
self = self.removeClue(iter);
end
end
end
function [players, self] = throwParty(self,players)
%we assume parties resolve instantly, i.e. everyone who can
%visit does so, and the player begins setting up for their next
%party immediately.
%fprintf('----DBG: P%d Party!\n',self.ID)
for cluenum = 1:7
self = self.removeClue(cluenum);
end
self.partiesThrown = self.partiesThrown + 1;
self.credits = self.credits + 210;
for friendID = self.friendList
players{friendID} = players{friendID}.receivePartyCredits();
end
end
function CL = getClueList(self)
CL = self.myClues + self.rxClues;
end
function isTradeable = checkClueTradeability(self,players)
for friendID = self.friendList
%how many trades are possible for each type of clue, i.e.
%which clue should I trade to remove as many dupes as
%possible?
possibleTrades = ((players{friendID}.getClueList()==0) & (self.myClues>0));
if any(possibleTrades)
isTradeable = true;
return
end
end
isTradeable = false;
end
function self = removeClue(self,cluenum)
if self.rxClues(cluenum) > 0
self.rxClues(cluenum) = self.rxClues(cluenum) - 1;
timer = self.clueTimers{cluenum};
timer(1) = [];
self.clueTimers{cluenum} = timer;
elseif self.myClues(cluenum) > 0
self.myClues(cluenum) = self.myClues(cluenum) - 1;
else
warning('P%d tried to remove C#, but they didn''t have any.',self.ID,cluenum)
end
end
end
methods (Abstract)
[players, self] = findClue(self,cluenum,players)
[players, self] = receiveClue(self,cluenum,players,id)
end
end