bridge
Class BridgeMove

java.lang.Object
  extended by bridge.BridgeMove

public class BridgeMove
extends java.lang.Object

This class represents moves in the Bridge Crossing problem. A move object stores its move name and knows how to apply itself to a bridge state to create a new state representing the result of the move.


Constructor Summary
BridgeMove(java.lang.String moveName)
          Constructs a new bridge move object.
 
Method Summary
 BridgeState doMove(BridgeState state)
          Attempts to perform this move on a given bridge state.
 java.lang.String getMoveName()
          Getter (accessor) for this move object's move name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BridgeMove

public BridgeMove(java.lang.String moveName)
Constructs a new bridge move object.

Parameters:
moveName - the name of this move. It is an error if the name is not one of the following:
  • "P1 crosses alone"
  • "P2 crosses alone"
  • "P5 crosses alone"
  • "P10 crosses alone"
  • "P1 crosses with P2"
  • "P1 crosses with P5"
  • "P1 crosses with P10"
  • "P2 crosses with P5"
  • "P2 crosses with P10"
  • "P5 crosses with P10"
Method Detail

getMoveName

public java.lang.String getMoveName()
Getter (accessor) for this move object's move name.

Returns:
this move object's move name

doMove

public BridgeState doMove(BridgeState state)
Attempts to perform this move on a given bridge state. The move to perform is determined by this object's move name. If the move can be performed a new bridge state object is returned that reflects this move. A move cannot be performed if the flashlight is not on the same side as the crossing person(s), or if a pair of persons who are crossing are not on the same side. If the move cannot be performed null is returned.

Parameters:
state - the bridge state on which this move is to be performed
Returns:
a new bridge state reflecting the move, or null if it cannot be performed