Karel, named after a Czech dramatist Karel Capek who popularized the word robot, is a robot simulator with a programming language that is used to teach students in high school and college the fundamentals of a programming language. Originally created to teach Pascal, it has since then switched over to an object-oriented language with syntax similar to that of C++. Object-oriented Karel supports functions, classes, two types loops (while and loop), recursion and one conditional operator (if-then-else).

The original book written for Pascal was titled "Karel The Robot: A Gentle Introduction to The Art of Programming" written by Richard Pattis. When Karel was transferred into the object-oriented world, the book primarily used is called "Karel++: A Gentle Introduction To the Art of Object-Oriented Programming" written by Richard Pattis along with three other people, Joseph Bergin, Mark Stehlik and Jim Roberts.

Although Karel++ was designed primarily for C++, it can also be converted into other object-oriented languages.

The architecture of the Karel package is such that developers can build their own user interfaces using virtually any toolkit they desire. All they need is a C interface to interact with the Karel engine. Karel was written this way to avoid being tied to any particular GUI toolkit. The choice of GUI toolkits is largely personal preference; (1)

Any sort of program or function described in this node will be based on the programming language outlined in the Karel++ book which compiles in the KarelWin(2) simulator. Karel will also be used to reference a generic robot class and not just a specific robot named Karel.

Karel's World
Karel runs in world that can only contain three possible objects. Robots, Beepers, and Walls. The world is surrounded by impregnable walls which prevents the robot from leaving the world. The world in which the robots are in is supposedly infinite, althougth the KarelWin simulator will only show the world up to 1000th avenue or street. Earlier versions of the simulator crashed when reaching the 32767th avenue or street, quite possibly because the robot ran out of fuel.

Movement in the world is done by streets (lanes that run east-west) and avenues (lanes that run north-south). Walls can also be placed inside of the world to block the streets and avenues. These walls are made of the same impregnable material that the world is enclosed in. If any robot runs into a wall it will shut itself down. Karel is only allowed to move inside of streets and avenues with each move beginning at a corner(between an avenue and a street) and ending at another corner. In a corner, beepers are also allowed to be placed onto the ground. Beepers are small plastic cones that emit a beeping noise which Karel can sense. More than one beeper can be placed on the ground although Karel does not know how many beepers are on the ground. Also of note is that there can be more than one robot in the world on the same corner.

Karel's Abilities
Karel possess some rudimentary abilities

  • Sight: Karel has a front-mounted camera that can detect if there is a wall in front of him. It can only see half a block away from itself.
  • Sound: Karel has a microphone that can detect the sound of a beeper on the corner that he is on.
  • Internal Compass: Karel knows which direction he is facing north(top of the screen), south(bottom of the screen), east(right side of the screen), west(left side of the screen).
  • Moving Arm: Karel has an arm that allows him to pick up beepers in the corner he is occupying. Karel carries a soundproof beeper-bag (obviously to prevent confusion between a beeper in his bag and a beeper in the corner). If Karel attempts to use his arm and there is no beeper on the corner, Karel will shutdown. Karel can also detect if there are any beepers in his bag by using the arm and can also detect other robots in the corner.

Karel's Internal Functions
The robots inside of the Karel world all contain five internal functions. Although functions can be added into the robots memory. The five internal functions are.

  • move(); - moves the robot forward one corner in the direction he is facing.
  • turnLeft(); - rotates the robot 90 degrees counter-clockwise
  • pickBeeper(); - picks a beeper off of a corner, if no beeper is present, the robot will shutdown with an error.
  • putBeeper(); - attempts to place a beeper on a corner, if there is no beeper in the robot's bag, it will shutdown.
  • turnOff(); - shuts the robot off, tasks that complete to the end will automatically shut the robot off.
The reason for not having a turnRight is stated by the authors. Although others, like myself, like to think differently.
Karel-Werke's designer purposely did not provide a built-in turnRight instruction. Would adding a turnRight to the primitive instructions allow the robot to perform any task it cannot accomplish without one? A moment's thought-and the right flash of insight-shows that the turnRight instruction is unnecessary; it does not permit robots to accomplish any new tasks. The key observation for verifying this conclusion is that a robot can manage the equivalent of a turnRight instruction by executing three turnLeft instructions
Karel also has some other functions that return values (TRUE/FALSE), each of these functions define themselves.. These conditionals can be NOTted (logical negation) by the exclamation point.

Some projects/assignments used in this programming language include Mazes, Stair Cleaning, Harvesting Beepers, Carpet. Contrary to C++, a Hello World program would probably be much harder to do.


1: http://karel.sourceforge.net/doc/html_node/karel_3.html
2: KarelWin and its documentation can be found here; http://faculty.ed.umuc.edu/~cklein/C++/other/Karelwin.zip
also fished for information was http://www.csis.pace.edu/~bergin/karel.html

Log in or register to write something here or to contact authors.