Karel the Robot


How to build a world.

Double click on the WorldBuilder.bat file

Pick up a tool in the tools (button) panel. The name of the current tool is highlited.
Click where you want to place an item controlled by that tool.

For beepers click near an intersection when using the beeper tool.
For walls, click across streets (for vertical walls) and across avenues (for horizontal walls) when using the corresponding tool.

To put more than one beeper on a corner, click more than once with the beeper tool active.
To lower the number of beepers on a corner, control click the corner with the beeper tool.

To put an infinite number of beepers on a corner, control-click (with the beeper tool) when there are none on the corner.

To clear all the beepers from a corner, shift-click the corner when using the beeper tool.

To remove a wall from across a street, control click the wall segment with the appropriate wall tool.

To change the number of streets or avenues in the world, enter an integer into the corresponding text field and hit enter. Note that this doesn't restrict the world in any way. It just determines how much of it is drawn with street and avenues.

Save when you like. I've used an extension kwld here, but there is nothing special about it. It is neither assumed or automatically appended.

You can also open an existing world to edit/modify it.

The Clear World button will remove all elements from the world. (Be careful, there is no UNDO here.)

Quit the world builder by closing either of its windows. If your world has been modified since the last Save you will be prompted to save it again. Note that if you QUIT using a menu or command key, this extra Save prompt will NOT occur.


If you use an IDE, make a separate project for this and include the jar file. Make kareltherobot.WorldBuilder the main file for the project. In Codewarrior (on the Macintosh at least) you need to set the output to be a class folder rather than a jar file, since the main is in the existing jar file, and not in any code of your own. After you build this class folder will be empty.

(Image of a world with walls, beepers and the world builder)

World builder shows the position of the mouse in street,avenue coordinates if you have selected any tool. If the current tool is the Beeper tool, it shows the nearest corner (where the beeper will be placed if you click). If the current tool is the Horizontal Wall tool, it shows where the corner below the wall that will be placed. If the current tool is the Vertical Wall tool it shows the corner to the left of the wall that will be placed.


How to use a world created with the world builder.

Remember the name you used when you saved it. Say test.kwld.

Include a statement in your robot program to open it. Include this at the beginning of
your main task block.

 World.readWorld("test.kwld");

The world file will be opened and its content merged into your existing world.


Note on the files created by the world builder.

The format is compatible with that of the older simulator. However, there is no need to use the older version as this is an extension.

You can actually write the world files with a text editor.

Lines that do not start with a keyword for the builder are ignored. Elements can appear in any order. They are NOT case sensitive.

Here is a sample file.

KarelWorld
Streets 10 Avenues 20 beepers 3 4 1 beepers 4 2 1 eastwestwalls 3 2 4 northsouthwalls 4 2 2 northsouthwalls 4 3 3 northsouthwalls 1 5 5 northsouthwalls 1 4 4

The first line (KarelWorld) is not a keyword, but it might be in the future. It might also contain a version number eventually. It is ignored when reading now, but written when you save a world. The following gives the meaning of the current keywords. This is not expected to change.

  • Streets --The number of streets to draw.
  • Avenues --The number of avenues to draw.
  • beepers --The data is: street, avenue, number of beepers, without punctuation of any kind.
  • eastwestwalls -- The data is: North of Street, first avenue crossed, last avenue crossed. Last should be bigger than first (or equal).
  • northsouthwalls -- The data is: East of Avenue, first street crossed, last street crossed. Last should be bigger than first (or equal).

The world builder writes out a separate wall command for each segment of a wall (one block long). If you do it by hand, you can combine them.

If you create a world in a Robot program using the programming interface (in this version or the previous one) and save it, it will be consistent with the world builder files.


Karel Home Page