Here is a blank RobotWorld which you may print out. It may help with the design of Robot Programs
In this lab you will write, compile and run some introductory RobotWorld problems.
First setup RobotWorld.
Create a file called OneBeeper.java which contains the following code.
public class OneBeeper
{
public static void main(String [] args)
{
World space = new World();
space.addBeeper(5, 2);
}
}
|
Compile the program. (Type javac OneBeeper.java). If there are any errors, fix them. Run the program. (type java OneBeeper)
|
|
What are the fewest number of instructions required to complete the task?
|
Write a program that places the four robots in the world, and then makes each do a quarter round.
The robots start as shown below, after a quarter turn, they will each have taken the position of the robot in front of them (of course that robot will also have moved on).
|
Note: to place a robot in a particular cell facing a particular direction,
use a variation of the add method:
world.add(robotname, x, y, "direction");
where world is the name of the world, robotname is the name of the robot, x and y are the coordinates of the cell the robot is going to, "direction" is the direction that the robot is to face, one of "north", "south", "east" or "west".
Here is an example code fragment using this method:
World stage = new World(); Robot pferdy = new Robot(); // Place pferdy at cell (2, 8) facing north. stage.add(pferdy, 2, 8, "north");