-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelfishPlayer.m
156 lines (137 loc) · 7.24 KB
/
SelfishPlayer.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
classdef SelfishPlayer < Player
%SELFISHPLAYER This is an Arknights player that uses their clues
%selfishly
% A selfish player uses all their clues for themselves whenever
% possible, only trading when they run out of inventory
methods
function self = SelfishPlayer(id)
%SELFISHPLAYER Construct an instance of this class
% Inputs:
% id: a unique integer identifier for this player.
self@Player(id)
self.playertype = 1;
end
function [players, self] = findClue(self,cluenum,players)
%FINDCLUE this player finds a clue themselves
% Inputs:
% cluenum: the clue number found (1-7)
% players: a cell array of all players in the game.
% Yeah yeah yeah, I know it's a bad solution.
% It works. Deal with it.
% Outputs:
% self: an updated version of this player, after this
% operation. Overwrite the player whenever
% you use this method.
% players: an updated version of the players structure.
% again, make sure to overwrite it whenever
% you use this method
% Example:
% players = {SelfishPlayer(1), SelfishPlayer(2),
% SelflessPlayer(3)};
% [players{1}, players] = players{1}.findClue(1,players);
%fprintf('P%d F%d | ',self.ID,cluenum)
if sum(self.myClues) < self.maxClues
self.myClues(cluenum) = self.myClues(cluenum)+1;
if all(self.getClueList()>0)
[players, self] = self.throwParty(players);
end
while sum(self.myClues) >= self.maxClues
%give away a clue if I'm out of space
[players, self] = self.giveClue(players);
end
else
[players, self] = self.giveClue(players);
%error('Player:findClue',...
% 'Player %d already has max Clues',self.ID);
end
end
function [players, self] = receiveClue(self,cluenum,players,~)
%RECEIVECLUE this player is given a clue by another player. This
%varies from SelfishPlayer.findClue because the clue is added
%to a list of untradeable 'gifted' clues instead of their own.
% Inputs:
% cluenum: the clue number found (1-7)
% players: a cell array of all players in the game.
% Yeah yeah yeah, I know it's a bad solution.
% It works. Deal with it.
% Outputs:
% self: an updated version of this player, after this
% operation. Overwrite the player whenever
% you use this method.
% players: an updated version of the players structure.
% again, make sure to overwrite it whenever
% you use this method
% Example:
% players = {SelfishPlayer(1), SelfishPlayer(2),
% SelflessPlayer(3)};
% [players{1}, players] = players{1}.receiveClue(1,players);
%fprintf('P%d R%d | ',self.ID,cluenum)
self.rxClues(cluenum) = self.rxClues(cluenum)+1;
self.clueTimers{cluenum} = [self.clueTimers{cluenum} self.clueDurability];
if all(self.getClueList())
[players, self] = self.throwParty(players);
end
end
function [players, self] = giveClue(self,players)
%GIVECLUE this player gives a clue by another player. The clue
%given is decided automatically by looking through the player's
%friend list at the most impactful trades possible.
% Inputs:
% players: a cell array of all players in the game.
% Yeah yeah yeah, I know it's a bad solution.
% It works. Deal with it.
% Outputs:
% self: an updated version of this player, after this
% operation. Overwrite the player whenever
% you use this method.
% players: an updated version of the players structure.
% again, make sure to overwrite it whenever
% you use this method
% Example:
% players = {SelfishPlayer(1), SelfishPlayer(2),
% SelflessPlayer(3)};
% [players{1}, players] = players{1}.findClue(1,players);
% [players{1}, players] = players{1}.giveClue(players);
minRemaining = 8;
bestTrade = 0;
tradeClue = 0;
tradeID = 0;
%Look through friends list to find the best trade possible:
% prioritizing players who are missing the fewest clues, then
% choosing among them by giving the clue the player has the
% most of.
% TODO: add some noise to this. if everyone does this, nobody
% who gives clues gets any clues >.>
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))...
.* self.getClueList();
if any(possibleTrades)
if any(possibleTrades) && ...
sum(players{friendID}.getClueList()==0) < minRemaining
tradeID = friendID;
minRemaining = sum(players{friendID}.getClueList()==0);
[bestTrade, tradeClue] = max(possibleTrades);
elseif sum(players{friendID}.getClueList()==0)==minRemaining...
&& max(possibleTrades) > bestTrade
tradeID = friendID;
[bestTrade, tradeClue] = max(possibleTrades);
end
end
end
if minRemaining == 8
tradeID = self.friendList(1);
[~, tradeClue] = max(self.myClues);
fprintf('----DBG: P%d has no trades: C#%d -> P%d\n',...
self.ID,tradeClue,tradeID)
end
%fprintf('P%d->P%d C#%d | ',self.ID,tradeID,tradeClue)
self.myClues(tradeClue) = self.myClues(tradeClue) - 1;
[players, players{tradeID}] = players{tradeID}.receiveClue(tradeClue,players,self.ID);
self.credits = self.credits + 20;
players{tradeID}.credits = players{tradeID}.credits + 15;
end
end
end