Skip to content

Commit 1d6f0d0

Browse files
author
Lara Rodrigues
committed
logs done
1 parent ff9f968 commit 1d6f0d0

File tree

9 files changed

+48933
-67
lines changed

9 files changed

+48933
-67
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
hs_err_pid*
2323

2424
out/
25-
logs/
25+

logging

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
60.
3+
4+
My friends, tonight's effort produced 51 priceless paintings.
5+
My friends, tonight's effort produced 54 priceless paintings.
6+
My friends, tonight's effort produced 63 priceless paintings.
7+
My friends, tonight's effort produced 63 priceless paintings.

logs/logging

Lines changed: 48733 additions & 0 deletions
Large diffs are not rendered by default.

src/entities/OrdinaryThief.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public class OrdinaryThief extends Thief {
2626
*/
2727
private boolean hasCanvas;
2828

29+
/**
30+
* True if ordinary thief is in a party
31+
*/
32+
private boolean inParty;
33+
2934
/**
3035
* Array of Museum Rooms
3136
*/
@@ -45,7 +50,12 @@ public class OrdinaryThief extends Thief {
4550
public void setAssaultParty(int partyID, boolean reset) {
4651
logger(this, "Assault Party: "+partyID);
4752
party = assaultParties[partyID];
48-
if (reset) party.resetAssaultParty();
53+
inParty = true;
54+
repos.setOrdinaryThiefSituation(getThiefID(), isInParty());
55+
if (reset){
56+
party.resetAssaultParty();
57+
58+
}
4959
}
5060

5161
/**
@@ -54,6 +64,7 @@ public void setAssaultParty(int partyID, boolean reset) {
5464
*/
5565
public void setRoomOfParty(int roomID) {
5666
party.setRoom(rooms[roomID]);
67+
repos.setApRId(getPartyID(), roomID);
5768
}
5869

5970
/**
@@ -64,6 +75,23 @@ public int getDisplacement() {
6475
return displacement;
6576
}
6677

78+
/**
79+
* Get thief in party
80+
* @return True if the thief is in a party
81+
*/
82+
public boolean isInParty() {
83+
return inParty;
84+
}
85+
86+
/**
87+
* Set thief in party
88+
* @param inParty True if the thief is in a party
89+
*/
90+
public void setInParty(boolean inParty) {
91+
this.inParty = inParty;
92+
}
93+
94+
6795
/**
6896
* Get the room of the thief
6997
* @return True if the thief has a canvas
@@ -136,8 +164,10 @@ public OrdinaryThief(String threadName, int thiefID, Museum museum, Concentratio
136164
thiefState = OrdinaryThiefStates.CONCENTRATION_SITE;
137165
displacement = random(MIN_DISPLACEMENT, MAX_DISPLACEMENT);
138166
hasCanvas = false;
167+
inParty = false;
139168
rooms = museum.getRooms();
140169
this.repos = repos;
170+
repos.setOrdinaryThiefDisplacement(thiefID, displacement);
141171
}
142172

143173
/**
@@ -152,6 +182,8 @@ public void run() {
152182
party.reverseDirection();
153183
party.crawlOut();
154184
collectionSite.handACanvas();
185+
setInParty(false);
186+
repos.setOrdinaryThiefSituation(getThiefID(), isInParty());
155187
} else break;
156188
}
157189
}

src/sharedRegions/AssaultParty.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ public void addThief(int thiefID) {
6060
for (int i = 0; i < N_THIEVES_PER_PARTY; i++) {
6161
if (thieves[i] == null) {
6262
thieves[i] = new Mapping(thiefID, 0);
63-
//logger(this, "Added Ordinary " + thiefID);
6463
break;
6564
}
6665
}
66+
67+
6768
}
6869

6970
/**
@@ -82,11 +83,11 @@ public Museum.Room getRoom() {
8283
* @param room Room object
8384
*/
8485
public void setRoom(Museum.Room room) {
85-
logger(this, "Was given room " + room);
86-
//GenericIO.writelnString(room + " has distance " + room.getDistance() + " and paintings " + room.getPaintings());
8786
this.room = room;
8887
room.setAssaultPartyID(id);
8988
inRoom = 0;
89+
repos.setDistanceToRoom(room.getID(), room.getDistance());
90+
9091

9192
}
9293

@@ -99,7 +100,7 @@ public void resetAssaultParty() {
99100
nextThiefID = -1;
100101
for (int i = 0; i < N_THIEVES_PER_PARTY; i++)
101102
thieves[i] = null;
102-
//logger(this, "RESETED!");
103+
103104
}
104105

105106
/**
@@ -130,7 +131,6 @@ public synchronized void sendAssaultParty() {
130131
MasterThief masterThief = (MasterThief) Thread.currentThread();
131132
masterThief.setActiveAssaultParties(masterThief.getActiveAssaultParties() + 1);
132133
masterThief.setPartyActive(id, true);
133-
logger(this, "PARTY SENT");
134134
begin = true;
135135
notifyAll();
136136

@@ -182,6 +182,7 @@ private boolean sleep(int thiefID) {
182182
public synchronized void crawlIn() {
183183
OrdinaryThief ordinaryThief = (OrdinaryThief) Thread.currentThread();
184184
ordinaryThief.setThiefState(OrdinaryThiefStates.CRAWLING_INWARDS);
185+
repos.setOrdinaryThiefState(ordinaryThief.getThiefID(), OrdinaryThiefStates.CRAWLING_INWARDS);
185186
int thiefID = ordinaryThief.getThiefID();
186187

187188
if (nextThiefID == -1) {
@@ -202,13 +203,10 @@ public synchronized void crawlIn() {
202203
//GenericIO.writelnString(getThiefPosition(thiefID)+"is the position of thief "+thiefID);
203204
} while(crawl(ordinaryThief, 0, room.getDistance()));
204205

206+
repos.setDistance(room.getDistance());
205207
ordinaryThief.setThiefState(OrdinaryThiefStates.AT_A_ROOM);
206-
//GenericIO.writelnString(getThiefPosition(ordinaryThief.getThiefID())+"is the position of thief "+ordinaryThief.getThiefID());
207208
repos.setOrdinaryThiefState(thiefID, OrdinaryThiefStates.AT_A_ROOM);
208-
//repos.setOrdinaryThiefRoomID(thiefID, room.getID());
209-
loggerCrawl(ordinaryThief, "ARRIVED AT " + room);
210-
//repos.setAssaultPartyID(id);
211-
//repos.setOrdinaryThiefAssaultPartyID(thiefID, id);
209+
repos.setOrdinaryThiefAssaultPartyID(thiefID, id);
212210
}
213211

214212
/**
@@ -235,7 +233,6 @@ public synchronized void crawlOut() {
235233
getThief(thiefID).isAtGoal(false);
236234
ordinaryThief.setThiefState(OrdinaryThiefStates.COLLECTION_SITE);
237235
repos.setOrdinaryThiefState(thiefID, OrdinaryThiefStates.COLLECTION_SITE);
238-
loggerCrawl(ordinaryThief, "ARRIVED AT COLLECTION SITE");
239236
}
240237

241238
/**
@@ -256,7 +253,7 @@ private boolean crawl(OrdinaryThief ordinaryThief, int beginning, int goal) {
256253

257254
// wake up next thief
258255
nextThiefID = getNextThief(thiefID, backwards);
259-
//GenericIO.writelnString("Next Thief: " + nextThiefID);
256+
260257

261258
notifyAll();
262259

@@ -315,6 +312,7 @@ private void updateThiefPosition(int thiefID, int move, boolean backwards) {
315312
int newPos = !backwards ? thiefPos + move : thiefPos - move;
316313
repos.setOrdinaryThiefPosition(thiefID, newPos);
317314
setThiefPosition(thiefID, newPos);
315+
repos.setOrdinaryThiefPosition(thiefID, newPos);
318316
}
319317

320318
/**
@@ -347,7 +345,6 @@ private boolean checkOverlay(int beginning, int goal) {
347345
int currentPos = thieves[i].getPosition();
348346
int nextPos = thieves[j].getPosition();
349347
if (currentPos != beginning && currentPos != goal && currentPos == nextPos) {
350-
//GenericIO.writelnString("OVERLAY");
351348
return true;
352349
}
353350
}
@@ -443,7 +440,6 @@ private void printPositions() {
443440
for (int i = 0; i < N_THIEVES_PER_PARTY; i++) {
444441
print.append(thieves[i].getPosition()).append(" ");
445442
}
446-
//GenericIO.writelnString(print);
447443
}
448444

449445
/**

src/sharedRegions/CollectionSite.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public CollectionSite(GeneralRepos repos) {
153153
partiesInSite = new boolean[N_ASSAULT_PARTIES];
154154
thiefCanvasState = new int[N_THIEVES_ORDINARY];
155155
try { thiefQueue = new MemFIFO<>(new AppraisedThief[N_THIEVES_ORDINARY]); } catch (MemException e) {e.printStackTrace();}
156+
this.repos = repos;
156157
}
157158

158159
/**
@@ -202,6 +203,7 @@ public synchronized void takeARest() {
202203
public synchronized void handACanvas() {
203204
OrdinaryThief ordinaryThief = (OrdinaryThief) Thread.currentThread();
204205
ordinaryThief.setThiefState(OrdinaryThiefStates.COLLECTION_SITE);
206+
205207
AppraisedThief thief = new AppraisedThief(ordinaryThief.getThiefID(), ordinaryThief.getRoomID(), ordinaryThief.getPartyID(), ordinaryThief.hasCanvas());
206208
try {
207209
thiefQueue.write(thief);
@@ -298,9 +300,11 @@ public synchronized void sumUpResults() {
298300
MasterThief masterThief = (MasterThief) Thread.currentThread();
299301
masterThief.setThiefState(MasterThiefStates.PRESENTING_REPORT);
300302
// repos.updateMasterThiefState(MasterThiefStates.PRESENTING_REPORT);
301-
302303
notifyAll();
304+
303305
logger(this, "The heist is over! Were collected " + canvas + " canvas.");
306+
repos.setnCanvas(canvas);
307+
repos.printSumUp();
304308
}
305309

306310
/**

src/sharedRegions/ConcentrationSite.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public synchronized boolean prepareExcursion() {
193193
// setup nextPartyID
194194
//GenericIO.writelnString("NEXT PARTY ID: "+nextPartyID);
195195
//GenericIO.writelnString("NEXT PARTY ID: "+nextPartyID);
196+
197+
196198
joinedParty++;
197199
ordinaryThief.setAssaultParty(nextPartyID, joinedParty == 1);
198200
logger(ordinaryThief, "Joined Party " + nextPartyID + ". Party Occupancy: " + joinedParty + "/" + N_THIEVES_PER_PARTY);
@@ -215,7 +217,6 @@ public synchronized boolean prepareExcursion() {
215217

216218
// leave concentration site
217219
inside[ordinaryThief.getThiefID()] = false;
218-
//logger(ordinaryThief, "Left concentration site. Concentration Site Occupancy: " + occupancy() + "/" + N_THIEVES_ORDINARY);
219220
notifyAll();
220221

221222
return true;

0 commit comments

Comments
 (0)