com.webstersmalley.chessweb.model
Class Move

java.lang.Object
  extended by com.webstersmalley.chessweb.model.Move

public final class Move
extends java.lang.Object

Encapsulates a move. Has a source and a destination and a bunch of convenience methods.

Author:
Matthew Smalley

Constructor Summary
Move(Position source, Position destination)
          Constructor.
 
Method Summary
 long getCreated()
           
 Position getDestination()
           
 int getMaximumMagnitude()
          Returns the maximum magnitude.
 Position getSource()
           
 int getXDifference()
          Return the xDifference.
 int getXMagnitude()
          Return the xMagnitude.
 int getYDifference()
          Return the yDifference.
 int getYDirection()
          Returns the direction (magnitude 1) of the y direction.
 int getYMagnitude()
          Return the yMagnitude.
 boolean isCastling()
           
 boolean isDiagonal()
          Whether the move is a diagonal.
 boolean isPathClear(Board board)
          Calculates whether the path is clear.
 boolean isStraight()
          Whether the move is straight.
 void setCastling(boolean castling)
           
 void setDestination(Position destination)
           
 void setSource(Position source)
           
 java.lang.String toString()
          Returns a String representation of the move.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Move

public Move(Position source,
            Position destination)
Constructor. Source and destination are passed in.

Parameters:
source - the source
destination - the destination
Method Detail

getCreated

public long getCreated()
Returns:
Returns the created.

isPathClear

public boolean isPathClear(Board board)
Calculates whether the path is clear. This does not take into account pieces which can jump (Knights).

Parameters:
board - the current state
Returns:
whether the path is clear.

isDiagonal

public boolean isDiagonal()
Whether the move is a diagonal. This is calculated by comparing the magnitude along both axes. If they are the same then the move is a diagonal.

Returns:
whether the move is a diagonal.

isStraight

public boolean isStraight()
Whether the move is straight. This is calculated by checking that one of the x-axis or y-axis magnitudes are 0.

Returns:
whether the move is a straight line.

getXDifference

public int getXDifference()
Return the xDifference. This is destination.getX() - source.getX();

Returns:
the xDifference

getYDifference

public int getYDifference()
Return the yDifference. This is destination.getY() - source.getY();

Returns:
the yDifference

getXMagnitude

public int getXMagnitude()
Return the xMagnitude. This is abs(destination.getX() - source.getX());

Returns:
the xMagnitude

getYMagnitude

public int getYMagnitude()
Return the yMagnitude. This is abs(destination.getY() - source.getY());

Returns:
the yMagnitude

getMaximumMagnitude

public int getMaximumMagnitude()
Returns the maximum magnitude. This is the maximum between getXMagnitude and getYMagnitude.

Returns:
the maximum magnitude.

getYDirection

public int getYDirection()
Returns the direction (magnitude 1) of the y direction.

Returns:
the Y direction

getDestination

public Position getDestination()
Returns:
Returns the destination.

setDestination

public void setDestination(Position destination)
Parameters:
destination - The destination to set.

getSource

public Position getSource()
Returns:
Returns the source.

setSource

public void setSource(Position source)
Parameters:
source - The source to set.

toString

public java.lang.String toString()
Returns a String representation of the move.

Overrides:
toString in class java.lang.Object
Returns:
the representation.

isCastling

public boolean isCastling()
Returns:
Returns the castling.

setCastling

public void setCastling(boolean castling)
Parameters:
castling - The castling to set.


Copyright © 2005 Webster Smalley. All Rights Reserved.