import becker.robots.*; /** A class of robot that can harvest a field of Things. * The field can be any rectangular size * BUT the field must be solid with things * AND the robot must be positioned on the Thing at the upper left corner of the field. * * The robot moves east, picking up dots, as long as there is no blank intersection. * When the robot gets to an intersection with no dots, it turns around, returns * to where it started, and then moves down to position itself for picking up another row. * The robot stops when it gets positioned to a blank intersection. * @author Duncan Buell **/ public class Harvester extends RobotSE { /** Construct a new Harvester robot. * @param aCity The city where the robot will be created. * @param str The robot's initial street. * @param ave The robot's initial avenue. * @param dir The robot's initial direction, one of {Direction.NORTH, SOUTH, EAST, WEST}. **/ public Harvester(City aCity, int str, int ave, Direction dir) { super(aCity,str,ave,dir); } /*******************************************************************************/ /** Harvest a field of things. The robot is assumed to start on the north-west * corner of the field and to be positioned on top of a Thing that can be * picked up. **/ public void harvestField() { while(this.canPickThing()) { this.harvestOneRow(); this.positionForNextRow(); } } // public void harvestField() /*******************************************************************************/ /** Harvest one row of things, then turn around and return to the starting * position. The robot is assumed to start at the east end of a row of Things * and to be positioned over a Thing that can be picked up. **/ private void harvestOneRow() { int moveCount; moveCount = 0; while(this.canPickThing()) { this.pickThing(); this.move(); moveCount = moveCount + 1; } this.turnAround(); while(moveCount > 0) { this.move(); moveCount = moveCount - 1; } } // public void harvestOneRow() /*******************************************************************************/ /** Position for the next row. That is, from a position facing west at the * west edge of a row just harvested, move down one row and turn to face east. **/ private void positionForNextRow() { this.turnLeft(); this.move(); this.turnLeft(); } // private void positionForNextRow() /*******************************************************************************/ /** * Harvest one intersection. **/ public void harvestIntersection() { while (this.canPickThing()) { this.pickThing(); } } // public void harvestIntersection() }