Karel J Robot - Chapter 2: Simple Robot Programs BACK TO KAREL MAIN
Simple Robot Programs The basic robot class is called Robot (see definition below). A Robot will only respond top the five commands listed. In order to perfrom tasks, the robot must be given combinations of these commands which, when put together in the appropriate order, complete the given task. |
The Robot Class of Robots class Robot |
defines a UrRobot named Karel at location (1,2), facing East with 0 beepers. After that, the robot is instructed to move twice, pick up a beeper, move again, etc.... When the robot has completed its task, it is shut down using the command turnOff. |
public class Tester implements Directions |
Program 2-1: The Newspaper Retrieval Task 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. See the initial situation below. World File: fig2-8.kwld BACK TO KAREL MAIN |
Program 2-2: Plant the Flag! Initial Situation Final Situation
World File: fig2-9.kwld BACK TO KAREL MAIN |
Program 2-3: The Leaky Shopping Bag On the way home from grocery shopping, Karel's bag ripped open, leaking a few items. The items are represented by - you guessed it - beepers. Karel needs to go back and pick these items up and return to his starting position. See the initial situation below. World File: fig2-10.kwld BACK TO KAREL MAIN |
Program 2-4: The Rearranger Karel must rearrange a column of beepers into a row of beepers. This requires picking the beepers up, then placing back down as seen in the example Note that the middle beeper does not change position. See the initial and final situations below. World File:fig2-11.kwld BACK TO KAREL MAIN |
Program 2-5: The Initializer Karel must spell out your inititals using beepers. Make the initials at least 5 beepers high. See below for an example using my initials, DRS. Start with an infinite number of beepers (recall that is done with a -1).
World File: blank2.kwld BACK TO KAREL MAIN |