Login to Your Account
Results 1 to 1 of 1

Thread: KAREL, the Robot!

Popular topic for study

Digital signatures

Digital signatures enable the recipient of information to verify the authenticity of the information’s origin, and also verify that the information is intact. Thus, public key digital signatures provide authentication and data integrity.Click here for free notes. Read this topic
  1. #1
    Fuchcha FaaDoO Engineer
    Join Date
    Apr 2011

    Gender: : Female

    City : Srinagar

    Information KAREL, the Robot!



    Karel is a very simple robot living in a very simple world. By giving Karel a set of commands, you can direct it to perform certain tasks within its world. The process of specifying those commands is called programming. Initially, Karel understands only a very small number of predefined commands, but an important part of the programming process is teaching Karel new commands that extend its capabilities. When you program Karel to perform a task, you must write out the necessary commands in a very precise way so that the robot can correctly interpret what you have told it to do. In particular, the programs you write must obey a set of syntactic rules that define what commands and language forms are legal. Taken together, the predefined commands and syntactic rules define the Karel programming language.

    The Karel programming language is designed to be as similar as possible to Java so as to ease the transition to the language you will be using all quarter. Karel programs have much the same structure and involve the same fundamental elements as Java programs do. The critical difference is that Karel’s programming language is extremely small, in the sense that it has very few commands and rules. It is easy, for example, to teach the entire Karel language in just a couple of hours, which is precisely what we do in CS106A. At the end of that time, you will know everything that Karel can do and how to specify those actions in a program. The details are easy to master. Even so, you will discover that solving a problem can be extremely challenging. Problem solving is the essence of programming; the rules are just a minor concern along the way.

    In sophisticated languages like Java, there are so many details that learning these details often becomes the focus of the course. When that happens, the much more critical issues of problem solving tend to get lost in the shuffle. By starting with Karel, you can concentrate on solving problems from the very beginning. And because Karel encourages imagination and creativity, you can have quite a lot of fun along the way.

    Requirements and Installation

    The Karel J. Robot IDE was developed is developed with Java 1.4.2 and should presumably run with all Java 1.4.x versions. The IDE will not run with Java versions prior to 1.4 and 1.5; so use either version 1.4.x or >1.6.0. Windows-users start the IDE by double clicking theKarelJIDE.bat file. Linux or Unix users start the script In the "Rechnerbetriebsgruppe" (RBG) computer pools at Darmstadt University the IDE is already installed and can be started by typing KarelJIDE
    The Karel J. Robot IDE is designed to be used along with the courses "Introduction to Computer Science", "Grundzüger der Informatik" and "Algemeine Informatik" at the Darmstadt University where exercises include writing programs in the Karel J. Robot programming language.

    The IDE provides a convenient way of submitting your results to your tutor who will review your program. The first time the IDE is started a dialog is displayed for entering exercise submission settings. This dialog can also be opened by pressing the "Settings" button. There are two modes of submitting you exercise. Regardless of which mode you choose you must enter a group name (bottom-most field). The name must only include letters and digits. This group name is specific to you. If you are dealing with the exercises on your own, you are a "one-man-group" (or "one-woman" of course). If it is allowed in your course to work on the exercises in groups, the group name is specific to your study group; only submit an exercise once per group. Your tutor will give you the name you have to enter. If you have an internet connection you should use email submission.

    Then no more interaction from you is required then pressing the "Submit" button for sending your program to your tutor. You will also receive a disposition notification when the tutor opens the email with your submission. To use email submission you must enter a valid SMTP host. This is a server for outgoing emails. Because the IDE does not implement protocols to authenticate you at the server you should enter the server of the "RBG" here ( which does not require an authentication by the sending application but requires you to have a VPN-connection to the university network. Enter the email address you received from the RBG and the email address of your tutor. If you do not have an internet connection select the "No Internet Connection" check box. In this case pressing the "Submit" button will open a dialog that allows you to choose a directory. In this directory a ZIP archieve file will be created. You must then deliver this file to your tutor.


    The Karel J. Robot IDE is based on the following technologies:
    • Java 1.4
    • Java Mail API 1.3.1
    • Java Activation API 1.0.2
    • Eclipse JDT 3.0 Java Compiler
    • JavaCC
    • BAT 0.9

    The Integrated Development Environment (IDE) as shown in the picture above is mainly divided in four parts: A bar of buttons, the world (center right), the editor (center left) and an output field

    The Tool Itself
    Robots in the Karel J. Robot world live in a world that consists of the first quadrant of the Cartesian plane, with streets running horizontally (East-West) at the integer points and avenues running vertically (like New York City). The world can have walls between the streets and avenues and there is also a wall bounding on the south and on the west. The robots cannot penetrate walls. The world also contains beepers that the robots can pick up and carry. Here is a figure of a south facing robot in a world with two beepers. Theoretically the world extends infinitely to the north and east, though the implementation restricts it to a very large, but not infinite, space. We show only a small section here.

    The simulation speed can be set with the slider and the simulation run can be paused and resumed at will. The simulator itself is just a jar file, and was developed in Java 1.1, so it should run anywhere. The simulation is shown running on a Macintosh.
    The simplest kind of robot is an ur_Robot (built-in -- UrRobot in Karel J Robot) that can move, turn-off, and turn left, pick up and put down beepers. It will automatically (error) halt if it tries to move through a wall or pick up a beeper when there is none available on its corner or tries to put one down when it possesses none. The first three chapters of the book work only with ur_Robots.
    Another built in class is Robot, which extends ur_Robot, and can additionally sense its direction, whether it is facing a wall, whether it has beepers in its beeper-bag, and whether there are beepers on the current corner. Finally, a Robot can sense the presence of other Robots on the current corner. All other conditions and actions (turnRight,…) must be programmed by the user.
    A robot world with a single Robot and no beepers can be proved to be equivalent to a Turing Machine, and so problems of arbitrary complexity can be solved in this simple graphic world. Pattis proved this in the early 1980's.

    The Output Field

    The output field shows the output of the IDE. This can be error or status messages from the IDE directly or output generated by a running Karel J. Robot program. Error messages will be painted red. When you select a line in the output field which displays an error in your program or the stack trace of an exception produced when running your program, the appropriate line is selected in the editor. Pressing the "Clear" button or the keyboard shortcut Ctrl-L clears the output field.
    The Karel J. Robot language

    In the language as it is understood by the Karel J. Robot IDE each program consists of one file. A file must contain exactly one task { ... } block. Between the curly braces you write the program code which will be executed when you start the program. The block can contain any statement as allowed by\. And, additionally the loop(<number expression>) <statement or { block }>statement (also see the manuscript).

    The program can use the classes UrRobot, Robot and World and define new "Robot"-classes. This means classes that either extend UrRobot or Robot or extend another "Robot"-class. If you do not define a constructor in your "Robot"-class it will always have the standard-robot-constructor which can be used like new MyRobot(5, 4, 0, North). This will create and deliver a new robot of type MyRobot to street 5, avenue 4 looking northwards and having zero beepers. However you can also write and use your own constructors or even write your own version of this standard-constructor.
    The Karel J. Robot IDE supports one additional primitive type other than for example int or boolean which are part of Java. The new type is called direction and is used by the standard-robot-constructor and returned by thedirection() method of class UrRobot as the direction of the robot. There are four values of this primitive type, North, East, South and West. Unlike in the Karel J. Robot manuscript you can not use the literal infinity to specify that a robot as an infinit number of beepers. You can work around this shortcoming by simply using a large number.

    Karel J. Robot handles concurrency in two different ways, one of which is currently experimental. The first is simply to adopt Java concurrency primitives (Monitors and Synchronized methods). This is actually a good model for showing novice students some of the difficulties with concurrent programming such as race conditions and deadlock. One Robot task for two robots is to race to the origin from different directions and to pick up a beeper at that spot and then halt. The only way the Robot can know that it is at the origin is by finding the beeper. However the first robot to the origin will remove the beeper from the corner and so the second won't find it and will therefore crash into the wall. I use this to introduce the idea of a race condition.
    Another simple example is Dining Robots in which the robots eat and think, requiring the usual shared forks in order to eat. The robot philosophers can be seen to think and eat by the differences in their actions. The program can be written to show or to avoid deadlock. Here are four Philosopher Robots and the "beeper forks" that they need to eat. They will move into the center to eat once they get two forks and will move backwards to think once they replace their forks.

    The second method of doing concurrency (web site only) is to use something like Communicating Sequential Processes (CSP) with a form of message passing between threads. This is a fundamentally safer and easier to understand methodology, but the current implementation and interface design is experimental and has not yet been proven. This framework uses the Strategy Pattern which is an elementary design pattern discussed in Design Patterns by Gamma, Helm, Johnson, and Vlissides (Addison-Wesley, 1995).


    Karel J. Robot can be an effective way to introduce object-oriented programming to novices. Its pedagogy was carefully designed and its graphic nature is appealing to students. It uses an easily understood metaphor that is quite consistent overall.
    One of the main advantages of the Karel philosophy, however, is that it gives the students simple versions of a large number of tools that enable sophisticated problem solving. Thus, Karel forms the first cycle of a Spiral teaching approach, and students will have the ability to successively deepen their knowledge of many topics while having the tools to build exploratory programs from the very beginning of the course. This early overview of the programming process and its reinforcement of the most important ideas is its chief goal and the reason for its continuing success.
    Finally, this author believes that if students are to easily achieve a high degree of skill in object oriented programming, then their programming practice must NOT begin with the procedural paradigm. Everything in the Karel++ and Karel J. Robot philosophy is designed to avoid this trap. This is because the mind set of the object-oriented programmer is very different than that of the procedural programmer and that these mind sets clash

    Last edited by FaaDoO-Engineer; 10th May 2011 at 07:29 PM. Reason: Post Reformatted!

Tags for this Thread