@@ -63,7 +63,7 @@ public class CollectionSite {
6363 /**
6464 * Boolean to signal the closing of the party
6565 */
66- private boolean closingParty ;
66+ private int closingParty ;
6767
6868 /**
6969 * General Repository
@@ -136,8 +136,7 @@ private int numberPartiesInSite() {
136136 */
137137 public CollectionSite (GeneralRepos repos ) {
138138 canvas = 0 ;
139- appraisedThief = -1 ;
140- closingParty = false ;
139+ appraisedThief = closingParty = -1 ;
141140 registeredThieves = new boolean [N_THIEVES_ORDINARY ];
142141 inside = new boolean [N_THIEVES_ORDINARY ];
143142 roomState = new int [N_ROOMS ];
@@ -160,9 +159,11 @@ public synchronized int appraiseSit(int concentrationSiteOccupancy) {
160159 if (endHeist && occupancy () == 0 && concentrationSiteOccupancy == N_THIEVES_ORDINARY )
161160 return END_HEIST ;
162161
163- logger (this , "Active Parties: " +masterThief .getActiveAssaultParties ()+", Concentration Occupancy: " +concentrationSiteOccupancy +", Parties in Site: " +numberPartiesInSite ()+", Thief Queue: " +thiefQueue .size ());
164- if (masterThief .getActiveAssaultParties () > 0 || (concentrationSiteOccupancy < N_THIEVES_PER_PARTY && numberPartiesInSite () > 0 )
165- || thiefQueue .size () > 0 )
162+ //logger(this, "Active Parties: "+masterThief.getActiveAssaultParties()+", Concentration Occupancy: "+concentrationSiteOccupancy+", Parties in Site: "+numberPartiesInSite()+", Thief Queue: "+thiefQueue.size());
163+ //logger(this, "Free Party: "+masterThief.getFreeParty());
164+ if ((masterThief .getActiveAssaultParties () > 0 && concentrationSiteOccupancy < N_THIEVES_PER_PARTY && numberPartiesInSite () > 0 )
165+ || thiefQueue .size () > 0
166+ || masterThief .getFreeParty () == -1 )
166167 return WAIT_FOR_CANVAS ;
167168
168169 while (occupancy () > 0 ) {
@@ -229,7 +230,7 @@ public synchronized void handACanvas() {
229230 for (int thiefFromParty : thievesOfParty )
230231 registeredThieves [thiefFromParty ] = false ;
231232 printRoomState ();
232- closingParty = true ;
233+ closingParty = ordinaryThief . getPartyID () ;
233234 if (roomState [ordinaryThief .getRoomID ()] == BUSY_ROOM )
234235 roomState [ordinaryThief .getRoomID ()] = FREE_ROOM ;
235236 }
@@ -268,16 +269,17 @@ public synchronized void collectACanvas() {
268269
269270 logger (masterThief , "Waking up Ordinary " + nextThief .thiefID + " to leave the collection site." );
270271
271- notifyAll ();
272-
273- if (closingParty ) {
274- closingParty = false ;
272+ if (closingParty != -1 ) {
275273 masterThief .setActiveAssaultParties (masterThief .getActiveAssaultParties () - 1 );
274+ masterThief .setPartyActive (closingParty , false );
275+ closingParty = -1 ;
276276 }
277277
278278 if (thiefQueue .size () == 0 )
279279 appraisedThief = -1 ;
280280
281+ notifyAll ();
282+
281283 masterThief .setThiefState (MasterThiefStates .DECIDING_WHAT_TO_DO );
282284 //repos.updateMasterThiefState(MasterThiefStates.DECIDING_WHAT_TO_DO);
283285 }
0 commit comments