Skip to content

Commit de3c015

Browse files
committed
fixed issue in assigning parties
1 parent 4caa162 commit de3c015

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/sharedRegions/AssaultParty.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public void setRoom(Museum museum, Museum.Room room) {
8686
logger(this, "Was given room " + room);
8787
GenericIO.writelnString(room + " has distance " + room.getDistance() + " and paintings " + room.getPaintings());
8888
this.room = room;
89-
museum.clearRooms(id);
9089
room.setAssaultPartyID(id);
9190
inRoom = 0;
9291
}
@@ -97,7 +96,6 @@ public void setRoom(Museum museum, Museum.Room room) {
9796
*/
9897
public void resetAssaultParty() {
9998
begin = false;
100-
room = null;
10199
nextThiefID = -1;
102100
for (int i = 0; i < N_THIEVES_PER_PARTY; i++)
103101
thieves[i] = null;
@@ -179,9 +177,13 @@ public synchronized void crawlIn() {
179177
OrdinaryThief ordinaryThief = (OrdinaryThief) Thread.currentThread();
180178
ordinaryThief.setThiefState(OrdinaryThiefStates.CRAWLING_INWARDS);
181179
int thiefID = ordinaryThief.getThiefID();
182-
addThief(thiefID);
183180

184-
if (nextThiefID == -1) nextThiefID = thiefID;
181+
if (nextThiefID == -1) {
182+
resetAssaultParty();
183+
nextThiefID = thiefID;
184+
}
185+
186+
addThief(thiefID);
185187

186188
do {
187189
// wait until master says to begin
@@ -281,10 +283,13 @@ private void updateThiefPosition(int thiefID, int move, boolean backwards) {
281283
private boolean wrongSeparation(boolean backwards) {
282284
orderThieves(backwards);
283285

284-
boolean valid0 = Math.abs(thieves[0].getPosition() - thieves[1].getPosition()) <= MAX_SEPARATION_LIMIT;
285-
boolean valid1 = Math.abs(thieves[1].getPosition() - thieves[2].getPosition()) <= MAX_SEPARATION_LIMIT;
286-
//if (!valid0 || !valid1) GenericIO.writelnString("WRONG SEPARATION");
287-
return !valid0 || !valid1;
286+
for (int i = 0; i < N_THIEVES_PER_PARTY-1; i++) {
287+
int currentPos = thieves[i].getPosition();
288+
int nextPos = thieves[i+1].getPosition();
289+
if (Math.abs(currentPos - nextPos) > MAX_SEPARATION_LIMIT)
290+
return true;
291+
}
292+
return false;
288293
}
289294

290295
// make sure thieves are not overlapping

src/sharedRegions/CollectionSite.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,17 @@ public CollectionSite(GeneralRepos repos) {
9090
public synchronized int appraiseSit() {
9191
MasterThief masterThief = (MasterThief) Thread.currentThread();
9292

93-
if (endHeist && occupancy() == 0)
93+
masterThief.setRoomState(roomState);
94+
95+
if (endHeist && occupancy() == 0 && masterThief.getConcentrationSite().occupancy() == N_THIEVES_ORDINARY)
9496
return END_HEIST;
9597

96-
if ((masterThief.getActiveAssaultParties() > 0)
98+
/*
99+
logger(masterThief, "Appraising situation. Concentration Site Occupancy: " + masterThief.getConcentrationSite().occupancy() + "/" + N_THIEVES_ORDINARY);
100+
logger(masterThief, "Appraising situation. Active Assault Parties: " + masterThief.getActiveAssaultParties() + "/" + N_ASSAULT_PARTIES);
101+
logger(masterThief, "Appraising situation. Thief Queue Size: " + thiefQueue.size() + "/" + N_ASSAULT_PARTIES);
102+
*/
103+
if ((masterThief.getActiveAssaultParties() > 0 && masterThief.getConcentrationSite().occupancy() < N_THIEVES_PER_PARTY)
97104
|| thiefQueue.size() > 0)
98105
return WAIT_FOR_CANVAS;
99106

src/sharedRegions/ConcentrationSite.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public int occupancy() {
4040
return count;
4141
}
4242

43+
public void endHeist(boolean endHeist) {
44+
this.endHeist = endHeist;
45+
}
46+
4347
public ConcentrationSite(GeneralRepos repos) throws MemException {
4448
endHeist = makeParty = false;
4549
inside = new boolean[N_THIEVES_ORDINARY];

0 commit comments

Comments
 (0)