My own little floating island in the Netherworld
HomeHome  FAQFAQ  SearchSearch  RegisterRegister  Log in  


 Beyond KarelJ...

Go down 
Xian Nox
Demon Overlord
Xian Nox

Posts : 290
Join date : 2011-10-05

Name: Stellmaria
Class: Ranger
Element: Fire

Beyond KarelJ... Empty
PostSubject: Beyond KarelJ...   Beyond KarelJ... EmptyMon Nov 28 2011, 11:33

Some time ago I announced that I will add a Doll class to the KarelJ library. Hereby I state that it is both feasible and I have done it.
Due to a couple of reasons however, I cannot release the compiled binary, but will write a tutorial on modifying the KarelJ robot library. But before that, I have a bit of ranting to do.

Ever since I opened the KarelJ official website for the first time, two things struck me: first of all, the archaic design, which fortunately isn't found too often nowadays, and secondly: the fact that there is no mention of what license KarelJ is using. The last version is released on June 03, 2006, and is the one that I have been using so far. And if you think there was a lack of licenses available, you're totally wrong.
This is why I decided to contact Mr. Bergin, the author of the KarelJ library, and ask for permission to redistribute the original library, and to modify it and distribute the derivative work.
On the first point, we appeared to have reached an understanding:
Joseph Bergin wrote:
You can certainly redistribute the original materials with attribution. Please include a link somewhere to the original materials, however.
From the first version, right until the last, and for as long as this IDE ships with the KarelJ library, it included, includes and will include the attribution requested.
On the second question however, we seem to be on different wavelengths. There was no explicit answer to my question, but rather an explanation on why Karel is so limited:
Joseph Bergin wrote:
This exclusion is fundamental to the teaching ideology imbedded in Karel.

Investigate, if you wish, "Creativity Under Constraint." It is a fundamentally important concept.
For as much as I agree with the "Creativity Under Constraint", I must say that this constraint feels more like a stone on the neck for anyone that has gone beyond the basics.

In the end, there are two questions burning a hole in my mind.
First: Why isn't there a license? Chivalry, valor, honor and all those virtues are long gone, we live in a world where fakers claim even copyrighted programs.
Second of all: Why kill your own work? If you are no longer going to develop it, if the last update has been more than five years ago, and if it's an educational tool on top, why not release the source code and let everybody learn?

But enough of my random ramblings. Who knows, this may be the author's understanding of "creativity under constraint".

Tools you will need: JDK (obviously), and a Java decompiler. I used this one.
You'll also obviously need the KarelJRobot.jar. Whether it has had its pictures patched or not is of no concern.

Step 0: Set up your tools. I'm not going to explain how to do this in detail.
Step 1: Decompile Karel. This is actually the reason I am not exactly certain whether I can publish it or not.
How to do this: run the decompiler you happily installed in the previous step, open the KarelJRobot.jar file and then select Save all sources from the file menu. When ready, unpack the resulting zip archive.
Step 2: Navigate to a folder named kareltherobot and there copy the original KarelJRobot.jar
Step 3: Open and do the following modifications:
* Replace all "private" with an empty string, aka "".
* Find the two lines that have access$ ... . Comment out everything after the StateObject, it included, and make the loc[] equal 0;
* Create a directory called out in the kareltherobot directory.
* Run the following command (on Linux):
javac -d out -cp .:KarelJRobot.jar
For Windows, type in your whole javac path and change the : to a ;
Step 4: Open your favorite archive manager and pack in the freshly compiled files. They should replace the original ones.
Step 5: Create a file called with the following contents:
package kareltherobot;

import java.awt.Color;

public class Doll extends UrRobot
  implements Directions, Runnable

  public void turnRight()
    if (super.state == 2) {
      super.direction = super.direction.rotate(1);
      StateObject s = new StateObject(1);

  public void moveBack() {
    if (super.state == 2) {
        this.loc[this.direction.points()] -= 1;
        this.moves += 1;
        if (this.moves > 10) {
      StateObject s = new StateObject(0);

  public Doll(int street, int avenue, Directions.Direction direction, int beepers)
    super(street, avenue, direction, beepers, null);

Step 6:
javac -d out -cp .:KarelJRobot.jar
Step 7: Update in archive
And congrats. You now have a Doll that turns right and walks back.

This may not be the most elegant solution. It's more like a quick and dirty way to force your way in (removing all class protection from UrRobot for example) and it is meant to require as little compiling as possible.

Xian Nox over.

Beyond KarelJ... 161hwtd
Beyond KarelJ... Suigintout Suigintou fan. Nah... More like Suigintou-obsessed.
Beyond KarelJ... M0skit0_fan_userbar
Disturbed0ne's ultimate wisdom:
My Projects:
Back to top Go down
Beyond KarelJ...
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Pandaemonium :: Dev :: SuigintouJ-
Jump to: