bridge
Class BridgeState

java.lang.Object
  extended by bridge.BridgeState

public class BridgeState
extends java.lang.Object

This class represents states of the Bridge Crossing problem. It creates new bridge states, tests states for equality, and produces string representations of them.


Constructor Summary
BridgeState(Position p1Position, Position p2Position, Position flashlightPosition, Position p5Position, Position p10Position, int timeSoFar)
          Creates a new bridge state.
 
Method Summary
 boolean equals(BridgeState other)
          Tests 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, equals, 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 so far to cross 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(BridgeState other)
Tests 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.

Parameters:
other - the other bridge state to be tested against this one.
Returns:
true if this state is equal to the other state, false otherwise

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.

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

getP10Position

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

Returns:
the position of person P10

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

getTimeSoFar

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

Returns:
the time taken to get to this state