Creating Worlds for Karel the Robot in Java

One of the things you’ll find taking CS106A at Stanford online, is that the version of Eclipse Stanford uses for teaching the course comes with Karel the Robot. You can probably figure out how to get it to work in any version of Eclipse, or run Karel the Robot in any Java IDE but I learned a valuable lesson trying to do this that to save time, I should just stick to the program as set out by the school.

I’m such a rebel. So I want to create my own worlds for Karel just so I know how. The interface is clunky but works fine. You can click and drop construction items like walls and beepers and you can define dimensions. What I liked about looking at world files is that I can do a lot of this in text and skip the interface altogether. The advantages are I don’t have to fight with the clunky click-drag actions on my touchpad.

The things to be aware of is that you still load worlds but can use the file browser to go find worlds you’ve built somewhere in your filesystem. Keeping everything relative to the path where your program resides can save you time navigating. Just remember to name new files the the dot ‘w’ extension, as in filename.w, and Karel the Robot can load your worlds. Be aware of your max 50×50 size limit.

Karel the Robot’s world definitions for Standford CS106A lecture one:

Dimension: (6, 3)
Wall: (4, 1) west
Wall: (4, 1) north
Wall: (5, 1) north
Wall: (6, 1) north
Beeper: (2, 1) 1
Karel: (1, 1) east
Speed: 0.00

You can use the built-in Textedit program on your Mac (or notepad.exe in Windows) to edit this definition file. The best reason I can think of for writing worlds for Karel the Robot is that, not having physically attended the class, the world from the first lecture is not there by default. A blank Karel the Robot starts with a world that has no objects (except the robot in the starting position) and a 10×10 grid. Knowing how to create worlds should help you follow along the way I did.

Author: Disa Johnson

Independent consultant in technology, security, and computer programming including website and app development.

Leave a Reply

Your email address will not be published. Required fields are marked *