newspaper_retrieval
Newspaper Retrieval
Every morning Karel is awakened in bed when the newspaper, represented by a beeper, is thrown on the front porch of his house. Program Karel to retrieve the paper and bring it back to bed. Karel is inside in the southwest corner (Street 3, Avenue 4), while the newspaper is outside on the other side of the wall (Street 3, Avenue 3) Below is the description of the world:
KarelWorld streets 10 avenues 10 beepers 3 3 1 eastwestwalls 5 3 3 eastwestwalls 6 6 6 eastwestwalls 6 5 5 eastwestwalls 2 6 6 eastwestwalls 6 4 4 eastwestwalls 2 5 5 eastwestwalls 2 4 4 eastwestwalls 4 3 3 northsouthwalls 6 3 3 northsouthwalls 6 4 4 northsouthwalls 6 5 5 northsouthwalls 6 6 6 northsouthwalls 3 3 3 northsouthwalls 3 4 4 northsouthwalls 3 6 6
You can download this kwld file: CollectNewspaper.kwld
Here is some starter code:
import java.awt.Color; import kareltherobot.*; public class Newspaper implements Directions { public static void main(String[] args) { World.setDelay(30); World.setBeeperColor(Color.BLUE); //World.readWorld("CollectNewspaper.kwld"); World.getWorld("KarelWorld\n" + "streets 10\n" + "avenues 10\n" + "beepers 3 3 1\n" + "eastwestwalls 5 3 3\n" + "eastwestwalls 6 6 6\n" + "eastwestwalls 6 5 5\n" + "eastwestwalls 2 6 6\n" + "eastwestwalls 6 4 4\n" + "eastwestwalls 2 5 5\n" + "eastwestwalls 2 4 4\n" + "eastwestwalls 4 3 3\n" + "northsouthwalls 6 3 3\n" + "northsouthwalls 6 4 4\n" + "northsouthwalls 6 5 5\n" + "northsouthwalls 6 6 6\n" + "northsouthwalls 3 3 3\n" + "northsouthwalls 3 4 4\n" + "northsouthwalls 3 6 6"); World.setVisible(); task(); } public static void task() { Robot karel = new Robot(3,4,West,0); } }
Karel J Robot API (Application Programming Interface)
newspaper_retrieval.txt · Last modified: 2022/08/23 09:40 by frchris