Karel Language Reference

Primitives

  • void movek() - Moves Karel one intersection forward
  • void turnLeft() - Pivots Karel 90 degrees left
  • void pickBeeper() - Takes a beeper from the current intersection and puts it in the beeper bag
  • void putBeeper() - Takes a beeper from the beeper bag and puts it at the current intersection
  • void turnOn(char* path) - Turns Karel on
  • void turnOff() - Turns Karel off

Sensors

  • bool frontIsClear() - Returns true if there is no wall directly in front of Karel. Returns false if there is a wall.
  • bool frontIsBlocked() - Returns true if there is a wall directly in front of Karel. false otherwise.
  • bool leftIsClear() - Returns true if there is no wall immediately to Karel's left. false if there is
  • bool leftIsBlocked() - Returns true if there is a wall immediately to Karel's left. false otherwise
  • bool rightIsClear() - Returns true if there is no wall immediately to Karel's right. false if there is
  • bool rightIsBlocked() - Returns true if there is a wall immediately to Karel's right. false otherwise
  • bool beepersPresent() - Returns true if Karel is standing at an intersection that has a beeper. false otherwise
  • bool noBeepersPresent() - Returns true if there is not beeper at the current intersection. false if there is a beeper at the current intersection
  • bool facingNorth() - Returns true if Karel is facing north. false otherwise
  • bool notFacingNorth() - Returns true if Karel is not facing north. false if he is facing north
  • bool facingSouth() - Returns true if Karel is facing south. false otherwise
  • bool notFacingSouth() - Returns true if Karel is not facing south. false if he is facing south
  • bool facingEast() - Returns true if Karel is facing east. false otherwise
  • bool notFacingEast() - Returns true if Karel is not facing east. false if he is facing east
  • bool facingWest() - Returns true if Karel is facing west. false otherwise
  • bool notFacingWest() - Returns true if Karel is not facing west. false if he is facing west
  • bool beepersInBag() - Returns true if there is at least one beeper in Karel's beeper bag. false if the beeper bag is empty
  • bool noBeepersInBag() - Returns true if Karel's beeper bag is empty. false if there is at least one beeper in the beeper bag

Misc

  • void setStepDelay(int) - Sets delay of one Karel's step in miliseconds
  • void loop(int) - Repeats Karel's instruction in a loop

Library

Here you can find the original library of Karel the Robot, including the library installation instructions.

Karel's World

  • Text file with .kw extension
  • Example of the first line: 7 3 1 2 E 5
    • 7 3 - World dimensions (first horizontal, second vertical)
    • 1 2 - Position of Karel the Robot in the beginning of your program (first horizontal, second vertical)
    • E - Direction of Karel the Robot in the beginning of your program
    • 5 - Number of beepers in Karel's bag in the beginning of your program
  • Any other line starting with B represents beeper(s) placed in the world, example: B 5 1 2
    • B - This is beeper data
    • 5 1 - Position in the world (first horizontal, second vertical)
    • 2 - Number of beepers placed in this position
  • Any other line starting with W represents wall, example: W 5 1 E
    • W - This is wall data
    • 5 1 - Position in the world (first horizontal, second vertical)
    • E - Direction to which the wall is placed from the given position (because walls are placed between particular positions)