gpsys.lawnmower
Class Mower

java.lang.Object
  |
  +--gpsys.lawnmower.Mower

public class Mower
extends java.lang.Object
implements java.io.Serializable

The lawnmower itself is a robot that moves around on a lawn, cutting it. Unfortunately it only has a limited number of energy units available. These are divided into a number of left turns and number of movements. The lawnmower is only able to turn left when there are left turn units available, and similarly it can only move when there are movement units available. The lawnmower therefore stops when both of these units have run out. The lawn is mowed either by moving forward by one square thereby mowing that square or by leap frogging to any square and also mowing it.

Version:
$Revision: 1.1 $, $Date: 2000/07/05 16:26:49 $
Author:
Adil Qureshi
Department of Computer Science,
University College London,
Gower St,
London WC1E 6BT,
UK.
See Also:
Serialized Form

Field Summary
(package private)  int direction
          The current direction of the mower, can be one of NORTH, EAST, SOUTH or WEST.
static int EAST
          The value of direction when the mower is pointing EAST.
(package private)  Lawn lawn
          The lawn to be mowed.
(package private)  int leftTurnsAvailable
          The ration of left turn operations available.
(package private)  int movementAvailable
          The ration of movement operations available.
static int NORTH
          The value of direction when the mower is pointing NORTH.
static int SOUTH
          The value of direction when the mower is pointing SOUTH.
static int WEST
          The value of direction when the mower is pointing WEST.
(package private)  int x
          The X corrdinate of the mower on the lawn.
(package private)  int y
          The Y corrdinate of the mower on the lawn.
 
Constructor Summary
Mower(Lawn lawn)
          Construct a new mower to lawn the specified lawn.
 
Method Summary
 Vector2Mod8 frog(Vector2Mod8 displacement)
          Movement energy permitting, leap frogs the mower to by the specified (x,y) displacements.
 void left()
          Turns the mower left if possible (if there are suffucient left turn units).
 void mow()
          Movement energy permitting, moves the mower forward by one square in the current direction cutting the grass on that square.
 void reset()
          Resets the mower state to default values (position = (4,4), direction = NORTH, leftTurnsAvailable = 100, movementAvailable = 100.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

lawn

Lawn lawn
The lawn to be mowed.

x

int x
The X corrdinate of the mower on the lawn.

y

int y
The Y corrdinate of the mower on the lawn.

direction

int direction
The current direction of the mower, can be one of NORTH, EAST, SOUTH or WEST.

leftTurnsAvailable

int leftTurnsAvailable
The ration of left turn operations available.

movementAvailable

int movementAvailable
The ration of movement operations available.

NORTH

public static final int NORTH
The value of direction when the mower is pointing NORTH.

EAST

public static final int EAST
The value of direction when the mower is pointing EAST.

SOUTH

public static final int SOUTH
The value of direction when the mower is pointing SOUTH.

WEST

public static final int WEST
The value of direction when the mower is pointing WEST.
Constructor Detail

Mower

public Mower(Lawn lawn)
Construct a new mower to lawn the specified lawn. The mower starts at the default position (4,4) and direction NORTH. The number of left turn operations and the number of movement operations available are both initialised to 100.
Parameters:
lawn - The lawn to be mowed.
Method Detail

reset

public void reset()
Resets the mower state to default values (position = (4,4), direction = NORTH, leftTurnsAvailable = 100, movementAvailable = 100.

left

public final void left()
Turns the mower left if possible (if there are suffucient left turn units).

mow

public final void mow()
Movement energy permitting, moves the mower forward by one square in the current direction cutting the grass on that square.

frog

public final Vector2Mod8 frog(Vector2Mod8 displacement)
Movement energy permitting, leap frogs the mower to by the specified (x,y) displacements. The grass on square that the mower ends up on is cut.
Parameters:
displacement - The x and y displacements.
Returns:
The displacement specified.