CIT 594 Assignment 9: Robot, part 1
CIT 594, Spring 2005

In this assignment you will implement the Robot class. Part 1 implements the robot model, that is, the part that does the actual calculations of where the robot is and what it is doing; part 2 will add a graphical interface, so that you can see the results.

I will supply a small graphical API that you can use in part 2. Part 2 will be available shortly.

Robot Rules of the Road

Initially, you should define your Robot class as follows:

public class Robot implements RobotInterface

In part 2, this will change to

public class Robot extends Piece implements RobotInterface

The robot "lives" in a rectangular array. Your Robot constructor should take, as parameters, the number of rows and the number of columns of this array.

The array may contain different kinds of objects. Some objects can be picked up, and some can't. For now, we will have "beepers" and "obstacles." The robot can pick up and carry beepers, but it cannot move obstacles. Provide a method initialize to put the robot at location [0][0], facing EAST, and to place obstacles and beepers randomly in the array.

Each array location may be empty, or it may contain the robot, or one obstacle, or one beeper. There will never be more than one thing in any given array location.

I think these are reasonable starting values: 12 rows by 15 columns, with 25 obstacles and 10 beepers. Avoid magic numbers, of course.

Robot movement

When the robot moves, either forward or back, it cannot move on or through a square containing an object, nor can it move outside the bounds of the array. If the robot completes the requested move, the movement method returns true. If the robot cannot complete the requested move, it moves as far as it can, and the movement method returns false.

The robot can always turnLeft, turnRight, or turnAround. Turning around means turning 180°.

Interacting with objects

The robot can pick up (take) a beeper if the beeper is in the square directly in front of the robot. If it puts down (drop) a beeper, it puts it in the square directly in front of the robot. These methods return true if successful. Remember that no square can hold more than one object.

When the robot picks up an object, it is removed from the array and put in the robot's "inventory" (the list of object being held by the robot). Implement the inventory as an ArrayList. (Don't just keep a count of beepers; if you did that, you would not be able to handle other kinds of objects.) When the robot drops an object, it can drop any object of the specified kind (all beepers are alike.)

When you ask what the robot is "seeing," it looks in the direction it is facing, and returns the name of the first object in that direction. If no objects are in front of it, the seeing method returns "edge", representing the edge of the array. The distance method returns the distance to the object (or edge) seen; this will be 1 for an object directly in front of the robot.

Due date:

(Both parts) Thursday, March 14, before midnight.