bridge
Class BridgeState

java.lang.Object
  extended by bridge.BridgeState
All Implemented Interfaces:
State

public class BridgeState
extends java.lang.Object
implements State

This class represents states of the Bridge Crossing problem. It creates new bridge states, tests states for equality, and produces string representations of them. Note that this class implements the State interface and therefore imports framework.State. Except for the import and the class header, this class can be the same as in the previous assignment.


Constructor Summary
BridgeState(Position p1Position, Position p2Position, Position flashlightPosition, Position p5Position, Position p10Position, int timeSoFar)
          Creates a new bridge state.
 
Method Summary
 boolean equals(java.lang.Object other)
          Compares this bridge state with another for equality.
 Position getFlashlightPosition()
          Getter (accessor) for the position of the flashlight in this state.
 Position getP10Position()
          Getter (accessor) for the position of person P10 in this state.
 Position getP1Position()
          Getter (accessor) for the position of person P1 in this state.
 Position getP2Position()
          Getter (accessor) for the position of person P2 in this state.
 Position getP5Position()
          Getter (accessor) for the position of person P5 in this state.
 int getTimeSoFar()
          Getter (accessor) for the time taken to get to this state.
 java.lang.String toString()
          Creates a string representation of this state for display to the user trying to solve the problem.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BridgeState

public BridgeState(Position p1Position,
                   Position p2Position,
                   Position flashlightPosition,
                   Position p5Position,
                   Position p10Position,
                   int timeSoFar)
Creates a new bridge state. Besides storing the positions of the persons and flashlight, a bridge state should also store the time taken to get to this state in integer minutes.

Parameters:
p1Position - position of the person who can cross in 1 minute
p2Position - position of the person who can cross in 2 minutes
flashlightPosition - position of the flashlight
p5Position - position of the person who can cross in 5 minutes
p10Position - position of the person who can cross in 10 minutes
timeSoFar - time taken so far
Method Detail

equals

public boolean equals(java.lang.Object other)
Compares this bridge state with another for equality. Two bridge states are equal if the positions of the persons and flashlight in one state are matched by their positions in the other. Note that the time taken to cross so far is not taken into account when considering equality.

Specified by:
equals in interface State
Overrides:
equals in class java.lang.Object
Parameters:
other - the other bridge state to be compared with this one.
Returns:
whether this state is equal to the other state

toString

public java.lang.String toString()
Creates a string representation of this state for display to the user trying to solve the problem. Note that the time so far to cross is part of the string representation.

Specified by:
toString in interface State
Overrides:
toString in class java.lang.Object
Returns:
the string representation of this state

getFlashlightPosition

public Position getFlashlightPosition()
Getter (accessor) for the position of the flashlight in this state.

Returns:
the position of the flashlight

getP1Position

public Position getP1Position()
Getter (accessor) for the position of person P1 in this state.

Returns:
the position of person P1

getP2Position

public Position getP2Position()
Getter (accessor) for the position of person P2 in this state.

Returns:
the position of person P2

getP5Position

public Position getP5Position()
Getter (accessor) for the position of person P5 in this state.

Returns:
the position of person P5

getP10Position

public Position getP10Position()
Getter (accessor) for the position of person P10 in this state.

Returns:
the position of person P10

getTimeSoFar

public int getTimeSoFar()
Getter (accessor) for the time taken to get to this state.

Returns:
the time taken to get to this state