class BasicRobot{ boolean worthySetting() { //determine wether a beeper stack is to be processed boolean returnValue; turnLeft(); if (myworld.frontIsClear(xLoc(),yLoc()+1,east) returnValue = false; else returnValue = true; return returnValue; } void processStack() { turnLeft(); //take all beppers, and count them for later use int i; while (nextToABeeper()){ pickBeeper(); i++; } //walk along the wall until reaching the first cleared on the right spot while (!myworld.rightIsClear(xLoc(),yLoc(),north)) move(); //drop all beepers but one for (i; i>1 ; i--) putBeeper(); //return to main line and head east turnLeft(); turnLeft(); while (frontIsClear()) move(); turnLeft(); } void endSequence() { //return to (1,1) and head East turnLeft(); turnLeft(); while (frontIsClear()) move(); turnLeft(); turnLeft(); //drop l00t while (anyBeepersInBag()) putBeeper(); //go to sleep turnOff(); } public static void main(String[ ] args){ //make sure that Karel is east-headed. while (!karel.facingEast()) karel.turnLeft( ); //get Karel to move until the front is blocked, checking for a beeper on each step and invoking the proper sequence of methods while (karel.frontIsClear) { karel.move(); if (karel.nextToABeeper()) { if (karel.worthySetting()) karel.processStack(); } karel.endSequence(); } }