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.
-
direction
- The current direction of the mower, can be one of NORTH, EAST, SOUTH or
WEST.
-
EAST
- The value of direction when the mower is pointing EAST.
-
lawn
- The lawn to be mowed.
-
leftTurnsAvailable
- The ration of left turn operations available.
-
movementAvailable
- The ration of movement operations available.
-
NORTH
- The value of direction when the mower is pointing NORTH.
-
SOUTH
- The value of direction when the mower is pointing SOUTH.
-
WEST
- The value of direction when the mower is pointing WEST.
-
x
- The X corrdinate of the mower on the lawn.
-
y
- The Y corrdinate of the mower on the lawn.
-
Mower(Lawn)
- Construct a new mower to lawn the specified lawn.
-
frog(Vector2Mod8)
- Movement energy permitting, leap frogs the mower to by the specified
(x,y) displacements.
-
left()
- Turns the mower left if possible (if there are suffucient left turn
units).
-
mow()
- Movement energy permitting, moves the mower forward by one square in the
current direction cutting the grass on that square.
-
reset()
- Resets the mower state to default values (position = (4,4),
direction = NORTH, leftTurnsAvailable = 100, movementAvailable = 100.
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.
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.
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.
All Packages Class Hierarchy This Package Previous Next Index