New Simulator

(June 2004)

There is a new simulator that is an extension of the October 2003 Version. It has a new class AutoRemote that will create a remote controller for any of your own robot classes automatically.

This is now the official version. It is part of the normal distribution. Note that the name of the ultimate robot base class has changed from ur_Robot to UrRobot to make it better compatible with standard Java practice. You may need to modify some of your code slightly to use this. This change will be reflected in the printed book if we can make that happen.

Limitations

In order to use this, your class must implement a constructor of the following form (though it can have others as welll):

public MyRobot(int street, int avenue, Direction direction, int beepers, Color color)...

AutoRemote can extract from such a class all of its public methods that have no parameters and will construct a controller and a controlled robot for them. It will not find those methods that are static, nor those with parameters. Methods that return values (predicates, for example) will be able to show you the String equivalent of the value returned when you push the button with the name of the method.

Sample main

Here is an example main method that can be used to create such an AutoRemote:

	public static void main(String [] args)
	{	int street =1;
		int avenue = 1;
		Direction direction = North;
		int beepers = infinity;
World.setDelay(0); int len = args.length; if(len>1) street = Integer.parseInt(args[1]); if(len > 2) avenue = Integer.parseInt(args[2]); if(len > 3) { String which = args[3]; if(which.equals("North")) direction = North; else if(which.equals("South")) direction = South; else if(which.equals("East")) direction = East; else if(which.equals("West")) direction = West; } if(len>4) beepers = Integer.parseInt(args[4]); if(len>5 && !args[5].equals("null")) World.readWorld(args[5]); AutoRemote foo = new AutoRemote(args[0], street, avenue, direction, beepers, Color.red); World.setVisible(true); }

Examples

And here is a picture of it in action. The command to generate this (on a PC) was:

	java -cp .;KarelJRobot.jar kareltherobot.MyMain kareltherobot.Robot 1 1 East 0 stairworld.kwld

 

And if we change the command to the following, we see instead:

	java -cp .;KarelJRobot.jar kareltherobot.MyMain kareltherobot.StairClimber 1 1 East 0 stairworld.kwld
 

Final Notes

The first argument in the constructor of an AutoRemote is the fully qualified name of the robot class to instantiate. AutoRemote itself has another constructor (without a Color), but your class must implement the constructor mentioned above or you will get an Exception. My sample main used a color for demonstration purposes. You can modify the argument structure of this main to allow the user to specify a color of course. There is no requirement to use this main at all, actually, and it is not in the distribution. You will need to provide it or something like it. You can create as many of these as you like,in your main, of course.

AutoRemote has a constructor with no arguments to create an UrRobot at 1,1, facing North with no beepers.

AutoRemote has another constructor with a single (String) argument to name the class whose robot should be created. It will be created at 1, 1, facing North, with no beepers.


Last Updated: July 7, 2004