@@ -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
0 commit comments