Karel J Robot - Chapter 2: Simple Robot Programs BACK TO KAREL MAIN
Simple Robot Programs The basic robot class is called UrRobot (see definition below). An UrRobot 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 UrRobot Class of Robots class UrRobot |
defines a UrRobot named Karel at location (1,2), facing East with 0 beepers. After that, the rpbpt is instructed to move twice, pick up a bepper, 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 StairClimber Class Karel must learn to climb stairs, picking up a beeper from each step. See the initial and final situations below.
World File: fig3-1.kwld BACK TO KAREL MAIN |
Program 3-2:
The ShelfStocker Class
Initial Situation Final Situation
World File: Shelf.kwld BACK TO KAREL MAIN |
| Program 3-3: The Harvester Class Karel must “harvest” a field of beepers. Each row of will consist of 5 beepers, and the number of rows will always be an even number. See the initial and final situations below.
World File: fig3-2.kwld BACK TO KAREL MAIN |
| Program 3-4: The Pinsetter Class Karel just got a job as a pinsetter at the local bowling alley. His job requires him to set up 10 pins in the normal configuration. See the initial and final situations below.
World File: blank.kwld BACK TO KAREL MAIN |
| Program 3-5: The Mover Class Karel is rearranging office furniture. he needs to move employees desks from one cubicle to the one adjacent to it. He will then move on and do the next desk, etc... . Beginning and ending situations are as shown below. Karel begins the task at (1, 3) facing East. World File: mover.kwld BACK TO KAREL MAIN |
Program 3-6: The Planter Class World File: planter.kwld BACK TO KAREL MAIN |