[Top] - [Next] - [Previous]

The World Builder

  1. Positioning Karel
  2. Loading and Placing Beepers
  3. Building and Destroying Wall Sections
  4. Exiting the World Builder
  5. Miscellaneous World Builder Commands

In Chapter 2, while starting the Karel simulator, you were prompted with a request for how to get an initial situation; you answered by typing an R. This answer directed the simulator to read Karel's initial situation from a file and immediately start execution of Karel's program in that initial situation. In this chapter we discuss how to use the World Builder, which allows you to position Karel, put walls and beepers in his world, and generally create your own initial situations. If you want to use the World Builder, when asked the following question, you should reply by typing B (or just use the default answer by pressing the return key).

     Where to get initial situation([B]uild or [R]ead from a file)[B]:B

You will next be asked whether you want to start with a blank world (one that has no walls or beepers) or want to modify a world that has already been stored in a file. The question appears as:

     How do you want to start([B]lank World or [P]reRead world)[P]:_

If you want to start with a blank world, you should type a B. The World Builder would then draw a blank world with Karel positioned facing east on the origin.

If you want to start with a file containing an already existing world, type a P, which also is the default answer. The World Builder would then ask you for the name of this pre-existing world file, and then it would read it and draw that initial situation on your screen. In both cases, once the simulator has drawn the world, you can then enter world building commands to alter the current initial situation.

The following five sections in this chapter discuss the commands that you can give the World Builder, which prompts with the following request for World Builder commands:

     World Builder is ready to accept a command(type ? for help):_

You can see a brief summary of the commands discussed in this chapter by typing a ? to the World Builder prompt line (also, see Appendix I.3). If your screen ever accidentally becomes erased, issue the R command, which Redraws the world on your screen.

Positioning Karel

The symbol for Karel is used as the focus of attention in the World Builder. To build a wall or put down a beeper, you first must move Karel to the correct corner. Thus, moving Karel through his world is of paramount importance to the World Builder, so we shall discuss the Move command first. Because it is so useful, the Move command can take many forms. A representative sample of M commands and their associated meanings is listed below:

MN5      Moves Karel 5 blocks North (his direction remains unchanged).
ME       Moves Karel 1 block East (his direction remains unchanged).
M4,9     Moves Karel to the corner of 4thStreet and 9thAvenue. The direction
         that he is facing remains unchanged. Remember to type the street
         number first, followed by the avenue number.  Also remember to
         separate these two numbers y a comma.
MO       Moves Karel to the Origin and faces him East.
MR       Moves Karel to the position that he occupied when the World Builder
          was entered.

Also, if you just press the return key, Karel moves one block forward in the direction that he is facing. Similarly, if you type 5 followed by return, Karel moves 5 blocks forward in the direction that he is facing (even a negative number is meaningful: a -5 moves him backward 5 blocks).

You don't have to worry about Karel going off the screen: if you issue a move command that moves him off the current screen, the display will automatically be erased and redrawn, with Karel's new position centered on the screen. Finally, if you try to move Karel past either of the boundary walls, he will just stop at the corner nearest the boundary.

The next World Builder command allows you to face Karel in any direction. It is the F command, and one simple example is:

FE        Faces Karel to the East (the other possible directions are N, S, W).

Loading and Placing Beepers

To load beepers into Karel's beeper-bag, use the L command:

L100      Loads 100 beepers into Karel's beeper-bag.
L0        Loads 0 beepers into Karel's beeper-bag (i.e., the bag is emptied).
LINFINITE Loads an infinite number of beepers into Karel's beeper-bag. The
          word INFINITE may be abbreviated by INF.

Next, we learn how to put beepers on the corner where Karel is. For this action we use the P command.

P2        Puts 2 beepers on the corner that Karel is positioned at.
P1N3      Puts 1 beeper on Karel's current corner, moves him north, puts 1
          beeper on his new corner, moves him north again, and finally puts 1
          beeper on his new corner. Thus, Karel puts down 1 beeper 3 times, on
          his current corner and the two corners to his north.

Experiment with the second form of the P command until you can easily build initial situations that contain lines of intricate beeper patterns.

Building and Destroying Wall Sections

Next, we discuss the wall building command B and the wall destroying command D. In the following examples, you can substitute D for B and B for D, changing the command from build to destroy and from destroy to build, respectively.

BNE       Builds walls to the North and East of Karel's current corner (order
          is unimportant).
BN5W      Builds a wall to the north of Karel's current corner and a wall to
          the north of each of the next four corners to Karel's west (for a
          total of five walls built).
DA        Destroys all walls to Karel's immediate North, South, East, and West.

The second form of the B command is similar to the second form of the P command; both repeat a basic World Builder action, and both require practice to be mastered. Experiment with the wall building command until you can easily build hurdles, rooms, mazes, and other barriers and enclosures.

Exiting the World Builder

The S command Saves a description of your current world in a file, and then it exits the World Builder. Whenever you issue the S command, you will be prompted for the file name in which to store the initial situation that you have created. Once your initial situation has been stored in a file, the simulator will request the three main Execution Options and then start execution of your Karel program in the current initial situation. The S command is one way to end the world building process and start program execution.

The E command Exits the World Builder, but by using this command you don't necessarily have to save the initial situation that you have just finished building. If you want (when the simulator asks the question) you can just say that execution should start immediately, without permanently saving the initial situation. If you do want the initial situation saved, say so and the simulator will prompt you for a file name, just as if you had issued the S command. The E command is useful when you have slightly modified a previously-saved initial situation, and you don't need to save this slight modification.

IMPORTANT NOTE BEFORE EXITING: Karel starts his task at the corner he occupied when you exited the World Builder. Before exiting the World Builder (with either the S or E), position Karel on the corner that he must occupy in the initial situation.

Miscellaneous World Builder Commands

The T command Temporarily Saves the world in a file, but instead of starting to execute your Karel program, the simulator returns to the World Builder. If you are building a large, complex world, it is useful to be able to save your current copy every so often; doing so ensures that if you make a catastrophic mistake, you can always go back and reload the world that you saved and continue world building from there (see K, the next command).

The K command Kills (blanks out) the current world and then brings you back to the beginning of the World Builder, which asks whether you want to pre-read a file or start modifying the now empty world.

Remember that if you type a ? you will get a short reminder about all these commands. Note that for convenience, while you are in the World Builder you can move Karel through any wall sections that you have built. Of course, this won't be true when the simulator executes Karel's program. An error shutoff will occur if Karel is instructed (by his program) to try to move through a wall.

Also, note that spaces are unimportant: for example, the command P 1 N 3 can be written as P1N3. Finally, many default values are known to the World Builder: for example, if you typed PN3, it would be the same as typing P1N3. If you are in doubt about any default value, type the command fully.

[Top] - [Next] - [Previous]