@@ -55,12 +55,16 @@ public void setRoomID(int roomID) {
5555 repos .setRoomID (roomID );
5656 }
5757
58+ public void resetThieves () {
59+ thieves = new OrdinaryThief [N_THIEVES_PER_PARTY ];
60+ nThieves = 0 ;
61+ nextThiefID = roomID = -1 ;
62+ }
63+
5864 public AssaultParty (int id , GeneralRepos repos ) throws MemException {
5965 this .id = id ;
60- this .thieves = new OrdinaryThief [N_THIEVES_PER_PARTY ];
61- nThieves = 0 ;
62- nextThiefID = roomID = -1 ;
6366 this .repos = repos ;
67+ resetThieves ();
6468 }
6569
6670 @ Override
@@ -78,6 +82,7 @@ public synchronized void sendAssaultParty() {
7882 MasterThief master = (MasterThief ) Thread .currentThread ();
7983 master .setThiefState (MasterThiefStates .DECIDING_WHAT_TO_DO );
8084 GenericIO .writelnString ("Sending " + this + " to Room " + roomID );
85+ master .sentAnyAssaultParty (true );
8186
8287 repos .setAssaultPartyID (id );
8388
@@ -104,7 +109,11 @@ public synchronized void reverseDirection() {
104109
105110 public synchronized void crawlIn () {
106111 OrdinaryThief thief = (OrdinaryThief ) Thread .currentThread ();
107- thieves [nThieves ++] = thief ;
112+
113+ try {
114+ thieves [nThieves ++] = thief ;
115+ } catch (ArrayIndexOutOfBoundsException e ) {}
116+
108117 thief .setThiefState (OrdinaryThiefStates .CRAWLING_INWARDS );
109118 repos .setOrdinaryThiefState (thief .getThiefID (), OrdinaryThiefStates .CRAWLING_INWARDS );
110119 repos .setOrdinaryThiefId (thief .getThiefID ());
@@ -154,13 +163,15 @@ public synchronized void crawlOut() {
154163 }
155164
156165 private boolean crawl (OrdinaryThief thief , int goal , int endState , boolean backwards ) {
157- printPositions ();
166+ // printPositions();
158167
159168 while (thief .canMove ()) // move the most
160169 move (thief , goal , backwards );
161170
162- if (!wakeUpNextThief (thief , backwards )) // wake up next thief
163- printPositions (); // if last thief, print final positions
171+ //if (!wakeUpNextThief(thief, backwards)) // wake up next thief
172+ //printPositions(); // if last thief, print final positions
173+ wakeUpNextThief (thief , backwards );
174+
164175
165176 repos .setOrdinaryThiefPosition (thief .getThiefID (), thief .getPosition ());
166177
@@ -196,7 +207,7 @@ private void move(OrdinaryThief thief, int goal, boolean backwards) {
196207 // make the move
197208 updatePosition (thief , distanceToMove , backwards );
198209 thief .setMovesLeft (thief .getMovesLeft () - distanceToMove );
199- loggerCrawl (this , thief , "MOVED " + (backwards ? "-" : "" ) + distanceToMove + " positions to " + thief .getPosition ());
210+ // loggerCrawl(this, thief, "MOVED " + (backwards ? "-" : "") + distanceToMove + " positions to " + thief.getPosition());
200211
201212 if (thief .getPosition () == goal ) {
202213 noMoreMoves (thief );
@@ -233,7 +244,6 @@ private boolean wakeUpNextThief(OrdinaryThief thief, boolean backwards) {
233244 if (currentThief == nextThief ) return false ;
234245
235246 // only choose next thief if not all thieves are at the room
236- GenericIO .writelnString ("Counter: " + counter );
237247 if (counter != N_THIEVES_PER_PARTY ) {
238248 nextThiefID = nextThief .getThiefID ();
239249 nextThief .resetMovesLeft ();
@@ -256,14 +266,14 @@ private boolean wakeUpNextThief(OrdinaryThief thief, boolean backwards) {
256266
257267 private boolean checkExcessMove (OrdinaryThief thief , int distanceToMove , boolean backwards ) {
258268 OrdinaryThief newLowerThief = !backwards ? lowerThief (thief ) : higherThief (thief );
259- GenericIO .writelnString ("new lower thief: " + newLowerThief );
269+ // GenericIO.writelnString("new lower thief: " + newLowerThief);
260270 int distanceToNextThief = Math .abs (newLowerThief .getPosition () - thief .getPosition ());
261271 if (distanceToNextThief > MAX_SEPARATION_LIMIT ) {
262272 int excessMove = distanceToMove - distanceToNextThief ;
263273 // fix position
264274 updatePosition (thief , excessMove , !backwards );
265- loggerCrawl (this , thief , "[EXCESS MOVE] fixing..." );
266- loggerCrawl (this , thief , "MOVED " + excessMove + " positions to " + thief .getPosition ());
275+ // loggerCrawl(this, thief, "[EXCESS MOVE] fixing...");
276+ // loggerCrawl(this, thief, "MOVED " + excessMove + " positions to "+ thief.getPosition());
267277 return true ;
268278 }
269279 return false ;
@@ -283,8 +293,8 @@ private boolean checkOccupiedMove(OrdinaryThief thief, boolean backwards) {
283293 while (inOccupiedPos (thief )) {
284294 wrongMove = true ;
285295 updatePosition (thief , 1 , !backwards );
286- loggerCrawl (this , thief , "[MOVED TO OCCUPIED POSITION] fixing..." );
287- loggerCrawl (this , thief , "MOVED " + "1 positions to " + thief .getPosition ());
296+ // loggerCrawl(this, thief, "[MOVED TO OCCUPIED POSITION] fixing...");
297+ // loggerCrawl(this, thief, "MOVED " + "1 positions to "+ thief.getPosition());
288298 }
289299 return wrongMove ;
290300 }
0 commit comments