All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class gpsys.lawnmower.Mower

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

public class Mower
extends Object
implements 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.

Author:
Adil Qureshi
Department of Computer Science,
University College London,
Gower St,
London WC1E 6BT,
UK.

Variable Index

 o direction
The current direction of the mower, can be one of NORTH, EAST, SOUTH or WEST.
 o EAST
The value of direction when the mower is pointing EAST.
 o lawn
The lawn to be mowed.
 o leftTurnsAvailable
The ration of left turn operations available.
 o movementAvailable
The ration of movement operations available.
 o NORTH
The value of direction when the mower is pointing NORTH.
 o SOUTH
The value of direction when the mower is pointing SOUTH.
 o WEST
The value of direction when the mower is pointing WEST.
 o x
The X corrdinate of the mower on the lawn.
 o y
The Y corrdinate of the mower on the lawn.

Constructor Index

 o Mower(Lawn)
Construct a new mower to lawn the specified lawn.

Method Index

 o frog(Vector2Mod8)
Movement energy permitting, leap frogs the mower to by the specified (x,y) displacements.
 o left()
Turns the mower left if possible (if there are suffucient left turn units).
 o mow()
Movement energy permitting, moves the mower forward by one square in the current direction cutting the grass on that square.
 o reset()
Resets the mower state to default values (position = (4,4), direction = NORTH, leftTurnsAvailable = 100, movementAvailable = 100.

Variables

 o lawn
 Lawn lawn
The lawn to be mowed.

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

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

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

 o leftTurnsAvailable
 int leftTurnsAvailable
The ration of left turn operations available.

 o movementAvailable
 int movementAvailable
The ration of movement operations available.

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

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

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

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

Constructors

 o 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.

Methods

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

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

 o 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.

 o 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.

All Packages  Class Hierarchy  This Package  Previous  Next  Index