|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.
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
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
initialize to put the robot at location
EAST, and to place obstacles and beepers randomly in the
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.
When the robot moves, either
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
true. If the robot cannot complete the requested
move, it moves as far as it can, and the movement method returns
The robot can always
Turning around means turning 180°.
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 (
beeper, it puts it in the square directly in front of the robot. These methods
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
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.
(Both parts) Thursday, March 14, before midnight.