User Tools

Site Tools


harvester

This is an old revision of the document!


The Harvester could also be called a Roomba– this robot will pick up all the beepers, ending facing West at Street7, Avenue 2.

If you have a strategy, go for it, and try it out. If you want a suggestion you can try this:

  • A method could pick up a row beepers, stoping when there are no others
  • A method that would turn North and turn toward the new row
  • If there are beepers to pick up, continue again, otherwise turnOff()

Harvester.java

import kareltherobot.Robot;
 
public class Harvester extends Robot
{
 
    public Harvester(int street, int avenue, 
			        Direction direction, int beepers) 
    {
	super(street, avenue, direction, beepers);
 
    }
 
    public void nameYourMethodHere()
    {
    	// your code here
    }
}

HarvesterRunner.java

import kareltherobot.*;
 
public class HarvesterRunner implements Directions
{
	public static void main(String[] args) 
        {
		String field = "streets 8\n" + 
				"avenues 10\n" + 
				"beepers 3 4 1\n" + 
				"beepers 3 3 1\n" + 
				"beepers 6 7 1\n" + 
				"beepers 6 6 1\n" + 
				"beepers 6 5 1\n" + 
				"beepers 6 4 1\n" + 
				"beepers 6 3 1\n" + 
				"beepers 2 7 1\n" + 
				"beepers 2 6 1\n" + 
				"beepers 2 5 1\n" + 
				"beepers 2 4 1\n" + 
				"beepers 2 3 1\n" + 
				"beepers 5 7 1\n" + 
				"beepers 5 6 1\n" + 
				"beepers 5 5 1\n" + 
				"beepers 5 4 1\n" + 
				"beepers 5 3 1\n" + 
				"beepers 4 7 1\n" + 
				"beepers 4 6 1\n" + 
				"beepers 4 5 1\n" + 
				"beepers 4 4 1\n" + 
				"beepers 4 3 1\n" + 
				"beepers 7 7 1\n" + 
				"beepers 7 6 1\n" + 
				"beepers 7 5 1\n" + 
				"beepers 7 4 1\n" + 
				"beepers 7 3 1\n" + 
				"beepers 3 7 1\n" + 
				"beepers 3 6 1\n" + 
				"beepers 3 5 1";
		World.getWorld(field);
		World.setVisible();
                task();
	}
 
	private static void task() 
        {
		Harvester farmer = new Harvester(2,2,East,0);
                // your code here to use your new method(s)
		farmer.turnOff();
 
	}
 
}
harvester.1567173168.txt.gz · Last modified: 2019/08/30 09:52 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki